Advertisement
ILyaCyclone

Untitled

Mar 25th, 2024
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. List<String> actual = new CopyOnWriteArrayList<>();
  2. ExecutorService service = Executors.newSingleThreadExecutor();
  3. Future<?> consumingTask = service.submit(() -> {
  4.   while (!Thread.currentThread().isInterrupted()) {
  5.     ConsumerRecords<String, String> records =
  6.       consumer.poll(Duration.ofMillis(100));
  7.     for (ConsumerRecord<String, String> rec : records) {
  8.       actual.add(rec.value());
  9.     }
  10.   }
  11. });
  12.  
  13. ...
  14.  
  15. try {
  16.   Awaitility.await().atMost(5, Seconds)
  17.     .until(() -> List.of("A", "B").equals(actual));
  18. } finally {
  19.   consumingTask.cancel(true);
  20.   service.awaitTermintion(200, MILLISECONDS);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement