|
2 | 2 |
|
3 | 3 | import java.io.IOException; |
4 | 4 | import java.util.ArrayList; |
| 5 | +import java.util.Collection; |
5 | 6 | import java.util.Collections; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.Map; |
@@ -171,25 +172,21 @@ public void test_drainOnClose() throws Exception { |
171 | 172 | // Contrary the test above, we expect the objects to be sent |
172 | 173 | // only after context.close(), as the half-empty batch will |
173 | 174 | // be drained. Similarly, we want to ack everything as it arrives. |
174 | | - Future<?> backgroundAcks = BACKGROUND.submit(() -> { |
| 175 | + BACKGROUND.submit(() -> { |
175 | 176 | try { |
176 | 177 | List<String> received = recvDataAndAck(); |
177 | 178 | Assertions.assertThat(tasks) |
178 | 179 | .extracting(TaskHandle::id).containsExactlyInAnyOrderElementsOf(received); |
179 | 180 | Assertions.assertThat(tasks) |
180 | 181 | .extracting(TaskHandle::isAcked).allMatch(CompletableFuture::isDone); |
181 | | - |
182 | | - // Wait until the Results event's been processed to guarantee |
183 | | - // that the tasks' futures are completed before asserting. |
184 | | - Future<?> results = out.emitEvent(new Event.Results(received, Collections.emptyMap())); |
185 | | - results.get(); |
| 182 | + out.emitEvent(new Event.Results(received, Collections.emptyMap())); |
186 | 183 | } catch (Exception e) { |
187 | 184 | throw new RuntimeException(e); |
188 | 185 | } |
189 | 186 | }); |
190 | 187 |
|
191 | 188 | context.close(); |
192 | | - backgroundAcks.get(); // Wait for the "mock server" to process the data message. |
| 189 | + awaitResults(tasks); |
193 | 190 |
|
194 | 191 | Assertions.assertThat(tasks).extracting(TaskHandle::result) |
195 | 192 | .allMatch(CompletableFuture::isDone) |
@@ -268,6 +265,13 @@ public void test_backoffBacklog() throws Exception { |
268 | 265 |
|
269 | 266 | context.close(); |
270 | 267 |
|
| 268 | + // Wait until the Results event's been processed to guarantee |
| 269 | + // that the tasks' futures are completed before asserting. |
| 270 | + CompletableFuture.allOf( |
| 271 | + tasks.stream().map(TaskHandle::result) |
| 272 | + .toArray(CompletableFuture[]::new)) |
| 273 | + .get(100, TimeUnit.MILLISECONDS); |
| 274 | + |
271 | 275 | Assertions.assertThat(tasks).extracting(TaskHandle::result) |
272 | 276 | .allMatch(CompletableFuture::isDone) |
273 | 277 | .extracting(CompletableFuture::get).extracting(TaskHandle.Result::error) |
@@ -464,6 +468,15 @@ private List<String> recvDataAndAck() throws InterruptedException { |
464 | 468 | return ids; |
465 | 469 | } |
466 | 470 |
|
| 471 | + private void awaitResults(Collection<TaskHandle> tasks) throws Exception { |
| 472 | + // Wait until the Results event's been processed to guarantee |
| 473 | + // that the tasks' futures are completed before asserting. |
| 474 | + CompletableFuture.allOf( |
| 475 | + tasks.stream().map(TaskHandle::result) |
| 476 | + .toArray(CompletableFuture[]::new)) |
| 477 | + .get(100, TimeUnit.MILLISECONDS); |
| 478 | + } |
| 479 | + |
467 | 480 | static String getBeacon(WeaviateProtoBatch.BatchReference reference) { |
468 | 481 | return "weaviate://localhost/" + reference.getToCollection() + "/" + reference.getToUuid(); |
469 | 482 | } |
|
0 commit comments