1717
1818import static org .assertj .core .api .Assertions .*;
1919import static org .assertj .core .api .Assumptions .*;
20- import static org .springframework . data . redis . SpinBarrier .* ;
20+ import static org .awaitility . Awaitility . await ;
2121import static org .springframework .data .redis .connection .BitFieldSubCommands .*;
2222import static org .springframework .data .redis .connection .BitFieldSubCommands .BitFieldIncrBy .Overflow .*;
2323import static org .springframework .data .redis .connection .BitFieldSubCommands .BitFieldType .*;
3636import java .util .concurrent .TimeUnit ;
3737
3838import org .assertj .core .data .Offset ;
39+ import org .awaitility .Awaitility ;
3940import org .junit .AssumptionViolatedException ;
4041import org .junit .jupiter .api .AfterEach ;
4142import org .junit .jupiter .api .BeforeEach ;
@@ -162,7 +163,9 @@ void testExpire() {
162163 actual .add (connection .expire ("exp" , 1 ));
163164
164165 verifyResults (Arrays .asList (true , true ));
165- assertThat (waitFor (new KeyExpired ("exp" ), 3000L )).isTrue ();
166+
167+ KeyExpired keyExpired = new KeyExpired ("exp" );
168+ await ().atMost (Duration .ofMillis (3000L )).until (keyExpired ::passes );
166169 }
167170
168171 @ Test // DATAREDIS-1103
@@ -185,7 +188,9 @@ void testExpireAt() {
185188 actual .add (connection .set ("exp2" , "true" ));
186189 actual .add (connection .expireAt ("exp2" , System .currentTimeMillis () / 1000 + 1 ));
187190 verifyResults (Arrays .asList (true , true ));
188- assertThat (waitFor (new KeyExpired ("exp2" ), 3000L )).isTrue ();
191+
192+ KeyExpired keyExpired = new KeyExpired ("exp2" );
193+ await ().atMost (Duration .ofMillis (3000L )).until (keyExpired ::passes );
189194 }
190195
191196 @ LongRunningTest
@@ -194,7 +199,9 @@ void testPExpire() {
194199 actual .add (connection .set ("exp" , "true" ));
195200 actual .add (connection .pExpire ("exp" , 100 ));
196201 verifyResults (Arrays .asList (true , true ));
197- assertThat (waitFor (new KeyExpired ("exp" ), 1000L )).isTrue ();
202+
203+ KeyExpired keyExpired = new KeyExpired ("exp" );
204+ await ().atMost (Duration .ofMillis (1000L )).until (keyExpired ::passes );
198205 }
199206
200207 @ Test
@@ -209,7 +216,9 @@ void testPExpireAt() {
209216 actual .add (connection .set ("exp2" , "true" ));
210217 actual .add (connection .pExpireAt ("exp2" , System .currentTimeMillis () + 200 ));
211218 verifyResults (Arrays .asList (true , true ));
212- assertThat (waitFor (new KeyExpired ("exp2" ), 1000L )).isTrue ();
219+
220+ KeyExpired keyExpired = new KeyExpired ("exp2" );
221+ await ().atMost (Duration .ofMillis (1000L )).until (keyExpired ::passes );
213222 }
214223
215224 @ LongRunningTest
@@ -390,7 +399,9 @@ void testSetEx() {
390399 actual .add (connection .get ("expy" ));
391400
392401 verifyResults (Arrays .asList (true , "yep" ));
393- assertThat (waitFor (new KeyExpired ("expy" ), 2500L )).isTrue ();
402+
403+ KeyExpired keyExpired = new KeyExpired ("expy" );
404+ await ().atMost (Duration .ofMillis (2500L )).until (keyExpired ::passes );
394405 }
395406
396407 @ LongRunningTest // DATAREDIS-271
@@ -400,7 +411,9 @@ void testPsetEx() {
400411 actual .add (connection .get ("expy" ));
401412
402413 verifyResults (Arrays .asList (true , "yep" ));
403- assertThat (waitFor (new KeyExpired ("expy" ), 2500L )).isTrue ();
414+
415+ KeyExpired keyExpired = new KeyExpired ("expy" );
416+ await ().atMost (Duration .ofMillis (2500L )).until (keyExpired ::passes );
404417 }
405418
406419 @ LongRunningTest
@@ -632,7 +645,8 @@ public void testPubSubWithNamedChannels() throws Exception {
632645
633646 Thread th = new Thread (() -> {
634647 // sync to let the registration happen
635- waitFor (connection ::isSubscribed , 2000 );
648+ await ().atMost (Duration .ofMillis (2000L )).until (connection ::isSubscribed );
649+
636650 try {
637651 Thread .sleep (500 );
638652 } catch (InterruptedException o_O ) {}
@@ -674,7 +688,7 @@ public void testPubSubWithPatterns() throws Exception {
674688
675689 Thread th = new Thread (() -> {
676690 // sync to let the registration happen
677- waitFor ( connection ::isSubscribed , 2000 );
691+ await (). atMost ( Duration . ofMillis ( 2000L )). until ( connection ::isSubscribed );
678692
679693 try {
680694 Thread .sleep (500 );
@@ -1093,7 +1107,9 @@ void testRestoreTtl() {
10931107 actual .add (connection .get ("testing" ));
10941108 connection .restore ("testing" .getBytes (), 100L , (byte []) results .get (1 ));
10951109 verifyResults (Arrays .asList (1L , null ));
1096- assertThat (waitFor (new KeyExpired ("testing" ), 400L )).isTrue ();
1110+
1111+ KeyExpired keyExpired = new KeyExpired ("testing" );
1112+ await ().atMost (Duration .ofMillis (400L )).until (keyExpired ::passes );
10971113 }
10981114
10991115 @ Test
0 commit comments