1010import org .testng .annotations .BeforeTest ;
1111import org .testng .annotations .Test ;
1212
13+ import java .io .IOException ;
1314import java .io .InputStream ;
1415
1516@ Test (groups = "integration" )
@@ -41,20 +42,52 @@ public void afterTest() {
4142 }
4243
4344 @ Test
44- public void canCloseFrameReaderAndReadExpectedLinens () throws Exception {
45+ public void canCloseFrameReaderAndReadExpectedLines () throws Exception {
4546
46- InputStream log = dockerClient
47+ try (FrameReader reader = new FrameReader (getLoggerStream ())) {
48+ assertEquals (reader .readFrame (), new Frame (StreamType .STDOUT , String .format ("to stdout%n" ).getBytes ()));
49+ assertEquals (reader .readFrame (), new Frame (StreamType .STDERR , String .format ("to stderr%n" ).getBytes ()));
50+ assertNull (reader .readFrame ());
51+ }
52+ }
53+
54+ private InputStream getLoggerStream () {
55+ return dockerClient
4756 .logContainerCmd (dockerfileFixture .getContainerId ())
4857 .withStdOut ()
4958 .withStdErr ()
50- .withFollowStream ()
5159 .withTailAll ()
60+ .withTail (10 )
61+ .withFollowStream ()
5262 .exec ();
63+ }
5364
54- try (FrameReader reader = new FrameReader (log )) {
55- assertEquals (reader .readFrame (), new Frame (StreamType .STDOUT , String .format ("to stdout%n" ).getBytes ()));
56- assertEquals (reader .readFrame (), new Frame (StreamType .STDERR , String .format ("to stderr%n" ).getBytes ()));
57- assertNull (reader .readFrame ());
65+ @ Test
66+ public void canLogInOneThreadAndExecuteCommandsInAnother () throws Exception {
67+
68+ Thread thread = new Thread (new Runnable () {
69+ @ Override
70+ public void run () {
71+ try {
72+ try (FrameReader reader = new FrameReader (getLoggerStream ())) {
73+ //noinspection StatementWithEmptyBody
74+ while (reader .readFrame () != null ) {
75+ // nop
76+ }
77+ }
78+ } catch (IOException e ) {
79+ throw new RuntimeException (e );
80+ }
81+ }
82+ });
83+
84+ thread .start ();
85+
86+ try (DockerfileFixture busyboxDockerfile = new DockerfileFixture (dockerClient , "busyboxDockerfile" )) {
87+ busyboxDockerfile .open ();
5888 }
89+
90+ thread .join ();
91+
5992 }
6093}
0 commit comments