use of com.rabbitmq.client.impl.nio.DefaultByteBufferFactory 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