Search in sources :

Example 11 with ClientParameters

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

the class TlsTest method verifiedConnectionWithCorrectServerCertificate.

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

Example 12 with ClientParameters

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

the class TlsTest method verifiedConnectionWithCorrectClientPrivateKey.

@Test
void verifiedConnectionWithCorrectClientPrivateKey() throws Exception {
    SslContext context = SslContextBuilder.forClient().trustManager(caCertificate()).keyManager(clientKey(), clientCertificate()).build();
    cf.get(new ClientParameters().sslContext(context));
}
Also used : ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.jupiter.api.Test)

Example 13 with ClientParameters

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

the class TlsTest method unverifiedConnectionWithSni.

@Test
void unverifiedConnectionWithSni() {
    ChannelCustomizer channelCustomizer = ch -> {
        SslHandler sslHandler = ch.pipeline().get(SslHandler.class);
        if (sslHandler != null) {
            SSLParameters sslParameters = sslHandler.engine().getSSLParameters();
            sslParameters.setServerNames(Collections.singletonList(new SNIHostName("localhost")));
            sslHandler.engine().setSSLParameters(sslParameters);
        }
    };
    cf.get(new ClientParameters().sslContext(alwaysTrustSslContext()).channelCustomizer(channelCustomizer));
}
Also used : X509Certificate(java.security.cert.X509Certificate) IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) SNIHostName(javax.net.ssl.SNIHostName) CertificateFactory(java.security.cert.CertificateFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SSLParameters(javax.net.ssl.SSLParameters) TestUtils.latchAssert(com.rabbitmq.stream.impl.TestUtils.latchAssert) Address(com.rabbitmq.stream.Address) TestUtils.b(com.rabbitmq.stream.impl.TestUtils.b) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) ConfirmationHandler(com.rabbitmq.stream.ConfirmationHandler) InetAddress(java.net.InetAddress) TRUST_EVERYTHING_TRUST_MANAGER(com.rabbitmq.stream.impl.Utils.TRUST_EVERYTHING_TRUST_MANAGER) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StreamException(com.rabbitmq.stream.StreamException) Charset(java.nio.charset.Charset) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelCustomizer(com.rabbitmq.stream.ChannelCustomizer) Host(com.rabbitmq.stream.Host) SslContext(io.netty.handler.ssl.SslContext) PKCS8EncodedKeySpec(java.security.spec.PKCS8EncodedKeySpec) Files(java.nio.file.Files) Environment(com.rabbitmq.stream.Environment) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Producer(com.rabbitmq.stream.Producer) UnknownHostException(java.net.UnknownHostException) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) KeyFactory(java.security.KeyFactory) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Base64(java.util.Base64) SSLException(javax.net.ssl.SSLException) AfterEach(org.junit.jupiter.api.AfterEach) DisabledIfTlsNotEnabled(com.rabbitmq.stream.impl.TestUtils.DisabledIfTlsNotEnabled) SslHandler(io.netty.handler.ssl.SslHandler) PrivateKey(java.security.PrivateKey) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) OffsetSpecification(com.rabbitmq.stream.OffsetSpecification) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) SSLParameters(javax.net.ssl.SSLParameters) SNIHostName(javax.net.ssl.SNIHostName) ChannelCustomizer(com.rabbitmq.stream.ChannelCustomizer) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.jupiter.api.Test)

Example 14 with ClientParameters

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

the class SubEntryBatchingTest method subEntriesCompressedWithDifferentCompressionsShouldBeReadCorrectly.

