use of com.rabbitmq.stream.impl.Client.StreamMetadata in project rabbitmq-stream-java-client by rabbitmq.
the class StreamEnvironmentTest method environmentPublishersConsumersShouldCloseSuccessfullyWhenBrokerIsDown.
@Test
@TestUtils.DisabledIfRabbitMqCtlNotSet
void environmentPublishersConsumersShouldCloseSuccessfullyWhenBrokerIsDown() throws Exception {
Environment environment = environmentBuilder.recoveryBackOffDelayPolicy(BackOffDelayPolicy.fixed(Duration.ofSeconds(10))).build();
CountDownLatch consumeLatch = new CountDownLatch(2);
Consumer consumer = environment.consumerBuilder().stream(stream).messageHandler((context, message) -> consumeLatch.countDown()).build();
// will be closed by the environment
environment.consumerBuilder().stream(stream).messageHandler((context, message) -> consumeLatch.countDown()).build();
Producer producer = environment.producerBuilder().stream(stream).build();
// will be closed by the environment
environment.producerBuilder().stream(stream).build();
producer.send(producer.messageBuilder().addData("".getBytes(StandardCharsets.UTF_8)).build(), confirmationStatus -> {
});
latchAssert(consumeLatch).completes();
try {
Host.rabbitmqctl("stop_app");
producer.close();
consumer.close();
environment.close();
} finally {
Host.rabbitmqctl("start_app");
}
waitAtMost(30, () -> {
Client client = cf.get();
Map<String, StreamMetadata> metadata = client.metadata(stream);
return metadata.containsKey(stream) && metadata.get(stream).isResponseOk();
});
}
Aggregations