11package tech .ydb .core .impl .pool ;
22
33import java .io .IOException ;
4- import java .net .ServerSocket ;
4+ import java .net .Socket ;
5+ import java .net .SocketAddress ;
56import java .util .Arrays ;
67import java .util .List ;
78import java .util .concurrent .ThreadLocalRandom ;
89
9- import javax .net .ServerSocketFactory ;
10+ import javax .net .SocketFactory ;
1011
1112import com .google .common .base .Ticker ;
1213import org .junit .After ;
2021import tech .ydb .core .grpc .BalancingSettings ;
2122import tech .ydb .core .timer .TestTicker ;
2223
23- import static org .mockito .Mockito .mockStatic ;
24- import static org .mockito .Mockito .times ;
25- import static org .mockito .Mockito .verify ;
26- import static org .mockito .Mockito .when ;
27-
2824/**
2925 * @author Aleksandr Gorshenin
3026 * @author Kirill Kurdyukov
3127 */
3228public class EndpointPoolTest {
3329 private AutoCloseable mocks ;
34- private final MockedStatic <ThreadLocalRandom > threadLocalStaticMock = mockStatic (ThreadLocalRandom .class );
35- private final MockedStatic <Ticker > tickerStaticMock = mockStatic (Ticker .class );
30+ private final MockedStatic <ThreadLocalRandom > threadLocalStaticMock = Mockito .mockStatic (ThreadLocalRandom .class );
31+ private final MockedStatic <Ticker > tickerStaticMock = Mockito .mockStatic (Ticker .class );
32+ private final MockedStatic <SocketFactory > socketFactoryStaticMock = Mockito .mockStatic (SocketFactory .class );
33+
34+ private final Socket socket = Mockito .mock (Socket .class );
35+ private final SocketFactory socketFactory = Mockito .mock (SocketFactory .class );
3636 private final ThreadLocalRandom random = Mockito .mock (ThreadLocalRandom .class );
3737
3838 @ Before
39- public void setUp () {
39+ public void setUp () throws IOException {
4040 mocks = MockitoAnnotations .openMocks (this );
4141 threadLocalStaticMock .when (ThreadLocalRandom ::current ).thenReturn (random );
42+ socketFactoryStaticMock .when (SocketFactory ::getDefault ).thenReturn (socketFactory );
43+ Mockito .when (socketFactory .createSocket ()).thenReturn (socket );
44+ Mockito .doNothing ().when (socket ).connect (Mockito .any (SocketAddress .class ));
4245 }
4346
4447 @ After
4548 public void tearDown () throws Exception {
49+ socketFactoryStaticMock .close ();
4650 tickerStaticMock .close ();
4751 threadLocalStaticMock .close ();
4852 mocks .close ();
@@ -77,7 +81,7 @@ public void useAllNodesTest() {
7781
7882 check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (3 );
7983
80- when (random .nextInt (3 )).thenReturn (2 , 0 , 2 , 1 );
84+ Mockito . when (random .nextInt (3 )).thenReturn (2 , 0 , 2 , 1 );
8185
8286 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12345 ); // random choice
8387 check (pool .getEndpoint (0 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12345 ); // random choose
@@ -87,7 +91,7 @@ public void useAllNodesTest() {
8791 check (pool .getEndpoint (4 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12345 ); // random choose
8892 check (pool .getEndpoint (5 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12345 ); // random choose
8993
90- verify (random , times (4 )).nextInt (3 );
94+ Mockito . verify (random , Mockito . times (4 )).nextInt (3 );
9195 }
9296
9397 @ Test
@@ -103,7 +107,7 @@ public void localDcTest() {
103107
104108 check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (1 );
105109
106- when (random .nextInt (1 )).thenReturn (0 , 0 , 0 );
110+ Mockito . when (random .nextInt (1 )).thenReturn (0 , 0 , 0 );
107111
108112 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12345 ); // random from local DC
109113 check (pool .getEndpoint (0 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12345 ); // random from local DC
@@ -112,7 +116,7 @@ public void localDcTest() {
112116 check (pool .getEndpoint (3 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12345 ); // preferred
113117 check (pool .getEndpoint (4 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12345 ); // random from local DC
114118
115- verify (random , times (3 )).nextInt (1 );
119+ Mockito . verify (random , Mockito . times (3 )).nextInt (1 );
116120 }
117121
118122 @ Test
@@ -128,7 +132,7 @@ public void preferredDcTest() {
128132
129133 check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (1 );
130134
131- when (random .nextInt (1 )).thenReturn (0 , 0 , 0 );
135+ Mockito . when (random .nextInt (1 )).thenReturn (0 , 0 , 0 );
132136
133137 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12345 ); // random from DC1
134138 check (pool .getEndpoint (0 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12345 ); // random from DC1
@@ -137,7 +141,7 @@ public void preferredDcTest() {
137141 check (pool .getEndpoint (3 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12345 ); // preferred
138142 check (pool .getEndpoint (4 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12345 ); // random from DC1
139143
140- verify (random , times (3 )).nextInt (1 );
144+ Mockito . verify (random , Mockito . times (3 )).nextInt (1 );
141145 }
142146
143147 @ Test
@@ -153,7 +157,7 @@ public void preferredEndpointsTest() {
153157
154158 check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (3 );
155159
156- when (random .nextInt (3 )).thenReturn (2 , 0 , 2 , 1 );
160+ Mockito . when (random .nextInt (3 )).thenReturn (2 , 0 , 2 , 1 );
157161
158162 // If node is known
159163 check (pool .getEndpoint (1 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
@@ -167,7 +171,7 @@ public void preferredEndpointsTest() {
167171 check (pool .getEndpoint (6 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
168172 check (pool .getEndpoint (7 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
169173
170- verify (random , times (4 )).nextInt (3 );
174+ Mockito . verify (random , Mockito . times (4 )).nextInt (3 );
171175 }
172176
173177 @ Test
@@ -185,24 +189,24 @@ public void nodePessimizationTest() {
185189
186190 check (pool ).records (5 ).knownNodes (5 ).needToReDiscovery (false ).bestEndpointsCount (5 );
187191
188- when (random .nextInt (5 )).thenReturn (0 , 1 , 3 , 2 , 4 );
192+ Mockito . when (random .nextInt (5 )).thenReturn (0 , 1 , 3 , 2 , 4 );
189193 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
190194 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
191195 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
192196 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
193197 check (pool .getEndpoint (null )).hostname ("n5.ydb.tech" ).nodeID (5 ).port (12345 );
194- verify (random , times (5 )).nextInt (5 );
198+ Mockito . verify (random , Mockito . times (5 )).nextInt (5 );
195199
196200 // Pessimize one node - four left in use
197201 pool .pessimizeEndpoint (pool .getEndpoint (2 ));
198202 check (pool ).records (5 ).knownNodes (5 ).needToReDiscovery (false ).bestEndpointsCount (4 );
199203
200- when (random .nextInt (4 )).thenReturn (0 , 2 , 1 , 3 );
204+ Mockito . when (random .nextInt (4 )).thenReturn (0 , 2 , 1 , 3 );
201205 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
202206 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
203207 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
204208 check (pool .getEndpoint (null )).hostname ("n5.ydb.tech" ).nodeID (5 ).port (12345 );
205- verify (random , times (4 )).nextInt (4 );
209+ Mockito . verify (random , Mockito . times (4 )).nextInt (4 );
206210
207211 // but we can use pessimized node if specify it as preferred
208212 check (pool .getEndpoint (2 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
@@ -217,25 +221,25 @@ public void nodePessimizationTest() {
217221 pool .pessimizeEndpoint (pool .getEndpoint (2 ));
218222 check (pool ).records (5 ).knownNodes (5 ).needToReDiscovery (false ).bestEndpointsCount (4 );
219223
220- when (random .nextInt (4 )).thenReturn (3 , 1 , 2 , 0 );
224+ Mockito . when (random .nextInt (4 )).thenReturn (3 , 1 , 2 , 0 );
221225 check (pool .getEndpoint (null )).hostname ("n5.ydb.tech" ).nodeID (5 ).port (12345 );
222226 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
223227 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
224228 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
225- verify (random , times (8 )).nextInt (4 ); // Mockito counts also previous 4
229+ Mockito . verify (random , Mockito . times (8 )).nextInt (4 ); // Mockito counts also previous 4
226230
227231 // Pessimize two nodes - then we need to discovery
228232 pool .pessimizeEndpoint (pool .getEndpoint (3 ));
229233 check (pool ).records (5 ).knownNodes (5 ).needToReDiscovery (false ).bestEndpointsCount (3 );
230234 pool .pessimizeEndpoint (pool .getEndpoint (5 ));
231235 check (pool ).records (5 ).knownNodes (5 ).needToReDiscovery (true ).bestEndpointsCount (2 );
232236
233- when (random .nextInt (2 )).thenReturn (1 , 1 , 0 , 0 );
237+ Mockito . when (random .nextInt (2 )).thenReturn (1 , 1 , 0 , 0 );
234238 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
235239 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
236240 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
237241 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
238- verify (random , times (4 )).nextInt (2 );
242+ Mockito . verify (random , Mockito . times (4 )).nextInt (2 );
239243 }
240244
241245 @ Test
@@ -253,39 +257,39 @@ public void nodePessimizationFallbackTest() {
253257 check (pool ).records (4 ).knownNodes (4 ).needToReDiscovery (false ).bestEndpointsCount (2 );
254258
255259 // Only local nodes are used
256- when (random .nextInt (2 )).thenReturn (0 , 1 );
260+ Mockito . when (random .nextInt (2 )).thenReturn (0 , 1 );
257261 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
258262 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
259- verify (random , times (2 )).nextInt (2 );
263+ Mockito . verify (random , Mockito . times (2 )).nextInt (2 );
260264
261265 // Pessimize first local node - use second
262266 pool .pessimizeEndpoint (pool .getEndpoint (1 ));
263267 check (pool ).records (4 ).knownNodes (4 ).needToReDiscovery (false ).bestEndpointsCount (1 );
264268
265- when (random .nextInt (1 )).thenReturn (0 );
269+ Mockito . when (random .nextInt (1 )).thenReturn (0 );
266270 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
267- verify (random , times (1 )).nextInt (1 );
271+ Mockito . verify (random , Mockito . times (1 )).nextInt (1 );
268272
269273 // Pessimize second local node - use unlocal nodes
270274 pool .pessimizeEndpoint (pool .getEndpoint (2 ));
271275 check (pool ).records (4 ).knownNodes (4 ).needToReDiscovery (false ).bestEndpointsCount (2 );
272276
273- when (random .nextInt (2 )).thenReturn (1 , 0 );
277+ Mockito . when (random .nextInt (2 )).thenReturn (1 , 0 );
274278 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
275279 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
276- verify (random , times (4 )).nextInt (2 );
280+ Mockito . verify (random , Mockito . times (4 )).nextInt (2 );
277281
278282 // Pessimize all - fallback to use all nodes
279283 pool .pessimizeEndpoint (pool .getEndpoint (3 ));
280284 pool .pessimizeEndpoint (pool .getEndpoint (4 ));
281285 check (pool ).records (4 ).knownNodes (4 ).needToReDiscovery (true ).bestEndpointsCount (4 );
282286
283- when (random .nextInt (4 )).thenReturn (3 , 2 , 1 , 0 );
287+ Mockito . when (random .nextInt (4 )).thenReturn (3 , 2 , 1 , 0 );
284288 check (pool .getEndpoint (null )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 );
285289 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
286290 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
287291 check (pool .getEndpoint (null )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
288- verify (random , times (4 )).nextInt (4 );
292+ Mockito . verify (random , Mockito . times (4 )).nextInt (4 );
289293
290294 // setNewState reset all
291295 pool .setNewState ("DC3" , list (
@@ -318,7 +322,7 @@ public void duplicateEndpointsTest() {
318322 check (pool ).record (2 ).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
319323 check (pool ).record (3 ).hostname ("n3.ydb.tech" ).nodeID (6 ).port (12344 );
320324
321- when (random .nextInt (4 )).thenReturn (2 , 0 , 3 , 1 );
325+ Mockito . when (random .nextInt (4 )).thenReturn (2 , 0 , 3 , 1 );
322326
323327 check (pool .getEndpoint (null )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 ); // random
324328 check (pool .getEndpoint (0 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 ); // random
@@ -329,7 +333,7 @@ public void duplicateEndpointsTest() {
329333 check (pool .getEndpoint (5 )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 ); // random
330334 check (pool .getEndpoint (6 )).hostname ("n3.ydb.tech" ).nodeID (6 ).port (12344 );
331335
332- verify (random , times (4 )).nextInt (4 );
336+ Mockito . verify (random , Mockito . times (4 )).nextInt (4 );
333337 }
334338
335339 @ Test
@@ -349,15 +353,15 @@ public void duplicateNodesTest() {
349353 check (pool ).record (1 ).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
350354 check (pool ).record (2 ).hostname ("n3.ydb.tech" ).nodeID (2 ).port (12343 );
351355
352- when (random .nextInt (3 )).thenReturn (1 , 0 , 2 );
356+ Mockito . when (random .nextInt (3 )).thenReturn (1 , 0 , 2 );
353357
354358 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 ); // random
355359 check (pool .getEndpoint (0 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 ); // random
356360 check (pool .getEndpoint (1 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 );
357361 check (pool .getEndpoint (2 )).hostname ("n3.ydb.tech" ).nodeID (2 ).port (12343 );
358362 check (pool .getEndpoint (3 )).hostname ("n3.ydb.tech" ).nodeID (2 ).port (12343 ); // random
359363
360- verify (random , times (3 )).nextInt (3 );
364+ Mockito . verify (random , Mockito . times (3 )).nextInt (3 );
361365 }
362366
363367 @ Test
@@ -377,7 +381,7 @@ public void removeEndpointsTest() {
377381 check (pool ).record (1 ).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 );
378382 check (pool ).record (2 ).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
379383
380- when (random .nextInt (3 )).thenReturn (1 , 0 , 2 );
384+ Mockito . when (random .nextInt (3 )).thenReturn (1 , 0 , 2 );
381385
382386 check (pool .getEndpoint (null )).hostname ("n2.ydb.tech" ).nodeID (2 ).port (12342 ); // random
383387 check (pool .getEndpoint (0 )).hostname ("n1.ydb.tech" ).nodeID (1 ).port (12341 ); // random
@@ -386,7 +390,7 @@ public void removeEndpointsTest() {
386390 check (pool .getEndpoint (3 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 );
387391 check (pool .getEndpoint (4 )).hostname ("n3.ydb.tech" ).nodeID (3 ).port (12343 ); // random
388392
389- verify (random , times (3 )).nextInt (3 );
393+ Mockito . verify (random , Mockito . times (3 )).nextInt (3 );
390394
391395 pool .setNewState ("DC" , list (
392396 endpoint (2 , "n2.ydb.tech" , 12342 , "DC" ),
@@ -402,7 +406,7 @@ public void removeEndpointsTest() {
402406 check (pool ).record (2 ).hostname ("n5.ydb.tech" ).nodeID (5 ).port (12345 );
403407 check (pool ).record (3 ).hostname ("n6.ydb.tech" ).nodeID (6 ).port (12346 );
404408
405- when (random .nextInt (4 )).thenReturn (3 , 1 , 2 , 0 );
409+ Mockito . when (random .nextInt (4 )).thenReturn (3 , 1 , 2 , 0 );
406410
407411 check (pool .getEndpoint (null )).hostname ("n6.ydb.tech" ).nodeID (6 ).port (12346 ); // random
408412 check (pool .getEndpoint (0 )).hostname ("n4.ydb.tech" ).nodeID (4 ).port (12344 ); // random
@@ -413,7 +417,7 @@ public void removeEndpointsTest() {
413417 check (pool .getEndpoint (5 )).hostname ("n5.ydb.tech" ).nodeID (5 ).port (12345 );
414418 check (pool .getEndpoint (6 )).hostname ("n6.ydb.tech" ).nodeID (6 ).port (12346 );
415419
416- verify (random , times (4 )).nextInt (4 );
420+ Mockito . verify (random , Mockito . times (4 )).nextInt (4 );
417421 }
418422
419423
@@ -427,42 +431,35 @@ public void detectLocalDCTest() throws IOException {
427431
428432 tickerStaticMock .when (Ticker ::systemTicker ).thenReturn (testTicker );
429433
430- try (
431- ServerSocket s1 = ServerSocketFactory .getDefault ().createServerSocket (0 );
432- ServerSocket s2 = ServerSocketFactory .getDefault ().createServerSocket (0 );
433- ServerSocket s3 = ServerSocketFactory .getDefault ().createServerSocket (0 );
434- ) {
435-
436- EndpointPool pool = new EndpointPool (detectLocalDC ());
437- check (pool ).records (0 ).knownNodes (0 ).needToReDiscovery (false );
438-
439- int p1 = s1 .getLocalPort ();
440- int p2 = s2 .getLocalPort ();
441- int p3 = s3 .getLocalPort ();
442-
443- pool .setNewState ("DC" , list (
444- endpoint (1 , "127.0.0.1" , p1 , "DC1" ),
445- endpoint (2 , "127.0.0.2" , p2 , "DC2" ),
446- endpoint (3 , "127.0.0.3" , p3 , "DC3" )
447- ));
448-
449- check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (1 );
450-
451- check (pool .getEndpoint (null )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // detect local dc
452- check (pool .getEndpoint (0 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // random from local dc
453- check (pool .getEndpoint (1 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 );
454- check (pool .getEndpoint (2 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // local dc
455- check (pool .getEndpoint (3 )).hostname ("127.0.0.3" ).nodeID (3 ).port (p3 );
456- check (pool .getEndpoint (4 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // random from local dc
457-
458- pool .pessimizeEndpoint (pool .getEndpoint (2 ));
459- check (pool .getEndpoint (null )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // new local dc
460- check (pool .getEndpoint (0 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // random from local dc
461- check (pool .getEndpoint (1 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 );
462- check (pool .getEndpoint (2 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // local dc
463- check (pool .getEndpoint (3 )).hostname ("127.0.0.3" ).nodeID (3 ).port (p3 );
464- check (pool .getEndpoint (4 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // random from local dc
465- }
434+ EndpointPool pool = new EndpointPool (detectLocalDC ());
435+ check (pool ).records (0 ).knownNodes (0 ).needToReDiscovery (false );
436+
437+ int p1 = 1234 ;
438+ int p2 = 1235 ;
439+ int p3 = 1236 ;
440+
441+ pool .setNewState ("DC" , list (
442+ endpoint (1 , "127.0.0.1" , p1 , "DC1" ),
443+ endpoint (2 , "127.0.0.2" , p2 , "DC2" ),
444+ endpoint (3 , "127.0.0.3" , p3 , "DC3" )
445+ ));
446+
447+ check (pool ).records (3 ).knownNodes (3 ).needToReDiscovery (false ).bestEndpointsCount (1 );
448+
449+ check (pool .getEndpoint (null )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // detect local dc
450+ check (pool .getEndpoint (0 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // random from local dc
451+ check (pool .getEndpoint (1 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 );
452+ check (pool .getEndpoint (2 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // local dc
453+ check (pool .getEndpoint (3 )).hostname ("127.0.0.3" ).nodeID (3 ).port (p3 );
454+ check (pool .getEndpoint (4 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // random from local dc
455+
456+ pool .pessimizeEndpoint (pool .getEndpoint (2 ));
457+ check (pool .getEndpoint (null )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // new local dc
458+ check (pool .getEndpoint (0 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // random from local dc
459+ check (pool .getEndpoint (1 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 );
460+ check (pool .getEndpoint (2 )).hostname ("127.0.0.2" ).nodeID (2 ).port (p2 ); // local dc
461+ check (pool .getEndpoint (3 )).hostname ("127.0.0.3" ).nodeID (3 ).port (p3 );
462+ check (pool .getEndpoint (4 )).hostname ("127.0.0.1" ).nodeID (1 ).port (p1 ); // random from local dc
466463 }
467464
468465 private static class PoolChecker {
0 commit comments