@Test public void testAllOfFuturesHandlesZeroFutures() throws Exception { KafkaFuture<Void> allFuture = KafkaFuture.allOf(); assertTrue(allFuture.isDone()); assertFalse(allFuture.isCancelled()); assertFalse(allFuture.isCompletedExceptionally()); allFuture.get(); }
@Test public void testThenApply() throws Exception { KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>(); KafkaFuture<Integer> doubledFuture = future.thenApply(integer -> 2 * integer); assertFalse(doubledFuture.isDone()); KafkaFuture<Integer> tripledFuture = future.thenApply(integer -> 3 * integer); assertFalse(tripledFuture.isDone()); future.complete(21); assertEquals(Integer.valueOf(21), future.getNow(-1)); assertEquals(Integer.valueOf(42), doubledFuture.getNow(-1)); assertEquals(Integer.valueOf(63), tripledFuture.getNow(-1)); KafkaFuture<Integer> quadrupledFuture = future.thenApply(integer -> 4 * integer); assertEquals(Integer.valueOf(84), quadrupledFuture.getNow(-1)); KafkaFutureImpl<Integer> futureFail = new KafkaFutureImpl<>(); KafkaFuture<Integer> futureAppliedFail = futureFail.thenApply(integer -> 2 * integer); futureFail.completeExceptionally(new RuntimeException()); assertTrue(futureFail.isCompletedExceptionally()); assertTrue(futureAppliedFail.isCompletedExceptionally()); }
void maybePurgeCommitedRecords() { // we do not check any possible exceptions since none of them are fatal // that should cause the application to fail, and we will try delete with // newer offsets anyways. if (deleteRecordsResult == null || deleteRecordsResult.all().isDone()) { if (deleteRecordsResult != null && deleteRecordsResult.all().isCompletedExceptionally()) { log.debug("Previous delete-records request has failed: {}. Try sending the new request now", deleteRecordsResult.lowWatermarks()); } final Map<TopicPartition, RecordsToDelete> recordsToDelete = new HashMap<>(); for (final Map.Entry<TopicPartition, Long> entry : active.recordsToDelete().entrySet()) { recordsToDelete.put(entry.getKey(), RecordsToDelete.beforeOffset(entry.getValue())); } deleteRecordsResult = adminClient.deleteRecords(recordsToDelete); log.trace("Sent delete-records request: {}", recordsToDelete); } }