6
6
import static org .hamcrest .Matchers .isEmptyString ;
7
7
import static org .hamcrest .Matchers .not ;
8
8
9
- import java .io .ByteArrayInputStream ;
10
9
import java .io .File ;
11
- import java .io .InputStream ;
10
+ import java .io .PipedInputStream ;
11
+ import java .io .PipedOutputStream ;
12
12
import java .lang .reflect .Method ;
13
- import java .util .concurrent .TimeUnit ;
14
13
15
14
import org .testng .ITestResult ;
16
15
import org .testng .annotations .AfterMethod ;
@@ -93,8 +92,6 @@ public void attachContainerWithStdin() throws Exception {
93
92
94
93
dockerClient .startContainerCmd (container .getId ()).exec ();
95
94
96
- Thread .sleep (SECONDS .toMillis (10 )); //wait bash initialisation
97
-
98
95
InspectContainerResponse inspectContainerResponse = dockerClient .inspectContainerCmd (container .getId ()).exec ();
99
96
100
97
assertTrue (inspectContainerResponse .getState ().getRunning ());
@@ -107,15 +104,20 @@ public void onNext(Frame frame) {
107
104
}
108
105
};
109
106
110
- InputStream stdin = new ByteArrayInputStream ((snippet + "\n " ).getBytes ());
107
+ PipedOutputStream out = new PipedOutputStream ();
108
+ PipedInputStream in = new PipedInputStream (out );
111
109
112
110
dockerClient .attachContainerCmd (container .getId ())
113
111
.withStdErr (true )
114
112
.withStdOut (true )
115
113
.withFollowStream (true )
116
- .withStdIn (stdin )
117
- .exec (callback )
118
- .awaitCompletion (30 , SECONDS );
114
+ .withStdIn (in )
115
+ .exec (callback );
116
+
117
+ out .write ((snippet + "\n " ).getBytes ());
118
+ out .flush ();
119
+
120
+ callback .awaitCompletion (15 , SECONDS );
119
121
callback .close ();
120
122
121
123
assertThat (callback .toString (), containsString (snippet ));
0 commit comments