11package com .github .dockerjava .netty .exec ;
22
3+ import static java .util .concurrent .TimeUnit .SECONDS ;
34import static org .hamcrest .MatcherAssert .assertThat ;
45import static org .hamcrest .Matchers .containsString ;
56import static org .hamcrest .Matchers .isEmptyString ;
@@ -70,7 +71,7 @@ public void onNext(Frame frame) {
7071 };
7172
7273 dockerClient .attachContainerCmd (container .getId ()).withStdErr (true ).withStdOut (true ).withFollowStream (true )
73- .withLogs (true ).exec (callback ).awaitCompletion (10 , TimeUnit . SECONDS );
74+ .withLogs (true ).exec (callback ).awaitCompletion (10 , SECONDS );
7475 callback .close ();
7576
7677 assertThat (callback .toString (), containsString (snippet ));
@@ -81,33 +82,40 @@ public void attachContainerWithStdin() throws Exception {
8182
8283 String snippet = "hello world" ;
8384
84- CreateContainerResponse container = dockerClient .createContainerCmd ("busybox" ).withCmd ("/bin/sh" , "-c" , "read line && echo $line" )
85- .withTty (false ).withStdinOpen (true ).exec ();
85+ CreateContainerResponse container = dockerClient .createContainerCmd ("busybox" )
86+ .withCmd ("/bin/sh" , "-c" , "sleep 1 && read line && echo $line" )
87+ .withTty (false )
88+ .withStdinOpen (true )
89+ .exec ();
8690
8791 LOG .info ("Created container: {}" , container .toString ());
8892 assertThat (container .getId (), not (isEmptyString ()));
8993
9094 dockerClient .startContainerCmd (container .getId ()).exec ();
9195
96+ Thread .sleep (SECONDS .toMillis (3 )); //wait bash initialisation
97+
9298 InspectContainerResponse inspectContainerResponse = dockerClient .inspectContainerCmd (container .getId ()).exec ();
9399
94100 assertTrue (inspectContainerResponse .getState ().getRunning ());
95101
96102 AttachContainerTestCallback callback = new AttachContainerTestCallback () {
97-
98103 @ Override
99104 public void onNext (Frame frame ) {
100105 assertEquals (frame .getStreamType (), StreamType .STDOUT );
101106 super .onNext (frame );
102- };
107+ }
103108 };
104109
105110 InputStream stdin = new ByteArrayInputStream ((snippet + "\n " ).getBytes ());
106111
107- dockerClient .attachContainerCmd (container .getId ()).withStdErr (true ).withStdOut (true ).withFollowStream (true )
112+ dockerClient .attachContainerCmd (container .getId ())
113+ .withStdErr (true )
114+ .withStdOut (true )
115+ .withFollowStream (true )
108116 .withStdIn (stdin )
109117 .exec (callback )
110- .awaitCompletion (5 , TimeUnit . SECONDS );
118+ .awaitCompletion (15 , SECONDS );
111119 callback .close ();
112120
113121 assertThat (callback .toString (), containsString (snippet ));
@@ -141,7 +149,7 @@ public void onNext(Frame frame) {
141149 .withStdOut (true )
142150 .withFollowStream (true )
143151 .exec (callback )
144- .awaitCompletion (10 , TimeUnit . SECONDS );
152+ .awaitCompletion (10 , SECONDS );
145153 callback .close ();
146154
147155 // HexDump.dump(collectFramesCallback.toString().getBytes(), 0, System.out, 0);
0 commit comments