use of com.rabbitmq.stream.impl.MonitoringTestUtils.ProducerInfo in project rabbitmq-stream-java-client by rabbitmq.
the class StreamProducerTest method send.
@Test
void send() throws Exception {
int batchSize = 10;
// don't want a multiple of batch size
int messageCount = 10 * batchSize + 1;
CountDownLatch publishLatch = new CountDownLatch(messageCount);
Producer producer = environment.producerBuilder().stream(stream).batchSize(batchSize).build();
AtomicLong count = new AtomicLong(0);
AtomicLong sequence = new AtomicLong(0);
Set<Long> idsSent = ConcurrentHashMap.newKeySet(messageCount);
Set<Long> idsConfirmed = ConcurrentHashMap.newKeySet(messageCount);
IntStream.range(0, messageCount).forEach(i -> {
long id = sequence.getAndIncrement();
idsSent.add(id);
producer.send(producer.messageBuilder().properties().messageId(id).messageBuilder().addData("".getBytes()).build(), confirmationStatus -> {
idsConfirmed.add(confirmationStatus.getMessage().getProperties().getMessageIdAsLong());
count.incrementAndGet();
publishLatch.countDown();
});
});
boolean completed = publishLatch.await(10, TimeUnit.SECONDS);
assertThat(idsSent).hasSameSizeAs(idsConfirmed);
idsSent.forEach(idSent -> assertThat(idsConfirmed).contains(idSent));
assertThat(completed).isTrue();
ProducerInfo info = MonitoringTestUtils.extract(producer);
assertThat(info.getId()).isGreaterThanOrEqualTo(0);
assertThat(info.getStream()).isEqualTo(stream);
assertThat(info.getPublishingClient()).contains(" -> localhost:5552");
}
Aggregations