use of com.rabbitmq.client.impl.nio.NioParams in project rabbitmq-java-client by rabbitmq.
the class NioTlsUnverifiedConnection method socketChannelConfigurator.
@Test
public void socketChannelConfigurator() throws Exception {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.useNio();
connectionFactory.useSslProtocol();
NioParams nioParams = new NioParams();
final AtomicBoolean sslEngineHasBeenCalled = new AtomicBoolean(false);
nioParams.setSslEngineConfigurator(sslEngine -> sslEngineHasBeenCalled.set(true));
connectionFactory.setNioParams(nioParams);
Connection connection = null;
try {
connection = connectionFactory.newConnection();
assertTrue("The SSL engine configurator should have called", sslEngineHasBeenCalled.get());
} finally {
if (connection != null) {
connection.close();
}
}
}
use of com.rabbitmq.client.impl.nio.NioParams in project rabbitmq-java-client by rabbitmq.
the class NioTlsUnverifiedConnection method connectionGetConsumeProtocols.
@Test
public void connectionGetConsumeProtocols() throws Exception {
Collection<String> availableProtocols = TlsTestUtils.availableTlsProtocols();
Collection<String> protocols = Stream.of("TLSv1.2", "TLSv1.3").filter(p -> availableProtocols.contains(p)).collect(Collectors.toList());
for (String protocol : protocols) {
SSLContext sslContext = SSLContext.getInstance(protocol);
sslContext.init(null, new TrustManager[] { new TrustEverythingTrustManager() }, null);
ConnectionFactory cf = TestUtils.connectionFactory();
cf.useSslProtocol(sslContext);
cf.useNio();
AtomicReference<SSLEngine> engine = new AtomicReference<>();
cf.setNioParams(new NioParams().setSslEngineConfigurator(sslEngine -> engine.set(sslEngine)));
try (Connection c = cf.newConnection()) {
CountDownLatch latch = new CountDownLatch(1);
basicGetBasicConsume(c, QUEUE, latch, 100);
boolean messagesReceived = latch.await(5, TimeUnit.SECONDS);
assertTrue("Message has not been received", messagesReceived);
assertThat(engine.get()).isNotNull();
assertThat(engine.get().getEnabledProtocols()).contains(protocol);
}
}
}
use of com.rabbitmq.client.impl.nio.NioParams in project rabbitmq-java-client by rabbitmq.
the class JavaNioTest method byteBufferFactory.
@Test
public void byteBufferFactory() throws Exception {
ConnectionFactory cf = new ConnectionFactory();
cf.useNio();
int baseCapacity = 32768;
NioParams nioParams = new NioParams();
nioParams.setReadByteBufferSize(baseCapacity / 2);
nioParams.setWriteByteBufferSize(baseCapacity / 4);
List<ByteBuffer> byteBuffers = new CopyOnWriteArrayList<>();
cf.setNioParams(nioParams.setByteBufferFactory(new DefaultByteBufferFactory(capacity -> {
ByteBuffer bb = ByteBuffer.allocate(capacity);
byteBuffers.add(bb);
return bb;
})));
try (Connection c = cf.newConnection()) {
sendAndVerifyMessage(c, 100);
}
assertThat(byteBuffers).hasSize(2);
Condition<Integer> condition = new Condition<>(c -> c == nioParams.getReadByteBufferSize() || c == nioParams.getWriteByteBufferSize(), "capacity set by factory");
assertThat(byteBuffers.get(0).capacity()).is(condition);
assertThat(byteBuffers.get(1).capacity()).is(condition);
}
Aggregations