@@ -42,9 +42,9 @@ public class LogContainerCmdIT extends CmdIT {
4242 public void asyncLogContainerWithTtyEnabled () throws Exception {
4343
4444 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
45- .withCmd ("/bin/sh" , "-c" , "while true; do echo hello; sleep 1; done" )
46- .withTty (true )
47- .exec ();
45+ .withCmd ("/bin/sh" , "-c" , "while true; do echo hello; sleep 1; done" )
46+ .withTty (true )
47+ .exec ();
4848
4949 LOG .info ("Created container: {}" , container .toString ());
5050 assertThat (container .getId (), not (is (emptyString ())));
@@ -73,9 +73,9 @@ public void asyncLogContainerWithTtyEnabled() throws Exception {
7373 public void asyncLogContainerWithTtyDisabled () throws Exception {
7474
7575 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
76- .withCmd ("/bin/sh" , "-c" , "while true; do echo hello; sleep 1; done" )
77- .withTty (false )
78- .exec ();
76+ .withCmd ("/bin/sh" , "-c" , "while true; do echo hello; sleep 1; done" )
77+ .withTty (false )
78+ .exec ();
7979
8080 LOG .info ("Created container: {}" , container .toString ());
8181 assertThat (container .getId (), not (is (emptyString ())));
@@ -122,11 +122,13 @@ public void onError(Throwable throwable) {
122122 public void onComplete () {
123123 super .onComplete ();
124124 throw new AssertionError ("expected NotFoundException" );
125- };
125+ }
126+
127+ ;
126128 };
127129
128130 dockerRule .getClient ().logContainerCmd ("non-existing" ).withStdErr (true ).withStdOut (true ).exec (loggingCallback )
129- .awaitCompletion ();
131+ .awaitCompletion ();
130132 }
131133
132134 @ Test
@@ -135,44 +137,44 @@ public void asyncMultipleLogContainer() throws Exception {
135137 String snippet = "hello world" ;
136138
137139 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
138- .withCmd ("/bin/echo" , snippet )
139- .exec ();
140+ .withCmd ("/bin/echo" , snippet )
141+ .exec ();
140142
141143 LOG .info ("Created container: {}" , container .toString ());
142144 assertThat (container .getId (), not (is (emptyString ())));
143145
144146 dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
145147
146148 int exitCode = dockerRule .getClient ().waitContainerCmd (container .getId ())
147- .start ()
148- .awaitStatusCode ();
149+ .start ()
150+ .awaitStatusCode ();
149151
150152 assertThat (exitCode , equalTo (0 ));
151153
152154 LogContainerTestCallback loggingCallback = new LogContainerTestCallback ();
153155
154156 dockerRule .getClient ().logContainerCmd (container .getId ())
155- .withStdErr (true )
156- .withStdOut (true )
157- .exec (loggingCallback );
157+ .withStdErr (true )
158+ .withStdOut (true )
159+ .exec (loggingCallback );
158160
159161 loggingCallback .close ();
160162
161163 loggingCallback = new LogContainerTestCallback ();
162164
163165 dockerRule .getClient ().logContainerCmd (container .getId ())
164- .withStdErr (true )
165- .withStdOut (true )
166- .exec (loggingCallback );
166+ .withStdErr (true )
167+ .withStdOut (true )
168+ .exec (loggingCallback );
167169
168170 loggingCallback .close ();
169171
170172 loggingCallback = new LogContainerTestCallback ();
171173
172174 dockerRule .getClient ().logContainerCmd (container .getId ())
173- .withStdErr (true )
174- .withStdOut (true )
175- .exec (loggingCallback );
175+ .withStdErr (true )
176+ .withStdOut (true )
177+ .exec (loggingCallback );
176178
177179 loggingCallback .awaitCompletion ();
178180
@@ -184,8 +186,8 @@ public void asyncLogContainerWithSince() throws Exception {
184186 String snippet = "hello world" ;
185187
186188 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
187- .withCmd ("/bin/echo" , snippet )
188- .exec ();
189+ .withCmd ("/bin/echo" , snippet )
190+ .exec ();
189191
190192 LOG .info ("Created container: {}" , container .toString ());
191193 assertThat (container .getId (), not (is (emptyString ())));
@@ -195,18 +197,19 @@ public void asyncLogContainerWithSince() throws Exception {
195197 dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
196198
197199 int exitCode = dockerRule .getClient ().waitContainerCmd (container .getId ())
198- .start ()
199- .awaitStatusCode ();
200+ .start ()
201+ .awaitStatusCode ();
200202
201203 assertThat (exitCode , equalTo (0 ));
202204
203205 LogContainerTestCallback loggingCallback = new LogContainerTestCallback ();
204206
205207 dockerRule .getClient ().logContainerCmd (container .getId ())
206- .withStdErr (true )
207- .withStdOut (true )
208- .withSince (timestamp )
209- .exec (loggingCallback );
208+ .withStdErr (true )
209+ .withStdOut (true )
210+ .withSince (timestamp )
211+ .withUntil (timestamp + 1000 )
212+ .exec (loggingCallback );
210213
211214 loggingCallback .awaitCompletion ();
212215
@@ -218,8 +221,8 @@ public void simultaneousCommands() throws Exception {
218221 // Create a new client to not affect other tests
219222 DockerClient client = dockerRule .newClient ();
220223 CreateContainerResponse container = client .createContainerCmd ("busybox" )
221- .withCmd ("/bin/sh" , "-c" , "echo hello world; sleep infinity" )
222- .exec ();
224+ .withCmd ("/bin/sh" , "-c" , "echo hello world; sleep infinity" )
225+ .exec ();
223226
224227 client .startContainerCmd (container .getId ()).exec ();
225228
@@ -261,64 +264,41 @@ public void onNext(Frame object) {
261264 }
262265 }
263266
264- @ Test (timeout = 10_000 )
265- public void asyncLongDockerLogCmd () throws Exception {
267+
268+ @ Test
269+ public void asyncLogContainerWithTailAll () throws Exception {
266270 // Create a new client to not affect other tests
267- DockerClient client = dockerRule .newClient ();
268271 String testImage = "icevivek/logreader" ;
269272
270273 // Pulling image icevivek/logreader
271274 try {
272- client .inspectImageCmd (testImage ).exec ();
275+ dockerRule . getClient () .inspectImageCmd (testImage ).exec ();
273276 } catch (NotFoundException e ) {
274277 LOG .info ("Pulling image " );
275278 // need to block until image is pulled completely
276- client . pullImageCmd ("icevivek/logreader " )
279+ dockerRule . getClient (). pullImageCmd ("testImage " )
277280 .withTag ("latest" )
278281 .start ()
279- .awaitCompletion ();
282+ .awaitCompletion (30 , TimeUnit . SECONDS );
280283 }
281284
282- CreateContainerResponse container = client .createContainerCmd ("icevivek/logreader" )
285+ CreateContainerResponse container = dockerRule . getClient () .createContainerCmd ("icevivek/logreader" )
283286 .exec ();
284287
285- client .startContainerCmd (container .getId ()).exec ();
286-
287- // Simulate 100 simultaneous connections
288- int connections = 100 ;
289-
290- ExecutorService executor = Executors .newFixedThreadPool (connections );
291- try {
292- List <Frame > firstFrames = new CopyOnWriteArrayList <>();
293- executor .invokeAll (
294- LongStream .range (0 , connections ).<Callable <Object >>mapToObj (__ -> {
295- return () -> {
296- return client .logContainerCmd (container .getId ())
297- .withStdOut (true )
298- .withFollowStream (true )
299- .exec (new ResultCallback .Adapter <Frame >() {
288+ dockerRule .getClient ().startContainerCmd (container .getId ()).exec ();
300289
301- final AtomicBoolean first = new AtomicBoolean (true );
290+ LogContainerTestCallback loggingCallback = new LogContainerTestCallback (true );
302291
303- @ Override
304- public void onNext (Frame object ) {
305- if (first .compareAndSet (true , false )) {
306- firstFrames .add (object );
307- }
308- super .onNext (object );
309- }
310- });
311- };
312- }).collect (Collectors .toList ())
313- );
292+ // this essentially test the since=0 case
293+ dockerRule .getClient ().logContainerCmd (container .getId ())
294+ .withStdErr (true )
295+ .withStdOut (true )
296+ .withFollowStream (true )
297+ .withTailAll ()
298+ .exec (loggingCallback );
314299
315- await ().atMost (30 , TimeUnit .SECONDS ).untilAsserted (() -> {
316- assertThat (firstFrames , hasSize (connections ));
317- });
300+ loggingCallback .awaitCompletion (30 , TimeUnit .SECONDS );
318301
319- assertThat (firstFrames .size (), is (187 ));
320- } finally {
321- executor .shutdownNow ();
322- }
302+ assertThat (loggingCallback .getCollectedFrames (), hasSize (187 ));
323303 }
324304}
0 commit comments