use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldNotStoreIfOffsetAlreadyStored.
@Test
void autoShouldNotStoreIfOffsetAlreadyStored() throws Exception {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
long storedOffset = 10;
when(consumer.lastStoredOffset()).thenReturn(storedOffset);
Duration autoFlushInterval = Duration.ofMillis(checkInterval.toMillis() * 2);
Consumer<Context> postProcessedMessageCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, autoFlushInterval, Duration.ZERO)).postMessageProcessingCallback();
postProcessedMessageCallback.accept(context(10, () -> {
}));
Thread.sleep(autoFlushInterval.multipliedBy(4).toMillis());
verify(consumer, never()).store(anyLong());
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldStoreAfterSomeInactivity.
@Test
void autoShouldStoreAfterSomeInactivity() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
CountDownLatch flushLatch = new CountDownLatch(1);
doAnswer(answer(inv -> flushLatch.countDown())).when(consumer).store(anyLong());
Consumer<Context> postProcessedMessageCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, Duration.ofMillis(200), Duration.ZERO)).postMessageProcessingCallback();
postProcessedMessageCallback.accept(context(1, () -> {
}));
assertThat(latchAssert(flushLatch)).completes(5);
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method manualShouldNotStoreIfAlreadyUpToDate.
@Test
void manualShouldNotStoreIfAlreadyUpToDate() throws Exception {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
long lastStoredOffset = 50;
when(consumer.lastStoredOffset()).thenReturn(lastStoredOffset);
LongConsumer storeCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, false, -1, Duration.ZERO, checkInterval.multipliedBy(2))).trackingCallback();
storeCallback.accept(lastStoredOffset);
Thread.sleep(3 * checkInterval.toMillis());
verify(consumer, never()).store(anyLong());
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method manualShouldStoreIfRequestedStoredOffsetIsBehind.
@Test
void manualShouldStoreIfRequestedStoredOffsetIsBehind() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
long lastRequestedOffset = 50;
long lastStoredOffset = 40;
when(consumer.lastStoredOffset()).thenReturn(lastStoredOffset);
ArgumentCaptor<Long> lastStoredOffsetCaptor = ArgumentCaptor.forClass(Long.class);
CountDownLatch storeLatch = new CountDownLatch(1);
doAnswer(answer(inv -> storeLatch.countDown())).when(consumer).store(lastStoredOffsetCaptor.capture());
LongConsumer storeCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, false, -1, Duration.ZERO, checkInterval.multipliedBy(2))).trackingCallback();
storeCallback.accept(lastRequestedOffset);
assertThat(latchAssert(storeLatch)).completes(5);
verify(consumer, times(1)).store(anyLong());
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldStoreFixedMessageCountAndAutoTrackingAfterInactivity.
@Test
void autoShouldStoreFixedMessageCountAndAutoTrackingAfterInactivity() {
Duration checkInterval = Duration.ofMillis(100);
coordinator = new OffsetTrackingCoordinator(env, checkInterval);
CountDownLatch flushLatch = new CountDownLatch(1);
doAnswer(answer(inv -> flushLatch.countDown())).when(consumer).store(anyLong());
int messageInterval = 100;
int messageCount = 5 * messageInterval + messageInterval / 5;
Consumer<Context> postProcessedMessageCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, messageInterval, Duration.ofMillis(200), Duration.ZERO)).postMessageProcessingCallback();
AtomicInteger storedCountAfterProcessing = new AtomicInteger(0);
IntStream.range(0, messageCount).forEach(i -> {
postProcessedMessageCallback.accept(context(i, () -> storedCountAfterProcessing.incrementAndGet()));
});
assertThat(latchAssert(flushLatch)).completes(5);
assertThat(storedCountAfterProcessing.get()).isEqualTo(messageCount / messageInterval);
}
Aggregations