1
1
package redis .clients .jedis .authentication ;
2
2
3
3
import static org .awaitility .Awaitility .await ;
4
+ import static org .awaitility .Durations .TWO_SECONDS ;
4
5
import static org .awaitility .Durations .FIVE_SECONDS ;
5
6
import static org .awaitility .Durations .ONE_HUNDRED_MILLISECONDS ;
6
7
import static org .junit .Assert .assertEquals ;
15
16
import static org .mockito .Mockito .spy ;
16
17
import static org .mockito .Mockito .verify ;
17
18
import static org .mockito .Mockito .when ;
19
+ import static org .hamcrest .Matchers .in ;
20
+ import static org .hamcrest .Matchers .is ;
18
21
19
22
import java .io .IOException ;
20
23
import java .util .ArrayList ;
32
35
33
36
import org .awaitility .Awaitility ;
34
37
import org .awaitility .Durations ;
38
+ import org .hamcrest .MatcherAssert ;
35
39
import org .junit .BeforeClass ;
36
40
import org .junit .FixMethodOrder ;
37
41
import org .junit .Test ;
62
66
import redis .clients .jedis .exceptions .JedisAccessControlException ;
63
67
import redis .clients .jedis .exceptions .JedisConnectionException ;
64
68
import redis .clients .jedis .scenario .FaultInjectionClient ;
69
+ import redis .clients .jedis .scenario .FaultInjectionClient .TriggerActionResponse ;
65
70
66
71
@ FixMethodOrder (MethodSorters .NAME_ASCENDING )
67
72
public class RedisEntraIDIntegrationTests {
@@ -345,34 +350,44 @@ public void networkPartitionEvictionTest() {
345
350
jedis .del (key );
346
351
}
347
352
348
- triggerNetworkFailure ();
353
+ TriggerActionResponse actionResponse = triggerNetworkFailure ();
349
354
350
355
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
+ }
356
363
}
357
364
});
358
365
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 )));
360
369
Awaitility .await ().pollDelay (Durations .ONE_HUNDRED_MILLISECONDS ).atMost (Durations .TWO_SECONDS )
361
370
.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
+ }
367
382
});
368
383
}
369
384
}
370
385
371
- private void triggerNetworkFailure () {
386
+ private TriggerActionResponse triggerNetworkFailure () {
372
387
HashMap <String , Object > params = new HashMap <>();
373
388
params .put ("bdb_id" , endpointConfig .getBdbId ());
374
389
375
- FaultInjectionClient . TriggerActionResponse actionResponse = null ;
390
+ TriggerActionResponse actionResponse = null ;
376
391
String action = "network_failure" ;
377
392
try {
378
393
log .info ("Triggering {}" , action );
@@ -381,6 +396,7 @@ private void triggerNetworkFailure() {
381
396
fail ("Fault Injection Server error:" + e .getMessage ());
382
397
}
383
398
log .info ("Action id: {}" , actionResponse .getActionId ());
399
+ return actionResponse ;
384
400
}
385
401
386
402
@ Test
0 commit comments