Skip to content

Commit b450249

Browse files
committed
Add test with asynchronous processing
To test flow control.
1 parent 9861ef0 commit b450249

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/test/java/com/rabbitmq/stream/impl/StreamConsumerTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import static com.rabbitmq.stream.ConsumerFlowStrategy.creditWhenHalfMessagesProcessed;
1717
import static com.rabbitmq.stream.impl.TestUtils.*;
18+
import static com.rabbitmq.stream.impl.TestUtils.CountDownLatchConditions.completed;
19+
import static java.lang.Runtime.getRuntime;
1820
import static java.lang.String.format;
1921
import static java.util.Collections.synchronizedList;
2022
import static org.assertj.core.api.Assertions.*;
@@ -236,6 +238,35 @@ void consumeWithAsyncConsumerFlowControl() throws Exception {
236238
consumer.close();
237239
}
238240

241+
@Test
242+
void asynchronousProcessingWithFlowControl() {
243+
int messageCount = 100_000;
244+
TestUtils.publishAndWaitForConfirms(cf, messageCount, stream);
245+
246+
ExecutorService executorService =
247+
Executors.newFixedThreadPool(getRuntime().availableProcessors());
248+
try {
249+
CountDownLatch latch = new CountDownLatch(messageCount);
250+
environment.consumerBuilder().stream(stream)
251+
.offset(OffsetSpecification.first())
252+
.flow()
253+
.strategy(creditWhenHalfMessagesProcessed())
254+
.builder()
255+
.messageHandler(
256+
(ctx, message) -> {
257+
executorService.submit(
258+
() -> {
259+
latch.countDown();
260+
ctx.processed();
261+
});
262+
})
263+
.build();
264+
assertThat(latch).is(completed());
265+
} finally {
266+
executorService.shutdownNow();
267+
}
268+
}
269+
239270
@Test
240271
void closeOnCondition() throws Exception {
241272
int messageCount = 50_000;

0 commit comments

Comments
 (0)