11package org .testcontainers .junit ;
22
3- import com . google . common . util . concurrent . Uninterruptibles ;
3+ import org . awaitility . Awaitility ;
44import org .junit .Test ;
5- import org .rnorth .ducttape .unreliables .Unreliables ;
65import org .testcontainers .TestImages ;
76import org .testcontainers .containers .FixedHostPortGenericContainer ;
87import org .testcontainers .containers .GenericContainer ;
1110import java .io .IOException ;
1211import java .io .InputStreamReader ;
1312import java .net .Socket ;
14- import java .util . concurrent . TimeUnit ;
13+ import java .time . Duration ;
1514
1615import static org .assertj .core .api .Assertions .assertThat ;
1716
@@ -71,7 +70,7 @@ public void testFixedHostPortMapping() throws IOException {
7170 .as ("Port mapping does not seem to match given fixed port" )
7271 .isEqualTo (unusedHostPort );
7372
74- final String content = this . readResponse (echoServer , unusedHostPort );
73+ final String content = readResponse (echoServer , unusedHostPort );
7574 assertThat (content ).as ("Returned echo from fixed port does not match expected" ).isEqualTo (TEST_RESPONSE );
7675 }
7776 }
@@ -86,15 +85,11 @@ public void testFixedHostPortMapping() throws IOException {
8685 */
8786 private String readResponse (GenericContainer container , Integer port ) throws IOException {
8887 try (
89- final BufferedReader reader = Unreliables .retryUntilSuccess (
90- 10 ,
91- TimeUnit .SECONDS ,
92- () -> {
93- Uninterruptibles .sleepUninterruptibly (1 , TimeUnit .SECONDS );
94- final Socket socket = new Socket (container .getHost (), port );
95- return new BufferedReader (new InputStreamReader (socket .getInputStream ()));
96- }
97- )
88+ Socket socket = Awaitility
89+ .await ()
90+ .pollDelay (Duration .ofSeconds (1 ))
91+ .until (() -> new Socket (container .getHost (), port ), Socket ::isConnected );
92+ BufferedReader reader = new BufferedReader (new InputStreamReader (socket .getInputStream ()))
9893 ) {
9994 return reader .readLine ();
10095 }
0 commit comments