use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldStoreLastProcessedAfterInactivity.
@Test
void autoShouldStoreLastProcessedAfterInactivity() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
int storeEvery = 10;
int extraMessages = 3;
long expectedLastStoredOffset = storeEvery + extraMessages - 1;
when(consumer.lastStoredOffset()).thenReturn((long) (storeEvery - 1));
ArgumentCaptor<Long> lastStoredOffsetCaptor = ArgumentCaptor.forClass(Long.class);
CountDownLatch flushLatch = new CountDownLatch(1);
doAnswer(answer(inv -> flushLatch.countDown())).when(consumer).store(lastStoredOffsetCaptor.capture());
Duration autoFlushInterval = Duration.ofMillis(checkInterval.toMillis() * 2);
Consumer<Context> postProcessedMessageCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, storeEvery, autoFlushInterval, Duration.ZERO)).postMessageProcessingCallback();
IntStream.range(0, storeEvery + extraMessages).forEach(offset -> {
postProcessedMessageCallback.accept(context(offset, () -> {
}));
});
assertThat(latchAssert(flushLatch)).completes(5);
verify(consumer, times(1)).store(anyLong());
assertThat(lastStoredOffsetCaptor.getValue()).isEqualTo(expectedLastStoredOffset);
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldNotFlushAfterInactivityIfLastStoreIsOnModulo.
@Test
void autoShouldNotFlushAfterInactivityIfLastStoreIsOnModulo() throws Exception {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
int storeEvery = 10;
when(consumer.lastStoredOffset()).thenReturn((long) storeEvery - 1);
Duration autoFlushInterval = Duration.ofMillis(checkInterval.toMillis() * 2);
Consumer<Context> postProcessedMessageCallback = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, storeEvery, autoFlushInterval, Duration.ZERO)).postMessageProcessingCallback();
IntStream.range(0, storeEvery).forEach(offset -> {
postProcessedMessageCallback.accept(context(offset, () -> {
}));
});
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 autoShouldNotStoreLastProcessedOffsetOnClosingIfBehindStoredOffset.
@Test
void autoShouldNotStoreLastProcessedOffsetOnClosingIfBehindStoredOffset() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
when(consumer.lastStoredOffset()).thenReturn(15L);
Registration registration = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, Duration.ofHours(1), Duration.ZERO));
long lastProcessedOffset = 10;
registration.postMessageProcessingCallback().accept(context(lastProcessedOffset, () -> {
}));
registration.closingCallback().run();
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 autoShouldStoreLastProcessedOffsetOnClosing.
@Test
void autoShouldStoreLastProcessedOffsetOnClosing() {
Duration checkInterval = Duration.ofMillis(100);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
when(consumer.lastStoredOffset()).thenReturn(5L);
Registration registration = coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 1, Duration.ofHours(1), Duration.ZERO));
long lastProcessedOffset = 10;
registration.postMessageProcessingCallback().accept(context(lastProcessedOffset, () -> {
}));
registration.closingCallback().run();
verify(consumer, times(1)).store(lastProcessedOffset);
}
use of com.rabbitmq.stream.impl.StreamConsumerBuilder.TrackingConfiguration in project rabbitmq-stream-java-client by rabbitmq.
the class OffsetTrackingCoordinatorTest method autoShouldNotStoreIfNoMessagesArrive.
@Test
void autoShouldNotStoreIfNoMessagesArrive() throws Exception {
Duration checkInterval = Duration.ofMillis(10);
OffsetTrackingCoordinator coordinator = new OffsetTrackingCoordinator(env, checkInterval);
coordinator.registerTrackingConsumer(consumer, new TrackingConfiguration(true, true, 100, Duration.ofMillis(200), Duration.ZERO));
Thread.sleep(3 * checkInterval.toMillis());
verify(consumer, never()).store(anyLong());
}
Aggregations