本文整理汇总了Java中io.netty.buffer.UnpooledHeapByteBuf类的典型用法代码示例。如果您正苦于以下问题:Java UnpooledHeapByteBuf类的具体用法?Java UnpooledHeapByteBuf怎么用?Java UnpooledHeapByteBuf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnpooledHeapByteBuf类属于io.netty.buffer包,在下文中一共展示了UnpooledHeapByteBuf类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: releaseOnConsumption_ByteBuf
import io.netty.buffer.UnpooledHeapByteBuf; //导入依赖的package包/类
@Test
public void releaseOnConsumption_ByteBuf() throws Exception {
final ByteBuf buf = newPooledBuffer();
StreamMessage<ByteBuf> stream = newStream(ImmutableList.of(buf));
if (stream instanceof StreamWriter) {
assertThat(((StreamWriter<ByteBuf>) stream).write(buf)).isTrue();
((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());
}
示例2: releaseOnConsumption_HttpData
import io.netty.buffer.UnpooledHeapByteBuf; //导入依赖的package包/类
@Test
public void releaseOnConsumption_HttpData() throws Exception {
final ByteBufHttpData data = new ByteBufHttpData(newPooledBuffer(), false);
StreamMessage<ByteBufHolder> stream = newStream(ImmutableList.of(data));
if (stream instanceof StreamWriter) {
assertThat(((StreamWriter<ByteBufHolder>) stream).write(data)).isTrue();
((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(ByteBufHttpData.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());
}