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));
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations