11package redis .clients .jedis .authentication ;
22
33import static org .awaitility .Awaitility .await ;
4+ import static org .awaitility .Durations .TWO_SECONDS ;
45import static org .awaitility .Durations .FIVE_SECONDS ;
56import static org .awaitility .Durations .ONE_HUNDRED_MILLISECONDS ;
67import static org .junit .Assert .assertEquals ;
1516import static org .mockito .Mockito .spy ;
1617import static org .mockito .Mockito .verify ;
1718import static org .mockito .Mockito .when ;
19+ import static org .hamcrest .Matchers .in ;
20+ import static org .hamcrest .Matchers .is ;
1821
1922import java .io .IOException ;
2023import java .util .ArrayList ;
3235
3336import org .awaitility .Awaitility ;
3437import org .awaitility .Durations ;
38+ import org .hamcrest .MatcherAssert ;
3539import org .junit .BeforeClass ;
3640import org .junit .FixMethodOrder ;
3741import org .junit .Test ;
6266import redis .clients .jedis .exceptions .JedisAccessControlException ;
6367import redis .clients .jedis .exceptions .JedisConnectionException ;
6468import redis .clients .jedis .scenario .FaultInjectionClient ;
69+ import redis .clients .jedis .scenario .FaultInjectionClient .TriggerActionResponse ;
6570
6671@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
6772public class RedisEntraIDIntegrationTests {
@@ -345,34 +350,44 @@ public void networkPartitionEvictionTest() {
345350 jedis .del (key );
346351 }
347352
348- triggerNetworkFailure ();
353+ TriggerActionResponse actionResponse = triggerNetworkFailure ();
349354
350355 JedisConnectionException aclException = assertThrows (JedisConnectionException .class , () -> {
351- for (int i = 0 ; i < 50 ; i ++) {
352- String key = UUID .randomUUID ().toString ();
353- jedis .set (key , "value" );
354- assertEquals ("value" , jedis .get (key ));
355- jedis .del (key );
356+ while (!actionResponse .isCompleted (ONE_HUNDRED_MILLISECONDS , TWO_SECONDS , FIVE_SECONDS )) {
357+ for (int i = 0 ; i < 50 ; i ++) {
358+ String key = UUID .randomUUID ().toString ();
359+ jedis .set (key , "value" );
360+ assertEquals ("value" , jedis .get (key ));
361+ jedis .del (key );
362+ }
356363 }
357364 });
358365
359- assertEquals ("Unexpected end of stream." , aclException .getMessage ());
366+ String [] expectedMessages = new String [] { "Unexpected end of stream." ,
367+ "java.net.SocketException: Connection reset" };
368+ MatcherAssert .assertThat (aclException .getMessage (), is (in (expectedMessages )));
360369 Awaitility .await ().pollDelay (Durations .ONE_HUNDRED_MILLISECONDS ).atMost (Durations .TWO_SECONDS )
361370 .until (() -> {
362- String key = UUID .randomUUID ().toString ();
363- jedis .set (key , "value" );
364- assertEquals ("value" , jedis .get (key ));
365- jedis .del (key );
366- return true ;
371+ try {
372+ String key = UUID .randomUUID ().toString ();
373+ jedis .set (key , "value" );
374+ assertEquals ("value" , jedis .get (key ));
375+ jedis .del (key );
376+ return true ;
377+ } catch (Exception e ) {
378+ log .debug ("attempt to reconnect after network failure, connection has not been re-established yet:"
379+ + e .getMessage ());
380+ return false ;
381+ }
367382 });
368383 }
369384 }
370385
371- private void triggerNetworkFailure () {
386+ private TriggerActionResponse triggerNetworkFailure () {
372387 HashMap <String , Object > params = new HashMap <>();
373388 params .put ("bdb_id" , endpointConfig .getBdbId ());
374389
375- FaultInjectionClient . TriggerActionResponse actionResponse = null ;
390+ TriggerActionResponse actionResponse = null ;
376391 String action = "network_failure" ;
377392 try {
378393 log .info ("Triggering {}" , action );
@@ -381,6 +396,7 @@ private void triggerNetworkFailure() {
381396 fail ("Fault Injection Server error:" + e .getMessage ());
382397 }
383398 log .info ("Action id: {}" , actionResponse .getActionId ());
399+ return actionResponse ;
384400 }
385401
386402 @ Test
0 commit comments