17
17
import java .util .List ;
18
18
import java .util .Map ;
19
19
import java .util .UUID ;
20
+ import java .util .concurrent .TimeUnit ;
20
21
21
22
import static ch .lambdaj .Lambda .filter ;
22
23
import static com .github .dockerjava .api .model .HostConfig .newHostConfig ;
@@ -188,16 +189,8 @@ public void testIdsFilter() {
188
189
}
189
190
190
191
@ Test
191
- public void testStatusFilter () {
192
- String id1 , id2 ;
193
- id1 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
194
- .withCmd ("sh" , "-c" , "sleep 99999" )
195
- .withLabels (testLabel )
196
- .exec ()
197
- .getId ();
198
-
199
- id2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
200
- .withCmd ("sh" , "-c" , "sleep 99999" )
192
+ public void shouldFilterByCreatedStatus () {
193
+ String containerId = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
201
194
.withLabels (testLabel )
202
195
.exec ()
203
196
.getId ();
@@ -208,42 +201,67 @@ public void testStatusFilter() {
208
201
.withStatusFilter (singletonList ("created" ))
209
202
.exec ();
210
203
211
- assertThat (filteredContainers .size (), is (2 ));
212
- assertThat (filteredContainers .get (1 ).getId (), isOneOf (id1 , id2 ));
204
+ assertThat (filteredContainers .size (), is (1 ));
205
+ assertThat (filteredContainers .get (0 ).getId (), is (containerId ));
206
+ }
213
207
214
- dockerRule .getClient ().startContainerCmd (id1 ).exec ();
208
+ @ Test
209
+ public void shouldFilterByRunningStatus () {
210
+ String containerId = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
211
+ .withLabels (testLabel )
212
+ .exec ()
213
+ .getId ();
214
+ dockerRule .getClient ().startContainerCmd (containerId ).exec ();
215
215
216
- filteredContainers = dockerRule .getClient ().listContainersCmd ()
216
+ List < Container > filteredContainers = dockerRule .getClient ().listContainersCmd ()
217
217
.withShowAll (true )
218
218
.withLabelFilter (testLabel )
219
219
.withStatusFilter (singletonList ("running" ))
220
220
.exec ();
221
221
222
222
assertThat (filteredContainers .size (), is (1 ));
223
- assertThat (filteredContainers .get (0 ).getId (), is (id1 ));
223
+ assertThat (filteredContainers .get (0 ).getId (), is (containerId ));
224
+ }
224
225
225
- dockerRule .getClient ().pauseContainerCmd (id1 ).exec ();
226
+ @ Test
227
+ public void shouldFilterByPausedStatus () {
228
+ String containerId = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
229
+ .withCmd ("sh" , "-c" , "sleep 99999" )
230
+ .withLabels (testLabel )
231
+ .exec ()
232
+ .getId ();
233
+ dockerRule .getClient ().startContainerCmd (containerId ).exec ();
234
+ dockerRule .getClient ().pauseContainerCmd (containerId ).exec ();
226
235
227
- filteredContainers = dockerRule .getClient ().listContainersCmd ()
236
+ List < Container > filteredContainers = dockerRule .getClient ().listContainersCmd ()
228
237
.withShowAll (true )
229
238
.withLabelFilter (testLabel )
230
239
.withStatusFilter (singletonList ("paused" ))
231
240
.exec ();
232
241
233
242
assertThat (filteredContainers .size (), is (1 ));
234
- assertThat (filteredContainers .get (0 ).getId (), is (id1 ));
243
+ assertThat (filteredContainers .get (0 ).getId (), is (containerId ));
244
+ }
235
245
236
- dockerRule .getClient ().unpauseContainerCmd (id1 ).exec ();
237
- dockerRule .getClient ().stopContainerCmd (id1 ).exec ();
246
+ @ Test
247
+ public void shouldFilterByExitedStatus () throws InterruptedException {
248
+ String containerId = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
249
+ .withCmd ("sh" , "-c" , "sleep 99999" )
250
+ .withLabels (testLabel )
251
+ .exec ()
252
+ .getId ();
253
+ dockerRule .getClient ().startContainerCmd (containerId ).exec ();
254
+ dockerRule .getClient ().stopContainerCmd (containerId ).exec ();
255
+ dockerRule .getClient ().waitContainerCmd (containerId ).start ().awaitCompletion (15 , TimeUnit .SECONDS );
238
256
239
- filteredContainers = dockerRule .getClient ().listContainersCmd ()
257
+ List < Container > filteredContainers = dockerRule .getClient ().listContainersCmd ()
240
258
.withShowAll (true )
241
259
.withLabelFilter (testLabel )
242
260
.withStatusFilter (singletonList ("exited" ))
243
261
.exec ();
244
262
245
263
assertThat (filteredContainers .size (), is (1 ));
246
- assertThat (filteredContainers .get (0 ).getId (), is (id1 ));
264
+ assertThat (filteredContainers .get (0 ).getId (), is (containerId ));
247
265
}
248
266
249
267
@ Test
0 commit comments