|
3 | 3 | import com.github.dockerjava.api.async.ResultCallback; |
4 | 4 | import com.github.dockerjava.api.command.CreateContainerResponse; |
5 | 5 | import com.github.dockerjava.api.model.Event; |
| 6 | +import com.github.dockerjava.api.model.EventType; |
6 | 7 | import com.github.dockerjava.utils.TestUtils; |
7 | 8 | import org.junit.Test; |
8 | 9 | import org.slf4j.Logger; |
9 | 10 | import org.slf4j.LoggerFactory; |
10 | 11 |
|
11 | 12 | import java.util.ArrayList; |
12 | 13 | import java.util.List; |
| 14 | +import java.util.concurrent.CopyOnWriteArrayList; |
13 | 15 | import java.util.concurrent.CountDownLatch; |
14 | 16 | import java.util.concurrent.TimeUnit; |
15 | 17 |
|
@@ -113,6 +115,37 @@ public void testEventStreamingWithFilter() throws Exception { |
113 | 115 | } |
114 | 116 | } |
115 | 117 |
|
| 118 | + @Test |
| 119 | + public void testEventStreamingWithEventTypeFilter() throws Exception { |
| 120 | + assumeNotSwarm("", dockerRule); |
| 121 | + |
| 122 | + String startTime = getEpochTime(); |
| 123 | + generateEvents(); |
| 124 | + String endTime = getEpochTime(); |
| 125 | + |
| 126 | + for (EventType eventType : EventType.values()) { |
| 127 | + List<Event> events = new CopyOnWriteArrayList<>(); |
| 128 | + try ( |
| 129 | + ResultCallback.Adapter<?> eventCallback = dockerRule.getClient().eventsCmd() |
| 130 | + .withSince(startTime) |
| 131 | + .withUntil(endTime) |
| 132 | + .withEventTypeFilter(eventType) |
| 133 | + .exec(new ResultCallback.Adapter<Event>() { |
| 134 | + @Override |
| 135 | + public void onNext(Event event) { |
| 136 | + events.add(event); |
| 137 | + } |
| 138 | + }) |
| 139 | + ) { |
| 140 | + eventCallback.awaitCompletion(30, TimeUnit.SECONDS); |
| 141 | + |
| 142 | + for (Event event : events) { |
| 143 | + assertThat("Received event: " + event, event.getType(), is(eventType)); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + } |
| 148 | + |
116 | 149 | /** |
117 | 150 | * This method generates some events and returns the number of events being generated |
118 | 151 | */ |
|
0 commit comments