@Test
    void closedDuplicator_elementsAreNotReleasedUntilSubscribedByAllSubscribers() {
        final StreamWriter<HttpData> publisher = StreamMessage.streaming();
        final ArrayList<ByteBuf> byteBufs = new ArrayList<>(60);
        for (int i = 0; i < 60; i++) { // More than 50 that is the REQUEST_REMOVAL_THRESHOLD.
            final ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(4).writeInt(i);
            byteBufs.add(byteBuf);
            publisher.write(HttpData.wrap(byteBuf));
            assertThat(byteBuf.refCnt()).isOne();
        }
        publisher.close();

        final StreamMessageDuplicator<HttpData> duplicator =
                publisher.toDuplicator(ImmediateEventExecutor.INSTANCE);

        final StreamMessage<HttpData> first = duplicator.duplicate();
        final StreamMessage<HttpData> second = duplicator.duplicate();

        duplicator.close();

        final Queue<HttpData> firstQueue = new LinkedList<>();
        first.subscribe(new QueueingSubscriber(firstQueue));

        for (int i = 0; i < 60; i++) {
            assertThat(firstQueue.poll().byteBuf().readInt()).isEqualTo(i);
        }

        for (int i = 0; i < 60; i++) {
            assertThat(byteBufs.get(i).refCnt()).isOne();
        }

        final Queue<HttpData> secondQueue = new LinkedList<>();
        second.subscribe(new QueueingSubscriber(secondQueue));

        for (int i = 0; i < 60; i++) {
            assertThat(secondQueue.poll().byteBuf().readInt()).isEqualTo(i);
        }

        for (int i = 0; i < 60; i++) {
            assertThat(byteBufs.get(i).refCnt()).isZero();
        }
    }
This test checks that the duplicator does not release the elements that it holds until all subscribers are
received all element via {@link Subscriber#onNext(Object)}.
Previously, the duplicator has a bug that releases the elements when the duplicator is closed even though
there's a subscriber that does not subscribe to the child stream message yet.
See <a href="https://github.com/line/armeria/pull/3337">
Fix not to release elements before subscribed in duplicator</a>
core/src/test/java/com/linecorp/armeria/common/stream/StreamMessageDuplicatorCloseTest.java