@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); }
@Test public void rejectReferenceCounted() { AbstractReferenceCounted item = new AbstractReferenceCounted() { @Override protected void deallocate() {} @Override public ReferenceCounted touch(Object hint) { return this; } }; StreamMessageAndWriter<Object> stream = newStreamWriter(ImmutableList.of(item)); assertThatThrownBy(() -> stream.write(item)).isInstanceOf(IllegalArgumentException.class); }