@@ -367,6 +367,14 @@ protected void sleep(long sleepMillis) {
367367 @ Test
368368 public void runSuccessfulExecuteKeylessCommand () {
369369 ClusterConnectionProvider connectionHandler = mock (ClusterConnectionProvider .class );
370+ Map <String , ConnectionPool > connectionMap = new HashMap <>();
371+ ConnectionPool pool = mock (ConnectionPool .class );
372+ Connection connection = mock (Connection .class );
373+
374+ connectionMap .put ("localhost:6379" , pool );
375+ when (connectionHandler .getConnectionMap ()).thenReturn (connectionMap );
376+ when (pool .getResource ()).thenReturn (connection );
377+
370378 ClusterCommandExecutor testMe = new ClusterCommandExecutor (connectionHandler , 10 , Duration .ZERO ) {
371379 @ Override
372380 public <T > T execute (Connection connection , CommandObject <T > commandObject ) {
@@ -417,12 +425,13 @@ public void runKeylessCommandIgnoresRedirections() {
417425 ClusterConnectionProvider connectionHandler = mock (ClusterConnectionProvider .class );
418426 Map <String , ConnectionPool > connectionMap = new HashMap <>();
419427 ConnectionPool pool = mock (ConnectionPool .class );
420- Connection connection = mock (Connection .class );
428+ Connection connection1 = mock (Connection .class );
429+ Connection connection2 = mock (Connection .class );
421430 final HostAndPort movedTarget = new HostAndPort (null , 0 );
422431
423432 connectionMap .put ("localhost:6379" , pool );
424433 when (connectionHandler .getConnectionMap ()).thenReturn (connectionMap );
425- when (pool .getResource ()).thenReturn (connection );
434+ when (pool .getResource ()).thenReturn (connection1 , connection2 );
426435
427436 ClusterCommandExecutor testMe = new ClusterCommandExecutor (connectionHandler , 10 , ONE_SECOND ) {
428437 boolean isFirstCall = true ;
@@ -447,24 +456,25 @@ protected void sleep(long ignored) {
447456
448457 // Verify that we called getConnectionMap() twice (first failed with redirection, second succeeded)
449458 // and that we didn't follow the redirection to a specific node
450- InOrder inOrder = inOrder (connectionHandler , pool , connection );
451- inOrder .verify (connectionHandler , times (2 )).getConnectionMap ();
452- inOrder .verify (pool , times (2 )).getResource ();
453- inOrder .verify (connection , times (2 )).close ();
454- inOrder .verifyNoMoreInteractions ();
459+ verify (connectionHandler , times (2 )).getConnectionMap ();
460+ verify (pool , times (2 )).getResource ();
461+ verify (connection1 ).close ();
462+ verify (connection2 ).close ();
455463 }
456464
457465 @ Test
458466 public void runKeylessCommandFailsAfterMaxAttempts () {
459467 ClusterConnectionProvider connectionHandler = mock (ClusterConnectionProvider .class );
460468 Map <String , ConnectionPool > connectionMap = new HashMap <>();
461469 ConnectionPool pool = mock (ConnectionPool .class );
462- Connection connection = mock (Connection .class );
470+ Connection connection1 = mock (Connection .class );
471+ Connection connection2 = mock (Connection .class );
472+ Connection connection3 = mock (Connection .class );
463473 final LongConsumer sleep = mock (LongConsumer .class );
464474
465475 connectionMap .put ("localhost:6379" , pool );
466476 when (connectionHandler .getConnectionMap ()).thenReturn (connectionMap );
467- when (pool .getResource ()).thenReturn (connection );
477+ when (pool .getResource ()).thenReturn (connection1 , connection2 , connection3 );
468478
469479 ClusterCommandExecutor testMe = new ClusterCommandExecutor (connectionHandler , 3 , ONE_SECOND ) {
470480 @ Override
@@ -486,16 +496,15 @@ protected void sleep(long sleepMillis) {
486496 }
487497
488498 // Verify that we tried connection map access and performed slot cache renewal
489- InOrder inOrder = inOrder (connectionHandler , pool , connection , sleep );
490- inOrder .verify (connectionHandler , times (2 )).getConnectionMap ();
491- inOrder .verify (pool , times (2 )).getResource ();
492- inOrder .verify (connection , times (2 )).close ();
493- inOrder .verify (sleep ).accept (ArgumentMatchers .anyLong ());
494- inOrder .verify (connectionHandler ).renewSlotCache ();
495- inOrder .verify (connectionHandler ).getConnectionMap ();
496- inOrder .verify (pool ).getResource ();
497- inOrder .verify (connection ).close ();
498- inOrder .verifyNoMoreInteractions ();
499+ // getConnectionMap() called 3 times (once for each connection attempt)
500+ // getResource() called 3 times, sleep called once, renewSlotCache called once
501+ verify (connectionHandler , times (3 )).getConnectionMap ();
502+ verify (pool , times (3 )).getResource ();
503+ verify (connection1 ).close ();
504+ verify (connection2 ).close ();
505+ verify (connection3 ).close ();
506+ verify (sleep ).accept (ArgumentMatchers .anyLong ());
507+ verify (connectionHandler ).renewSlotCache ();
499508 }
500509
501510 @ Test
0 commit comments