File tree Expand file tree Collapse file tree
testFixtures/java/javasabr/rlib/common/util
test/java/javasabr/rlib/common/util
rlib-network/src/test/java/javasabr/rlib/network Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import static org .assertj .core .api .Assertions .assertThat ;
44
5- import java .time . temporal . ChronoUnit ;
5+ import java .util . concurrent . TimeUnit ;
66import java .util .concurrent .atomic .AtomicBoolean ;
77import org .junit .jupiter .api .Test ;
88
@@ -28,7 +28,7 @@ void shouldAwaitCondition() throws InterruptedException {
2828
2929 // when
3030 thread .start ();
31- boolean result = AwaitUtils .await (500 , ChronoUnit . MILLIS , condition ::get );
31+ boolean result = AwaitUtils .await (500 , TimeUnit . MILLISECONDS , condition ::get );
3232
3333 // then
3434 assertThat (result ).isTrue ();
@@ -40,7 +40,7 @@ void shouldTimeoutIfConditionNotMet() throws InterruptedException {
4040 var condition = new AtomicBoolean (false );
4141
4242 // when
43- boolean result = AwaitUtils .await (100 , ChronoUnit . MILLIS , condition ::get );
43+ boolean result = AwaitUtils .await (100 , TimeUnit . MILLISECONDS , condition ::get );
4444
4545 // then
4646 assertThat (result ).isFalse ();
Original file line number Diff line number Diff line change 11package javasabr .rlib .common .util ;
22
3- import java .time . temporal . ChronoUnit ;
3+ import java .util . concurrent . TimeUnit ;
44import java .util .function .Supplier ;
55
66/**
@@ -19,11 +19,11 @@ public final class AwaitUtils {
1919 * @return true if the condition was met.
2020 * @throws InterruptedException if the current thread was interrupted.
2121 */
22- public static boolean await (long amount , ChronoUnit unit , Supplier <Boolean > condition ) throws InterruptedException {
22+ public static boolean await (long amount , TimeUnit unit , Supplier <Boolean > condition ) throws InterruptedException {
2323 if (condition .get ()) {
2424 return true ;
2525 }
26- var timeoutMillis = unit .getDuration (). toMillis () * amount ;
26+ var timeoutMillis = unit .toMillis (amount ) ;
2727 var endTime = System .currentTimeMillis () + timeoutMillis ;
2828 while (System .currentTimeMillis () < endTime ) {
2929 if (condition .get ()) {
Original file line number Diff line number Diff line change 44
55import java .io .InputStream ;
66import java .net .InetSocketAddress ;
7- import java .time .temporal .ChronoUnit ;
87import java .util .concurrent .CountDownLatch ;
98import java .util .concurrent .TimeUnit ;
109import javasabr .rlib .common .util .AwaitUtils ;
@@ -77,11 +76,11 @@ void shouldCloseServerConnectionWhenClientClosesTcpChannelAbruptly() {
7776
7877 // when
7978 clientConnection .channel ().close ();
80- assertThat (AwaitUtils .await (5000 , ChronoUnit . MILLIS , clientConnection ::closed ))
79+ assertThat (AwaitUtils .await (5 , TimeUnit . SECONDS , clientConnection ::closed ))
8180 .as ("Client connection should be closed prior server side verification" ).isTrue ();
8281
8382 // then
84- assertThat (AwaitUtils .await (5000 , ChronoUnit . MILLIS , serverConnection ::closed ))
83+ assertThat (AwaitUtils .await (5 , TimeUnit . SECONDS , serverConnection ::closed ))
8584 .as ("Server connection should be closed after receiving EOF from abruptly closed client channel" )
8685 .isTrue ();
8786 }
You can’t perform that action at this time.
0 commit comments