1818
1919import java .util .Collections ;
2020import java .util .List ;
21- import java .util .Objects ;
2221import java .util .stream .Collectors ;
2322import java .util .stream .IntStream ;
2423
3029import org .springframework .cloud .client .DefaultServiceInstance ;
3130import org .springframework .cloud .client .ServiceInstance ;
3231import org .springframework .cloud .client .loadbalancer .LoadBalancerProperties ;
32+ import org .springframework .cloud .client .loadbalancer .Request ;
3333import org .springframework .cloud .client .loadbalancer .reactive .ReactiveLoadBalancer ;
3434import org .springframework .cloud .commons .util .IdUtils ;
3535import org .springframework .mock .env .MockEnvironment ;
3636
3737import static org .assertj .core .api .Assertions .assertThat ;
38+ import static org .mockito .ArgumentMatchers .any ;
3839import static org .mockito .Mockito .mock ;
3940import static org .mockito .Mockito .when ;
4041import static org .springframework .cloud .loadbalancer .core .LoadBalancerTestUtils .buildLoadBalancerClientFactory ;
@@ -49,6 +50,8 @@ class SubsetServiceInstanceListSupplierTest {
4950 private final DiscoveryClientServiceInstanceListSupplier delegate = mock (
5051 DiscoveryClientServiceInstanceListSupplier .class );
5152
53+ private final Request <?> request = mock (Request .class );
54+
5255 private MockEnvironment env ;
5356
5457 @ BeforeEach
@@ -83,11 +86,11 @@ void shouldUseIdUtilsWhenInstanceIdNotSet() {
8386 @ Test
8487 void shouldReturnEmptyWhenDelegateReturnedEmpty () {
8588 when (delegate .getServiceId ()).thenReturn ("test" );
86- when (delegate .get ()).thenReturn (Flux .just (Collections .emptyList ()));
89+ when (delegate .get (any ( Request . class ) )).thenReturn (Flux .just (Collections .emptyList ()));
8790 SubsetServiceInstanceListSupplier supplier = new SubsetServiceInstanceListSupplier (delegate , env ,
8891 factory ("foobar" , 100 ));
8992
90- List <ServiceInstance > serviceInstances = Objects . requireNonNull ( supplier .get ().blockFirst () );
93+ List <ServiceInstance > serviceInstances = supplier .get (request ).blockFirst ();
9194 assertThat (serviceInstances ).isEmpty ();
9295 }
9396
@@ -98,11 +101,11 @@ void shouldReturnSublistWithGivenSubsetSize() {
98101 .collect (Collectors .toList ());
99102
100103 when (delegate .getServiceId ()).thenReturn ("test" );
101- when (delegate .get ()).thenReturn (Flux .just (instances ));
104+ when (delegate .get (any ( Request . class ) )).thenReturn (Flux .just (instances ));
102105 SubsetServiceInstanceListSupplier supplier = new SubsetServiceInstanceListSupplier (delegate , env ,
103106 factory ("foobar" , 5 ));
104107
105- List <ServiceInstance > serviceInstances = Objects . requireNonNull ( supplier .get ().blockFirst () );
108+ List <ServiceInstance > serviceInstances = supplier .get (request ).blockFirst ();
106109 assertThat (serviceInstances ).hasSize (5 );
107110 }
108111
@@ -113,11 +116,11 @@ void shouldReturnRawWhenLessThanSubsetSize() {
113116 .collect (Collectors .toList ());
114117
115118 when (delegate .getServiceId ()).thenReturn ("test" );
116- when (delegate .get ()).thenReturn (Flux .just (instances ));
119+ when (delegate .get (any ( Request . class ) )).thenReturn (Flux .just (instances ));
117120 SubsetServiceInstanceListSupplier supplier = new SubsetServiceInstanceListSupplier (delegate , env ,
118121 factory ("foobar" , 1000 ));
119122
120- List <ServiceInstance > serviceInstances = Objects . requireNonNull ( supplier .get ().blockFirst () );
123+ List <ServiceInstance > serviceInstances = supplier .get (request ).blockFirst ();
121124 assertThat (serviceInstances ).hasSize (101 );
122125 }
123126
@@ -128,15 +131,17 @@ void shouldReturnSameSublistForSameInstanceId() {
128131 .collect (Collectors .toList ());
129132
130133 when (delegate .getServiceId ()).thenReturn ("test" );
131- when (delegate .get ()).thenReturn (Flux .just (instances ));
134+ when (delegate .get (any ( Request . class ) )).thenReturn (Flux .just (instances ));
132135
133136 SubsetServiceInstanceListSupplier supplier1 = new SubsetServiceInstanceListSupplier (delegate , env ,
134137 factory ("foobar" , 5 ));
135- List <ServiceInstance > serviceInstances1 = Objects .requireNonNull (supplier1 .get ().blockFirst ());
138+ List <ServiceInstance > serviceInstances1 = supplier1 .get (request ).blockFirst ();
139+ assertThat (serviceInstances1 ).hasSize (5 );
136140
137141 SubsetServiceInstanceListSupplier supplier2 = new SubsetServiceInstanceListSupplier (delegate , env ,
138142 factory ("foobar" , 5 ));
139- List <ServiceInstance > serviceInstances2 = Objects .requireNonNull (supplier2 .get ().blockFirst ());
143+ List <ServiceInstance > serviceInstances2 = supplier2 .get (request ).blockFirst ();
144+ assertThat (serviceInstances2 ).hasSize (5 );
140145
141146 assertThat (serviceInstances1 ).isEqualTo (serviceInstances2 );
142147 }
@@ -148,15 +153,17 @@ void shouldReturnDifferentSublistForDifferentInstanceId() {
148153 .collect (Collectors .toList ());
149154
150155 when (delegate .getServiceId ()).thenReturn ("test" );
151- when (delegate .get ()).thenReturn (Flux .just (instances ));
156+ when (delegate .get (any ( Request . class ) )).thenReturn (Flux .just (instances ));
152157
153158 SubsetServiceInstanceListSupplier supplier1 = new SubsetServiceInstanceListSupplier (delegate , env ,
154159 factory ("foobar1" , 5 ));
155- List <ServiceInstance > serviceInstances1 = Objects .requireNonNull (supplier1 .get ().blockFirst ());
160+ List <ServiceInstance > serviceInstances1 = supplier1 .get (request ).blockFirst ();
161+ assertThat (serviceInstances1 ).hasSize (5 );
156162
157163 SubsetServiceInstanceListSupplier supplier2 = new SubsetServiceInstanceListSupplier (delegate , env ,
158164 factory ("foobar2" , 5 ));
159- List <ServiceInstance > serviceInstances2 = Objects .requireNonNull (supplier2 .get ().blockFirst ());
165+ List <ServiceInstance > serviceInstances2 = supplier2 .get (request ).blockFirst ();
166+ assertThat (serviceInstances2 ).hasSize (5 );
160167
161168 assertThat (serviceInstances1 ).isNotEqualTo (serviceInstances2 );
162169 }
0 commit comments