public TestableReceiver createTestFlux() { KafkaReceiver<Integer, String> receiver = createReceiver(); Flux<ReceiverRecord<Integer, String>> kafkaFlux = receiver.receive(); return new TestableReceiver(receiver, kafkaFlux); }
private void testManualCommitRetry(boolean retriableException) throws Exception { int count = 1; int failureCount = 2; Semaphore receiveSemaphore = new Semaphore(1 - count); Semaphore commitSuccessSemaphore = new Semaphore(0); Semaphore commitFailureSemaphore = new Semaphore(0); receiverOptions = receiverOptions.commitInterval(Duration.ZERO).commitBatchSize(0); KafkaReceiver<Integer, String> receiver = createReceiver(); TestableReceiver testableReceiver = new TestableReceiver(receiver); Flux<? extends ConsumerRecord<Integer, String>> flux = testableReceiver .receiveWithManualCommitFailures(retriableException, failureCount, receiveSemaphore, commitSuccessSemaphore, commitFailureSemaphore); subscribe(flux, new CountDownLatch(count)); sendMessages(1, count); assertTrue("Did not receive messages", receiveSemaphore.tryAcquire(receiveTimeoutMillis, TimeUnit.MILLISECONDS)); assertTrue("Commit did not succeed after retry", commitSuccessSemaphore.tryAcquire(receiveTimeoutMillis, TimeUnit.MILLISECONDS)); assertEquals(failureCount, commitFailureSemaphore.availablePermits()); }
private void restartAndCheck(KafkaReceiver<Integer, String> receiver, int sendStartIndex, int sendCount, int maxRedelivered) throws Exception { Thread.sleep(500); // Give a little time for commits to complete before terminating abruptly new TestableReceiver(receiver).terminate(); cancelSubscriptions(true); clearReceivedMessages(); Flux<? extends ConsumerRecord<Integer, String>> kafkaFlux2 = createReceiver().receiveAtmostOnce(); sendReceiveWithRedelivery(kafkaFlux2, sendStartIndex, sendCount, 0, maxRedelivered); clearReceivedMessages(); cancelSubscriptions(false); }
TestableReceiver testReceiver = new TestableReceiver(receiver); Semaphore onNextSemaphore = new Semaphore(0); Flux<ReceiverRecord<Integer, String>> flux = receiver.receive()