@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());
}