io.netty.buffer.UnpooledHeapByteBuf Java Examples
The following examples show how to use
io.netty.buffer.UnpooledHeapByteBuf.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpDecodedResponseTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void unpooledPayload_unpooledDrain() { final HttpData payload = HttpData.wrap(PAYLOAD); final HttpResponse delegate = HttpResponse.of(RESPONSE_HEADERS, payload); final HttpResponse decoded = new HttpDecodedResponse(delegate, DECODERS, ByteBufAllocator.DEFAULT); final ByteBuf buf = responseBuf(decoded, false); assertThat(buf).isInstanceOf(UnpooledHeapByteBuf.class); }
Example #2
Source File: HttpDecodedResponseTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void pooledPayload_unpooledDrain() { final PooledHttpData payload = PooledHttpData.wrap( ByteBufAllocator.DEFAULT.buffer().writeBytes(PAYLOAD)).withEndOfStream(); final HttpResponse delegate = HttpResponse.of(RESPONSE_HEADERS, payload); final HttpResponse decoded = new HttpDecodedResponse(delegate, DECODERS, ByteBufAllocator.DEFAULT); final ByteBuf buf = responseBuf(decoded, false); assertThat(buf).isInstanceOf(UnpooledHeapByteBuf.class); assertThat(payload.refCnt()).isZero(); }
Example #3
Source File: HttpDecodedResponseTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void unpooledPayload_pooledDrain() { final HttpData payload = HttpData.wrap(PAYLOAD); final HttpResponse delegate = HttpResponse.of(RESPONSE_HEADERS, payload); final HttpResponse decoded = new HttpDecodedResponse(delegate, DECODERS, ByteBufAllocator.DEFAULT); final ByteBuf buf = responseBuf(decoded, true); assertThat(buf).isNotInstanceOf(UnpooledHeapByteBuf.class); }
Example #4
Source File: HttpDecodedResponseTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void pooledPayload_pooledDrain() { final PooledHttpData payload = PooledHttpData.wrap( ByteBufAllocator.DEFAULT.buffer().writeBytes(PAYLOAD)).withEndOfStream(); final HttpResponse delegate = HttpResponse.of(RESPONSE_HEADERS, payload); final HttpResponse decoded = new HttpDecodedResponse(delegate, DECODERS, ByteBufAllocator.DEFAULT); final ByteBuf buf = responseBuf(decoded, true); assertThat(buf).isNotInstanceOf(UnpooledHeapByteBuf.class); assertThat(payload.refCnt()).isZero(); }
Example #5
Source File: StreamMessageTest.java From armeria with Apache License 2.0 | 5 votes |
@ParameterizedTest @ArgumentsSource(ByteBufStreamProvider.class) public void releaseOnConsumption_ByteBuf(ByteBuf buf, StreamMessage<ByteBuf> stream) { if (stream instanceof StreamWriter) { ((StreamWriter<ByteBuf>) stream).write(buf); ((StreamWriter<?>) stream).close(); } assertThat(buf.refCnt()).isEqualTo(1); stream.subscribe(new Subscriber<ByteBuf>() { @Override public void onSubscribe(Subscription subscription) { subscription.request(1); } @Override public void onNext(ByteBuf o) { assertThat(o).isNotSameAs(buf); assertThat(o).isInstanceOf(UnpooledHeapByteBuf.class); assertThat(o.refCnt()).isEqualTo(1); assertThat(buf.refCnt()).isZero(); } @Override public void onError(Throwable throwable) { Exceptions.throwUnsafely(throwable); } @Override public void onComplete() { completed = true; } }); await().untilAsserted(() -> assertThat(completed).isTrue()); }
Example #6
Source File: StreamMessageTest.java From armeria with Apache License 2.0 | 5 votes |
@ParameterizedTest @ArgumentsSource(ByteBufHolderStreamProvider.class) void releaseOnConsumption_HttpData(ByteBufHolder data, StreamMessage<ByteBufHolder> stream) { if (stream instanceof StreamWriter) { ((StreamWriter<ByteBufHolder>) stream).write(data); ((StreamWriter<?>) stream).close(); } assertThat(data.refCnt()).isEqualTo(1); stream.subscribe(new Subscriber<ByteBufHolder>() { @Override public void onSubscribe(Subscription subscription) { subscription.request(1); } @Override public void onNext(ByteBufHolder o) { assertThat(o).isNotSameAs(data); assertThat(o).isInstanceOf(PooledHttpData.class); assertThat(o.content()).isInstanceOf(UnpooledHeapByteBuf.class); assertThat(o.refCnt()).isEqualTo(1); assertThat(data.refCnt()).isZero(); } @Override public void onError(Throwable throwable) { Exceptions.throwUnsafely(throwable); } @Override public void onComplete() { completed = true; } }); await().untilAsserted(() -> assertThat(completed).isTrue()); }