@@ -74,6 +74,7 @@ class ClusterTopologyRefreshUnitTests {
74
74
75
75
private static final String NODE_1_VIEW = "1 127.0.0.1:7380 master,myself - 0 1401258245007 2 disconnected 8000-11999\n "
76
76
+ "2 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n " ;
77
+
77
78
private static final String NODE_2_VIEW = "1 127.0.0.1:7380 master - 0 1401258245007 2 disconnected 8000-11999\n "
78
79
+ "2 127.0.0.1:7381 master,myself - 111 1401258245007 222 connected 7000 12000 12002-16383\n " ;
79
80
@@ -114,6 +115,11 @@ void before() {
114
115
when (clientResources .timer ()).thenReturn (timer );
115
116
when (clientResources .socketAddressResolver ()).thenReturn (SocketAddressResolver .create (DnsResolver .unresolved ()));
116
117
when (clientResources .eventExecutorGroup ()).thenReturn (eventExecutors );
118
+ doAnswer (invocation -> {
119
+ ((Runnable ) invocation .getArgument (0 )).run ();
120
+ return null ;
121
+ }).when (eventExecutors ).execute (any (Runnable .class ));
122
+
117
123
when (connection1 .async ()).thenReturn (asyncCommands1 );
118
124
when (connection2 .async ()).thenReturn (asyncCommands2 );
119
125
when (connection1 .closeAsync ()).thenReturn (CompletableFuture .completedFuture (null ));
@@ -299,10 +305,10 @@ void shouldAttemptToConnectOnlyOnce() {
299
305
300
306
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
301
307
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
302
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
308
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
303
309
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
304
310
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
305
- .thenReturn (completedWithException (new RedisException ("connection failed" )));
311
+ .thenReturn (completedWithException (new RedisException ("connection failed" )));
306
312
307
313
sut .loadViews (seed , Duration .ofSeconds (1 ), true );
308
314
@@ -346,10 +352,10 @@ void shouldFailIfNoNodeConnects() {
346
352
347
353
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
348
354
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
349
- .thenReturn (completedWithException (new RedisException ("connection failed" )));
355
+ .thenReturn (completedWithException (new RedisException ("connection failed" )));
350
356
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
351
357
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
352
- .thenReturn (completedWithException (new RedisException ("connection failed" )));
358
+ .thenReturn (completedWithException (new RedisException ("connection failed" )));
353
359
354
360
try {
355
361
sut .loadViews (seed , Duration .ofSeconds (1 ), true ).toCompletableFuture ().join ();
@@ -373,10 +379,10 @@ void shouldShouldDiscoverNodes() {
373
379
374
380
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
375
381
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
376
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
382
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
377
383
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
378
384
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
379
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
385
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
380
386
381
387
sut .loadViews (seed , Duration .ofSeconds (1 ), true );
382
388
@@ -393,7 +399,7 @@ void shouldShouldNotDiscoverNodes() {
393
399
394
400
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
395
401
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
396
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
402
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
397
403
398
404
sut .loadViews (seed , Duration .ofSeconds (1 ), false );
399
405
@@ -410,11 +416,11 @@ void shouldNotFailOnDuplicateSeedNodes() {
410
416
411
417
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
412
418
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
413
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
419
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
414
420
415
421
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
416
422
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
417
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
423
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
418
424
419
425
sut .loadViews (seed , Duration .ofSeconds (1 ), true );
420
426
@@ -431,10 +437,10 @@ void shouldCloseConnections() {
431
437
432
438
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
433
439
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
434
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
440
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
435
441
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
436
442
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
437
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
443
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
438
444
439
445
sut .loadViews (seed , Duration .ofSeconds (1 ), true );
440
446
@@ -449,7 +455,7 @@ void undiscoveredAdditionalNodesShouldBeLastUsingClientCount() {
449
455
450
456
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
451
457
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
452
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
458
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
453
459
454
460
Map <RedisURI , Partitions > partitionsMap = sut .loadViews (seed , Duration .ofSeconds (1 ), false ).toCompletableFuture ()
455
461
.join ();
@@ -469,18 +475,18 @@ void discoveredAdditionalNodesShouldBeOrderedUsingClientCount() {
469
475
470
476
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
471
477
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
472
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
478
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
473
479
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
474
480
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
475
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
481
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
476
482
477
483
Map <RedisURI , Partitions > partitionsMap = sut .loadViews (seed , Duration .ofSeconds (1 ), true ).toCompletableFuture ().join ();
478
484
479
485
Partitions partitions = partitionsMap .values ().iterator ().next ();
480
486
481
487
List <RedisClusterNode > nodes = TopologyComparators .sortByClientCount (partitions );
482
488
483
- assertThat (nodes ).hasSize (2 ).extracting (RedisClusterNode ::getUri ).containsSequence (RedisURI .create ("127.0.0.1" , 7381 ),
489
+ assertThat (nodes ).hasSize (2 ).extracting (RedisClusterNode ::getUri ).contains (RedisURI .create ("127.0.0.1" , 7381 ),
484
490
seed .get (0 ));
485
491
}
486
492
@@ -491,7 +497,7 @@ void undiscoveredAdditionalNodesShouldBeLastUsingLatency() {
491
497
492
498
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
493
499
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
494
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
500
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
495
501
496
502
Map <RedisURI , Partitions > partitionsMap = sut .loadViews (seed , Duration .ofSeconds (1 ), false ).toCompletableFuture ()
497
503
.join ();
@@ -511,18 +517,18 @@ void discoveredAdditionalNodesShouldBeOrderedUsingLatency() {
511
517
512
518
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
513
519
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
514
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
520
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
515
521
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
516
522
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
517
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
523
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
518
524
519
525
Map <RedisURI , Partitions > partitionsMap = sut .loadViews (seed , Duration .ofSeconds (1 ), true ).toCompletableFuture ().join ();
520
526
521
527
Partitions partitions = partitionsMap .values ().iterator ().next ();
522
528
523
529
List <RedisClusterNode > nodes = TopologyComparators .sortByLatency (partitions );
524
530
525
- assertThat (nodes ).hasSize (2 ).extracting (RedisClusterNode ::getUri ).containsSequence (RedisURI .create ("127.0.0.1" , 7381 ),
531
+ assertThat (nodes ).hasSize (2 ).extracting (RedisClusterNode ::getUri ).contains (RedisURI .create ("127.0.0.1" , 7381 ),
526
532
seed .get (0 ));
527
533
}
528
534
@@ -533,10 +539,10 @@ void shouldPropagateCommandFailures() {
533
539
534
540
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
535
541
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7380 ))))
536
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
542
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection1 ));
537
543
when (nodeConnectionFactory .connectToNodeAsync (any (RedisCodec .class ),
538
544
eq (InetSocketAddress .createUnresolved ("127.0.0.1" , 7381 ))))
539
- .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
545
+ .thenReturn (completedFuture ((StatefulRedisConnection ) connection2 ));
540
546
541
547
reset (connection1 , connection2 );
542
548
@@ -618,4 +624,5 @@ private static <T> ConnectionFuture<T> completedWithException(Exception e) {
618
624
619
625
return ConnectionFuture .from (InetSocketAddress .createUnresolved (TestSettings .host (), TestSettings .port ()), future );
620
626
}
627
+
621
628
}
0 commit comments