@@ -1012,6 +1012,57 @@ var _ = Describe("RouteRegistry", func() {
10121012 })
10131013 })
10141014
1015+ Context ("LookupWithInstance with specified load balancing algorithms for routes" , func () {
1016+ var (
1017+ appId string
1018+ appIndex string
1019+ )
1020+
1021+ BeforeEach (func () {
1022+ m1 := route .NewEndpoint (& route.EndpointOpts {AppId : "app-1-ID" , Host : "192.168.1.1" , Port : 1234 , PrivateInstanceIndex : "0" })
1023+ r .Register ("bar.com/foo" , m1 )
1024+ appId = "app-1-ID"
1025+ appIndex = "0"
1026+ })
1027+
1028+ It ("sets a default load balancing algorithm of a pool if no value is specified for a route" , func () {
1029+ p := r .LookupWithInstance ("bar.com/foo" , appId , appIndex )
1030+
1031+ Expect (p ).ToNot (BeNil ())
1032+ Expect (p .LoadBalancingAlgorithm ).To (Equal ("round-robin" ))
1033+ })
1034+
1035+ It ("keeps the default load balancing algorithm of a pool if the value for an endpoint is an empty string" , func () {
1036+ m2 := route .NewEndpoint (& route.EndpointOpts {AppId : "app-2-ID" , Host : "192.168.1.2" , Port : 1235 , PrivateInstanceIndex : "0" , LoadBalancingAlgorithm : "" })
1037+ r .Register ("bar.com/foo" , m2 )
1038+
1039+ p := r .LookupWithInstance ("bar.com/foo" , "app-2-ID" , appIndex )
1040+
1041+ Expect (p ).ToNot (BeNil ())
1042+ Expect (p .LoadBalancingAlgorithm ).To (Equal ("round-robin" ))
1043+ })
1044+
1045+ It ("sets the load balancing algorithm of pool to that of a newly added endpoint" , func () {
1046+ m3 := route .NewEndpoint (& route.EndpointOpts {AppId : "app-3-ID" , Host : "192.168.1.3" , Port : 1235 , PrivateInstanceIndex : "0" , LoadBalancingAlgorithm : "least-connection" })
1047+ r .Register ("bar.com/foo" , m3 )
1048+
1049+ p := r .LookupWithInstance ("bar.com/foo" , "app-3-ID" , appIndex )
1050+
1051+ Expect (p ).ToNot (BeNil ())
1052+ Expect (p .LoadBalancingAlgorithm ).To (Equal ("least-connection" ))
1053+ })
1054+
1055+ It ("repeatedly sets the load balancing algorithm of pool to that of a newly added endpoint" , func () {
1056+ m4 := route .NewEndpoint (& route.EndpointOpts {AppId : "app-4-ID" , Host : "192.168.1.4" , Port : 1235 , PrivateInstanceIndex : "0" , LoadBalancingAlgorithm : "round-robin" })
1057+ r .Register ("bar.com/foo" , m4 )
1058+
1059+ p := r .LookupWithInstance ("bar.com/foo" , "app-4-ID" , appIndex )
1060+
1061+ Expect (p ).ToNot (BeNil ())
1062+ Expect (p .LoadBalancingAlgorithm ).To (Equal ("round-robin" ))
1063+ })
1064+ })
1065+
10151066 Context ("LookupWithInstance" , func () {
10161067 var (
10171068 appId string
@@ -1043,6 +1094,13 @@ var _ = Describe("RouteRegistry", func() {
10431094 Expect (r .NumEndpoints ()).To (Equal (2 ))
10441095 })
10451096
1097+ It ("load balancing algorithm of an endpoint is not set and pool has a default load balancing value" , func () {
1098+ p := r .LookupWithInstance ("bar.com/foo" , appId , appIndex )
1099+
1100+ Expect (p ).ToNot (BeNil ())
1101+ Expect (p .LoadBalancingAlgorithm ).To (Equal ("round-robin" ))
1102+ })
1103+
10461104 It ("returns a pool that matches the result of Lookup" , func () {
10471105 Expect (r .NumUris ()).To (Equal (1 ))
10481106 Expect (r .NumEndpoints ()).To (Equal (2 ))
@@ -1083,7 +1141,7 @@ var _ = Describe("RouteRegistry", func() {
10831141
10841142 Context ("when given an incorrect app id" , func () {
10851143 BeforeEach (func () {
1086- appId = "app-3 -ID"
1144+ appId = "app-none -ID"
10871145 appIndex = "0"
10881146 })
10891147
0 commit comments