Search in sources :

Example 6 with ClientParameters

use of com.rabbitmq.stream.impl.Client.ClientParameters in project rabbitmq-stream-java-client by rabbitmq.

the class TlsTest method shouldConnectWhenSettingHostToLoopbackInterfaceAndDisablingHostnameVerification.

@Test
void shouldConnectWhenSettingHostToLoopbackInterfaceAndDisablingHostnameVerification() throws Exception {
    SslContext context = SslContextBuilder.forClient().trustManager(caCertificate()).build();
    cf.get(new ClientParameters().sslContext(context).host("127.0.0.1").tlsHostnameVerification(false));
}
Also used : ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 7 with ClientParameters

use of com.rabbitmq.stream.impl.Client.ClientParameters in project rabbitmq-stream-java-client by rabbitmq.

the class TlsTest method verifiedConnectionWithWrongServerCertificate.

@Test
void verifiedConnectionWithWrongServerCertificate() throws Exception {
    SslContext context = SslContextBuilder.forClient().trustManager(clientCertificate()).build();
    assertThatThrownBy(() -> cf.get(new ClientParameters().sslContext(context))).isInstanceOf(StreamException.class).hasCauseInstanceOf(SSLHandshakeException.class);
}
Also used : ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) SslContext(io.netty.handler.ssl.SslContext) StreamException(com.rabbitmq.stream.StreamException) Test(org.junit.jupiter.api.Test)

Example 8 with ClientParameters

use of com.rabbitmq.stream.impl.Client.ClientParameters in project rabbitmq-stream-java-client by rabbitmq.

the class TlsTest method hostnameVerificationShouldFailWhenSettingHostToLoopbackInterface.

@Test
void hostnameVerificationShouldFailWhenSettingHostToLoopbackInterface() throws Exception {
    SslContext context = SslContextBuilder.forClient().trustManager(caCertificate()).build();
    assertThatThrownBy(() -> cf.get(new ClientParameters().sslContext(context).host("127.0.0.1"))).isInstanceOf(StreamException.class).hasCauseInstanceOf(SSLHandshakeException.class);
}
Also used : ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) SslContext(io.netty.handler.ssl.SslContext) StreamException(com.rabbitmq.stream.StreamException) Test(org.junit.jupiter.api.Test)

Example 9 with ClientParameters

use of com.rabbitmq.stream.impl.Client.ClientParameters in project rabbitmq-stream-java-client by rabbitmq.

the class UtilsTest method exactNodeRetryClientFactoryShouldRetryUntilConditionOk.

@Test
@SuppressWarnings("unchecked")
void exactNodeRetryClientFactoryShouldRetryUntilConditionOk() {
    Client client = mock(Client.class);
    ClientFactory cf = mock(ClientFactory.class);
    when(cf.client(any())).thenReturn(client);
    Predicate<Client> condition = mock(Predicate.class);
    when(condition.test(any())).thenReturn(false).thenReturn(false).thenReturn(true);
    Client result = new ExactNodeRetryClientFactory(cf, condition, Duration.ofMillis(1)).client(ClientFactoryContext.fromParameters(new ClientParameters()));
    assertThat(result).isEqualTo(client);
    verify(cf, times(3)).client(any());
    verify(client, times(2)).close();
}
Also used : ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) ClientFactory(com.rabbitmq.stream.impl.Utils.ClientFactory) ExactNodeRetryClientFactory(com.rabbitmq.stream.impl.Utils.ExactNodeRetryClientFactory) ExactNodeRetryClientFactory(com.rabbitmq.stream.impl.Utils.ExactNodeRetryClientFactory) Test(org.junit.jupiter.api.Test)

Example 10 with ClientParameters

use of com.rabbitmq.stream.impl.Client.ClientParameters in project rabbitmq-stream-java-client by rabbitmq.

the class ClientTest method closingPublisherWhilePublishingShouldNotCloseConnection.

