Search in sources :

Example 1 with AbstractReferenceCounted

use of io.netty.util.AbstractReferenceCounted in project netty by netty.

the class Http2FrameCodecTest method unknownFrameTypeShouldThrowAndBeReleased.

@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());
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) AbstractReferenceCounted(io.netty.util.AbstractReferenceCounted) UnsupportedMessageTypeException(io.netty.handler.codec.UnsupportedMessageTypeException) Test(org.junit.Test)

Example 2 with AbstractReferenceCounted

use of io.netty.util.AbstractReferenceCounted in project netty by netty.

the class DefaultChannelPipelineTest method testFreeCalled.

@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);
}
Also used : AbstractReferenceCounted(io.netty.util.AbstractReferenceCounted) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractReferenceCounted(io.netty.util.AbstractReferenceCounted) ReferenceCounted(io.netty.util.ReferenceCounted) Test(org.junit.Test)

Aggregations

AbstractReferenceCounted (io.netty.util.AbstractReferenceCounted)2 Test (org.junit.Test)2 ChannelFuture (io.netty.channel.ChannelFuture)1 UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)1 ReferenceCounted (io.netty.util.ReferenceCounted)1 CountDownLatch (java.util.concurrent.CountDownLatch)1