Search in sources :

Example 1 with StreamMetadata

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();
    });
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SNIHostName(javax.net.ssl.SNIHostName) Message(com.rabbitmq.stream.Message) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) TestUtils.streamName(com.rabbitmq.stream.impl.TestUtils.streamName) AuthenticationFailureException(com.rabbitmq.stream.AuthenticationFailureException) AfterAll(org.junit.jupiter.api.AfterAll) StreamException(com.rabbitmq.stream.StreamException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) ConsumerBuilder(com.rabbitmq.stream.ConsumerBuilder) Duration(java.time.Duration) Map(java.util.Map) Host(com.rabbitmq.stream.Host) TestUtils.waitAtMost(com.rabbitmq.stream.impl.TestUtils.waitAtMost) Collection(java.util.Collection) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) BackOffDelayPolicy(com.rabbitmq.stream.BackOffDelayPolicy) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) StreamCreator(com.rabbitmq.stream.StreamCreator) SslHandler(io.netty.handler.ssl.SslHandler) ProducerBuilder(com.rabbitmq.stream.ProducerBuilder) Constants(com.rabbitmq.stream.Constants) OffsetSpecification(com.rabbitmq.stream.OffsetSpecification) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IntStream(java.util.stream.IntStream) SSLParameters(javax.net.ssl.SSLParameters) StreamMetadata(com.rabbitmq.stream.impl.Client.StreamMetadata) TestUtils.latchAssert(com.rabbitmq.stream.impl.TestUtils.latchAssert) Address(com.rabbitmq.stream.Address) ConfirmationHandler(com.rabbitmq.stream.ConfirmationHandler) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) EnvironmentInfo(com.rabbitmq.stream.impl.MonitoringTestUtils.EnvironmentInfo) ConnectException(java.net.ConnectException) ChannelCustomizer(com.rabbitmq.stream.ChannelCustomizer) ValueSource(org.junit.jupiter.params.provider.ValueSource) EventLoopGroup(io.netty.channel.EventLoopGroup) Environment(com.rabbitmq.stream.Environment) Consumer(com.rabbitmq.stream.Consumer) Producer(com.rabbitmq.stream.Producer) EnvironmentBuilder(com.rabbitmq.stream.EnvironmentBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisabledIfTlsNotEnabled(com.rabbitmq.stream.impl.TestUtils.DisabledIfTlsNotEnabled) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestUtils.localhost(com.rabbitmq.stream.impl.TestUtils.localhost) TestUtils.localhostTls(com.rabbitmq.stream.impl.TestUtils.localhostTls) StreamMetadata(com.rabbitmq.stream.impl.Client.StreamMetadata) Consumer(com.rabbitmq.stream.Consumer) Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Address (com.rabbitmq.stream.Address)1 AuthenticationFailureException (com.rabbitmq.stream.AuthenticationFailureException)1 BackOffDelayPolicy (com.rabbitmq.stream.BackOffDelayPolicy)1 ChannelCustomizer (com.rabbitmq.stream.ChannelCustomizer)1 ConfirmationHandler (com.rabbitmq.stream.ConfirmationHandler)1 Constants (com.rabbitmq.stream.Constants)1 Consumer (com.rabbitmq.stream.Consumer)1 ConsumerBuilder (com.rabbitmq.stream.ConsumerBuilder)1 Environment (com.rabbitmq.stream.Environment)1 EnvironmentBuilder (com.rabbitmq.stream.EnvironmentBuilder)1 Host (com.rabbitmq.stream.Host)1 Message (com.rabbitmq.stream.Message)1 OffsetSpecification (com.rabbitmq.stream.OffsetSpecification)1 Producer (com.rabbitmq.stream.Producer)1 ProducerBuilder (com.rabbitmq.stream.ProducerBuilder)1 StreamCreator (com.rabbitmq.stream.StreamCreator)1 StreamException (com.rabbitmq.stream.StreamException)1 StreamMetadata (com.rabbitmq.stream.impl.Client.StreamMetadata)1 EnvironmentInfo (com.rabbitmq.stream.impl.MonitoringTestUtils.EnvironmentInfo)1 DisabledIfTlsNotEnabled (com.rabbitmq.stream.impl.TestUtils.DisabledIfTlsNotEnabled)1