@Override
    public ChannelFuture resetStream(final ChannelHandlerContext ctx, int streamId, long errorCode,
                                     ChannelPromise promise) {
        final Http2Stream stream = connection().stream(streamId);
        if (stream == null) {
            return resetUnknownStream(ctx, streamId, errorCode, promise.unvoid());
        }

       return resetStream(ctx, stream, errorCode, promise);
    }
@Test
    public void writeMultipleRstFramesForSameStream() throws Exception {
        handler = newHandler();
        when(stream.id()).thenReturn(STREAM_ID);

        final AtomicBoolean resetSent = new AtomicBoolean();
        when(stream.resetSent()).then(new Answer<Http2Stream>() {
            @Override
            public Http2Stream answer(InvocationOnMock invocationOnMock) {
                resetSent.set(true);
                return stream;
            }
        });
        when(stream.isResetSent()).then(new Answer<Boolean>() {
            @Override
            public Boolean answer(InvocationOnMock invocationOnMock) {
                return resetSent.get();
            }
        });
        when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class)))
                .then(new Answer<ChannelFuture>() {
                    @Override
                    public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
                        ChannelPromise promise = invocationOnMock.getArgument(3);
                        return promise.setSuccess();
                    }
                });

        ChannelPromise promise =
                new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
        final ChannelPromise promise2 =
                new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
        promise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) {
                handler.resetStream(ctx, STREAM_ID, STREAM_CLOSED.code(), promise2);
            }
        });

        handler.resetStream(ctx, STREAM_ID, CANCEL.code(), promise);
        verify(frameWriter).writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class));
        assertTrue(promise.isSuccess());
        assertTrue(promise2.isSuccess());
    }