@Override public boolean conditionMet() { return result.listings().isDone(); } }, "Timed out waiting for listTopics to complete");
waiterThreads.add(new WaiterThread<>(futures.get(i), i)); assertFalse(allFuture.isDone()); for (int i = 0; i < numThreads; i++) { waiterThreads.get(i).start(); completerThreads.get(i).start(); assertFalse(allFuture.isDone()); completerThreads.get(numThreads - 1).start(); allFuture.get(); assertTrue(allFuture.isDone()); for (int i = 0; i < numThreads; i++) { assertEquals(Integer.valueOf(i), futures.get(i).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()); }
@Test public void testAllOfFuturesHandlesZeroFutures() throws Exception { KafkaFuture<Void> allFuture = KafkaFuture.allOf(); assertTrue(allFuture.isDone()); assertFalse(allFuture.isCancelled()); assertFalse(allFuture.isCompletedExceptionally()); allFuture.get(); }
@Override protected boolean complete() { if (this.descFuture.isDone() && this.configFuture.isDone()) { final TopicDescription desc = result(this.descFuture); final Config config = result(this.configFuture); if (!handled) { TopicMetadata metadata; if (desc != null && config != null) { metadata = new TopicMetadata(desc, config); } else { metadata = null; } this.handler.handle(Future.succeededFuture(metadata)); this.handled = true; LOGGER.trace("Handler for work {} executed ok", this); } else { } return handled; } else { if (!this.descFuture.isDone()) LOGGER.trace("Description future {} is not done", descFuture); if (!this.configFuture.isDone()) LOGGER.trace("Config future {} is not done", configFuture); return false; } } }
@Override protected boolean complete() { if (this.future.isDone()) { LOGGER.trace("Future {} of work {} is done", future, this); try { try { T result = this.future.get(); LOGGER.debug("Future {} has result {}", future, result); this.handler.handle(Future.succeededFuture(result)); LOGGER.debug("Handler for work {} executed ok", this); } catch (ExecutionException e) { LOGGER.debug("Future {} threw {}", future, e.toString()); this.handler.handle(Future.failedFuture(e.getCause())); } catch (InterruptedException e) { LOGGER.debug("Future {} threw {}", future, e.toString()); this.handler.handle(Future.failedFuture(e)); } } catch (OperatorException e) { // TODO handler threw, but I have no context for creating a k8s error event LOGGER.trace("Handler for work {} threw {}", this, e.toString()); e.printStackTrace(); } return true; } else { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Future {} is not done", future); } return false; } }
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); } }