io.netty.util.AbstractReferenceCounted Java Examples

The following examples show how to use io.netty.util.AbstractReferenceCounted. 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: SslHandlerTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonByteBufWriteIsReleased() throws Exception {
    SSLEngine engine = SSLContext.getDefault().createSSLEngine();
    engine.setUseClientMode(false);

    EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));

    AbstractReferenceCounted referenceCounted = new AbstractReferenceCounted() {
        @Override
        public ReferenceCounted touch(Object hint) {
            return this;
        }

        @Override
        protected void deallocate() {
        }
    };
    try {
        ch.write(referenceCounted).get();
        fail();
    } catch (ExecutionException e) {
        assertThat(e.getCause(), is(instanceOf(UnsupportedMessageTypeException.class)));
    }
    assertEquals(0, referenceCounted.refCnt());
    assertTrue(ch.finishAndReleaseAll());
}
 
Example #2
Source File: DefaultChannelPipelineTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeCalled() throws Exception {
    final CountDownLatch free = new CountDownLatch(1);

    final ReferenceCounted holder = new AbstractReferenceCounted() {
        @Override
        protected void deallocate() {
            free.countDown();
        }

        @Override
        public ReferenceCounted touch(Object hint) {
            return this;
        }
    };

    StringInboundHandler handler = new StringInboundHandler();
    setUp(handler);

    peer.writeAndFlush(holder).sync();

    assertTrue(free.await(10, TimeUnit.SECONDS));
    assertTrue(handler.called);
}
 
Example #3
Source File: DefaultChannelPipelineTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeCalled() throws Exception {
    final CountDownLatch free = new CountDownLatch(1);

    final ReferenceCounted holder = new AbstractReferenceCounted() {
        @Override
        protected void deallocate() {
            free.countDown();
        }
    };

    StringInboundHandler handler = new StringInboundHandler();
    setUp(handler);

    peer.writeAndFlush(holder).sync();

    assertTrue(free.await(10, TimeUnit.SECONDS));
    assertTrue(handler.called);
}
 
Example #4
Source File: Http2FrameCodecTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void unknownFrameTypeShouldThrowAndBeReleased() throws Exception {
    class UnknownHttp2Frame extends AbstractReferenceCounted implements Http2Frame {
        @Override
        public String name() {
            return "UNKNOWN";
        }

        @Override
        protected void deallocate() {
        }

        @Override
        public ReferenceCounted touch(Object hint) {
            return this;
        }
    }

    UnknownHttp2Frame frame = new UnknownHttp2Frame();
    assertEquals(1, frame.refCnt());

    ChannelFuture f = channel.write(frame);
    f.await();
    assertTrue(f.isDone());
    assertFalse(f.isSuccess());
    assertThat(f.cause(), instanceOf(UnsupportedMessageTypeException.class));
    assertEquals(0, frame.refCnt());
}
 
Example #5
Source File: DefaultStreamMessageTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void rejectReferenceCounted() {
    final AbstractReferenceCounted item = new AbstractReferenceCounted() {
        @Override
        protected void deallocate() {}

        @Override
        public ReferenceCounted touch(Object hint) {
            return this;
        }
    };
    final StreamMessageAndWriter<Object> stream = new DefaultStreamMessage<>();
    assertThatThrownBy(() -> stream.write(item)).isInstanceOf(IllegalArgumentException.class);
}