@Test
void subEntriesCompressedWithDifferentCompressionsShouldBeReadCorrectly() {
    List<CompressionCodecFactory> compressionCodecFactories = compressionCodecFactories().collect(Collectors.toList());
    int batchCount = compressionCodecFactories.size() * Compression.values().length;
    int messagesInBatch = 30;
    int messageCount = batchCount * messagesInBatch;
    AtomicInteger messageIndex = new AtomicInteger(0);
    CountDownLatch publishLatch = new CountDownLatch(batchCount);
    Set<String> publishedBodies = ConcurrentHashMap.newKeySet(messageCount);
    compressionCodecFactories.forEach(compressionCodecFactory -> {
        Client publisher = cf.get(new ClientParameters().compressionCodecFactory(compressionCodecFactory).publishConfirmListener((publisherId, publishingId) -> publishLatch.countDown()));
        Response response = publisher.declarePublisher(b(0), null, stream);
        assertThat(response.isOk()).isTrue();
        for (Compression compression : Compression.values()) {
            MessageBatch messageBatch = new MessageBatch(compression);
            IntStream.range(0, messagesInBatch).forEach(i -> {
                String body = "compression " + compression.name() + " message " + messageIndex.getAndIncrement();
                messageBatch.add(publisher.messageBuilder().addData(body.getBytes(UTF8)).build());
                publishedBodies.add(body);
            });
            publisher.publishBatches(b(0), Collections.singletonList(messageBatch));
        }
    });
    assertThat(latchAssert(publishLatch)).completes();
    compressionCodecFactories.forEach(compressionCodecFactory -> {
        CountDownLatch consumeLatch = new CountDownLatch(messageCount);
        Set<String> consumedBodies = ConcurrentHashMap.newKeySet(messageCount);
        Client consumer = cf.get(new ClientParameters().compressionCodecFactory(compressionCodecFactory).chunkListener((client, subscriptionId, offset, messageCount1, dataSize) -> client.credit(subscriptionId, 1)).messageListener((subscriptionId, offset, chunkTimestamp, message) -> {
            consumedBodies.add(new String(message.getBodyAsBinary(), UTF8));
            consumeLatch.countDown();
        }));
        Response response = consumer.subscribe(b(1), stream, OffsetSpecification.first(), 2);
        assertThat(response.isOk()).isTrue();
        assertThat(latchAssert(consumeLatch)).completes();
        assertThat(consumedBodies).hasSize(messageCount).hasSameSizeAs(publishedBodies);
        publishedBodies.forEach(publishBody -> assertThat(consumedBodies.contains(publishBody)).isTrue());
    });
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestUtils.latchAssert(com.rabbitmq.stream.impl.TestUtils.latchAssert) CommonsCompressCompressionCodecFactory(com.rabbitmq.stream.compression.CommonsCompressCompressionCodecFactory) HashMap(java.util.HashMap) Response(com.rabbitmq.stream.impl.Client.Response) TestUtils.b(com.rabbitmq.stream.impl.TestUtils.b) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) Charset(java.nio.charset.Charset) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DefaultCompressionCodecFactory(com.rabbitmq.stream.compression.DefaultCompressionCodecFactory) MethodSource(org.junit.jupiter.params.provider.MethodSource) MetricsCollector(com.rabbitmq.stream.metrics.MetricsCollector) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Compression(com.rabbitmq.stream.compression.Compression) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) CompressionCodecFactory(com.rabbitmq.stream.compression.CompressionCodecFactory) Stream(java.util.stream.Stream) Collections(java.util.Collections) OffsetSpecification(com.rabbitmq.stream.OffsetSpecification) Compression(com.rabbitmq.stream.compression.Compression) CountDownLatch(java.util.concurrent.CountDownLatch) Response(com.rabbitmq.stream.impl.Client.Response) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) CommonsCompressCompressionCodecFactory(com.rabbitmq.stream.compression.CommonsCompressCompressionCodecFactory) DefaultCompressionCodecFactory(com.rabbitmq.stream.compression.DefaultCompressionCodecFactory) CompressionCodecFactory(com.rabbitmq.stream.compression.CompressionCodecFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with ClientParameters

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

the class SuperStreamConsumerTest method publishToPartitions.

private static void publishToPartitions(TestUtils.ClientFactory cf, List<String> partitions, int messageCount) {
    CountDownLatch publishLatch = new CountDownLatch(messageCount);
    Client client = cf.get(new ClientParameters().publishConfirmListener((publisherId, publishingId) -> publishLatch.countDown()));
    for (int i = 0; i < partitions.size(); i++) {
        assertThat(client.declarePublisher(b(i), null, partitions.get(i)).isOk()).isTrue();
    }
    for (int i = 0; i < messageCount; i++) {
        int partitionIndex = i % partitions.size();
        String partition = partitions.get(partitionIndex);
        client.publish(b(partitionIndex), Collections.singletonList(client.messageBuilder().addData(partition.getBytes(StandardCharsets.UTF_8)).build()));
    }
    latchAssert(publishLatch).completes();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestUtils.latchAssert(com.rabbitmq.stream.impl.TestUtils.latchAssert) Connection(com.rabbitmq.client.Connection) TestUtils.b(com.rabbitmq.stream.impl.TestUtils.b) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestUtils.deleteSuperStreamTopology(com.rabbitmq.stream.impl.TestUtils.deleteSuperStreamTopology) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TestUtils.declareSuperStreamTopology(com.rabbitmq.stream.impl.TestUtils.declareSuperStreamTopology) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventLoopGroup(io.netty.channel.EventLoopGroup) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Environment(com.rabbitmq.stream.Environment) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Consumer(com.rabbitmq.stream.Consumer) EnvironmentBuilder(com.rabbitmq.stream.EnvironmentBuilder) StandardCharsets(java.nio.charset.StandardCharsets) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Collections(java.util.Collections) OffsetSpecification(com.rabbitmq.stream.OffsetSpecification) TestUtils.localhost(com.rabbitmq.stream.impl.TestUtils.localhost) ClientParameters(com.rabbitmq.stream.impl.Client.ClientParameters) CountDownLatch(java.util.concurrent.CountDownLatch)

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