@ParameterizedTest
@ValueSource(strings = { "", "some-publisher-reference" })
void closingPublisherWhilePublishingShouldNotCloseConnection(String publisherReference) {
    AtomicReference<CountDownLatch> confirmLatch = new AtomicReference<>(new CountDownLatch(500_000));
    CountDownLatch closedLatch = new CountDownLatch(1);
    Semaphore semaphore = new Semaphore(10000);
    Client client = cf.get(new ClientParameters().shutdownListener(shutdownContext -> closedLatch.countDown()).publishConfirmListener((publisherId, publishingId) -> {
        semaphore.release();
        confirmLatch.get().countDown();
    }));
    Response response = client.declarePublisher(TestUtils.b(0), publisherReference, stream);
    assertThat(response.isOk()).isTrue();
    List<Thread> threads = IntStream.range(0, 10).mapToObj(i -> {
        Thread thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                List<Message> messages = IntStream.range(0, 100).mapToObj(j -> client.messageBuilder().addData("hello".getBytes(StandardCharsets.UTF_8)).build()).collect(Collectors.toList());
                semaphore.acquireUninterruptibly(100);
                client.publish(b(0), messages);
            }
        });
        thread.start();
        return thread;
    }).collect(Collectors.toList());
    try {
        assertThat(latchAssert(confirmLatch)).completes();
        response = client.deletePublisher(b(0));
        assertThat(response.isOk()).isTrue();
        assertThat(latchAssert(closedLatch)).doesNotComplete(1);
    } finally {
        threads.forEach(Thread::interrupt);
    }
}
Also used : UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) IntStream(java.util.stream.IntStream) java.util(java.util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestUtils.latchAssert(com.rabbitmq.stream.impl.TestUtils.latchAssert) Connection(com.rabbitmq.client.Connection) QpidProtonCodec(com.rabbitmq.stream.codec.QpidProtonCodec) SimpleCodec(com.rabbitmq.stream.codec.SimpleCodec) Response(com.rabbitmq.stream.impl.Client.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TestUtils.b(com.rabbitmq.stream.impl.TestUtils.b) TestUtils.streamName(com.rabbitmq.stream.impl.TestUtils.streamName) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) ByteBuffer(java.nio.ByteBuffer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DataOutputStream(java.io.DataOutputStream) Charset(java.nio.charset.Charset) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) SwiftMqCodec(com.rabbitmq.stream.codec.SwiftMqCodec) ValueSource(org.junit.jupiter.params.provider.ValueSource) Properties(com.rabbitmq.stream.Properties) TestUtils.waitAtMost(com.rabbitmq.stream.impl.TestUtils.waitAtMost) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) com.rabbitmq.stream(com.rabbitmq.stream) Semaphore(java.util.concurrent.Semaphore) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) LongConsumer(java.util.function.LongConsumer) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) StreamParametersBuilder(com.rabbitmq.stream.impl.Client.StreamParametersBuilder) Channel(com.rabbitmq.client.Channel) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Response(com.rabbitmq.stream.impl.Client.Response) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) CountDownLatch(java.util.concurrent.CountDownLatch) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ClientParameters (com.rabbitmq.stream.impl.Client.ClientParameters)19 Test (org.junit.jupiter.api.Test)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 TestUtils.b (com.rabbitmq.stream.impl.TestUtils.b)11 Collections (java.util.Collections)11 IntStream (java.util.stream.IntStream)11 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)11 OffsetSpecification (com.rabbitmq.stream.OffsetSpecification)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 TestInfo (org.junit.jupiter.api.TestInfo)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Response (com.rabbitmq.stream.impl.Client.Response)8 TestUtils.latchAssert (com.rabbitmq.stream.impl.TestUtils.latchAssert)8 StandardCharsets (java.nio.charset.StandardCharsets)7 Set (java.util.Set)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Stream (java.util.stream.Stream)7