use of io.netty.buffer.ByteBuf in project netty by netty.
the class ChunkedWriteHandlerTest method check.
private static void check(Object... inputs) {
EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler());
for (Object input : inputs) {
ch.writeOutbound(input);
}
assertTrue(ch.finish());
int i = 0;
int read = 0;
for (; ; ) {
ByteBuf buffer = ch.readOutbound();
if (buffer == null) {
break;
}
while (buffer.isReadable()) {
assertEquals(BYTES[i++], buffer.readByte());
read++;
if (i == BYTES.length) {
i = 0;
}
}
buffer.release();
}
assertEquals(BYTES.length * inputs.length, read);
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SSLEngineTest method writeAndVerifyReceived.
private static void writeAndVerifyReceived(ByteBuf message, Channel sendChannel, CountDownLatch receiverLatch, MessageReceiver receiver) throws Exception {
List<ByteBuf> dataCapture = null;
try {
sendChannel.writeAndFlush(message);
receiverLatch.await(5, TimeUnit.SECONDS);
message.resetReaderIndex();
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
verify(receiver).messageReceived(captor.capture());
dataCapture = captor.getAllValues();
assertEquals(message, dataCapture.get(0));
} finally {
if (dataCapture != null) {
for (ByteBuf data : dataCapture) {
data.release();
}
}
}
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SSLEngineTest method runTest.
protected void runTest(String expectedApplicationProtocol) throws Exception {
final ByteBuf clientMessage = Unpooled.copiedBuffer("I am a client".getBytes());
final ByteBuf serverMessage = Unpooled.copiedBuffer("I am a server".getBytes());
try {
writeAndVerifyReceived(clientMessage.retain(), clientChannel, serverLatch, serverReceiver);
writeAndVerifyReceived(serverMessage.retain(), serverConnectedChannel, clientLatch, clientReceiver);
if (expectedApplicationProtocol != null) {
verifyApplicationLevelProtocol(clientChannel, expectedApplicationProtocol);
verifyApplicationLevelProtocol(serverConnectedChannel, expectedApplicationProtocol);
}
} finally {
clientMessage.release();
serverMessage.release();
}
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class HpackUtilBenchmark method newTestEncoder.
static HpackEncoder newTestEncoder() {
HpackEncoder hpackEncoder = new HpackEncoder();
ByteBuf buf = Unpooled.buffer();
try {
hpackEncoder.setMaxHeaderTableSize(buf, MAX_HEADER_TABLE_SIZE);
hpackEncoder.setMaxHeaderListSize(MAX_HEADER_LIST_SIZE);
} catch (Http2Exception e) {
throw new Error("max size not allowed?", e);
} finally {
buf.release();
}
return hpackEncoder;
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class ByteBufAllocatorBenchmark method unpooledHeapAllocAndFree.
@Benchmark
public void unpooledHeapAllocAndFree() {
int idx = rand.nextInt(unpooledHeapBuffers.length);
ByteBuf oldBuf = unpooledHeapBuffers[idx];
if (oldBuf != null) {
oldBuf.release();
}
unpooledHeapBuffers[idx] = unpooledAllocator.heapBuffer(size);
}
Aggregations