@Test
    void publishedSignalsCleanedUpWhenDuplicatorIsClosed() {
        final StreamWriter<HttpData> publisher = StreamMessage.streaming();
        final StreamMessageDuplicator<HttpData> duplicator =
                publisher.toDuplicator(ImmediateEventExecutor.INSTANCE);

        final StreamMessage<HttpData> duplicated1 = duplicator.duplicate();
        final StreamMessage<HttpData> duplicated2 = duplicator.duplicate();
        duplicator.close();
        // duplicate() is not allowed anymore.
        assertThatThrownBy(duplicator::duplicate).isInstanceOf(IllegalStateException.class);

        duplicated1.subscribe(new HttpDataSubscriber(), ImmediateEventExecutor.INSTANCE);
        duplicated2.subscribe(new HttpDataSubscriber(), ImmediateEventExecutor.INSTANCE);

        for (int i = 0; i < 30; i++) {
            final HttpData httpData = httpData(i);
            publisher.write(httpData);
            assertThat(httpData.byteBuf().refCnt()).isOne();
        }

        assertRefCnt(0, 25, 0); // first 25 signals are removed from the queue.
        assertRefCnt(25, 30, 1); // rest of them are still in the queue.
        duplicator.abort();

        assertRefCnt(0, 30, 0);  // rest of them are cleared after calling duplicator.abort()
    }
A test for the {@link SignalQueue} in {@link DefaultStreamMessageDuplicator}.
Queue expansion behaves differently when odd/even number head wrap-around happens.
core/src/test/java/com/linecorp/armeria/common/stream/StreamMessageDuplicatorTest.java