### Question:
DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder { @Override public ChannelFuture writePushPromise(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding, ChannelPromise promise) { try { if (connection.goAwayReceived()) { throw connectionError(PROTOCOL_ERROR, "Sending PUSH_PROMISE after GO_AWAY received."); } Http2Stream stream = requireStream(streamId); connection.local().reservePushStream(promisedStreamId, stream); ChannelFuture future = frameWriter.writePushPromise(ctx, streamId, promisedStreamId, headers, padding, promise); Throwable failureCause = future.cause(); if (failureCause == null) { stream.pushPromiseSent(); if (!future.isSuccess()) { notifyLifecycleManagerOnError(future, ctx); } } else { lifecycleManager.onError(ctx, true, failureCause); } return future; } catch (Throwable t) { lifecycleManager.onError(ctx, true, t); promise.tryFailure(t); return promise; } } DefaultHttp2ConnectionEncoder(Http2Connection connection, Http2FrameWriter frameWriter); @Override void lifecycleManager(Http2LifecycleManager lifecycleManager); @Override Http2FrameWriter frameWriter(); @Override Http2Connection connection(); @Override final Http2RemoteFlowController flowController(); @Override void remoteSettings(Http2Settings settings); @Override ChannelFuture writeData(final ChannelHandlerContext ctx, final int streamId, ByteBuf data, int padding,
            final boolean endOfStream, ChannelPromise promise); @Override ChannelFuture writeHeaders(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding,
            boolean endStream, ChannelPromise promise); @Override ChannelFuture writeHeaders(final ChannelHandlerContext ctx, final int streamId,
            final Http2Headers headers, final int streamDependency, final short weight,
            final boolean exclusive, final int padding, final boolean endOfStream, ChannelPromise promise); @Override ChannelFuture writePriority(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight,
            boolean exclusive, ChannelPromise promise); @Override ChannelFuture writeRstStream(ChannelHandlerContext ctx, int streamId, long errorCode,
            ChannelPromise promise); @Override ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings,
            ChannelPromise promise); @Override ChannelFuture writeSettingsAck(ChannelHandlerContext ctx, ChannelPromise promise); @Override ChannelFuture writePing(ChannelHandlerContext ctx, boolean ack, long data, ChannelPromise promise); @Override ChannelFuture writePushPromise(ChannelHandlerContext ctx, int streamId, int promisedStreamId,
            Http2Headers headers, int padding, ChannelPromise promise); @Override ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData,
            ChannelPromise promise); @Override ChannelFuture writeWindowUpdate(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement,
            ChannelPromise promise); @Override ChannelFuture writeFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags,
            ByteBuf payload, ChannelPromise promise); @Override void close(); @Override Http2Settings pollSentSettings(); @Override Configuration configuration();  }### Answer:
@Test public void pushPromiseWriteAfterGoAwayReceivedShouldFail() throws Exception { createStream(STREAM_ID, false); goAwayReceived(0); ChannelFuture future = encoder.writePushPromise(ctx, STREAM_ID, PUSH_STREAM_ID, EmptyHttp2Headers.INSTANCE, 0, newPromise()); assertTrue(future.isDone()); assertFalse(future.isSuccess()); }
@Test public void pushPromiseWriteShouldReserveStream() throws Exception { createStream(STREAM_ID, false); ChannelPromise promise = newPromise(); encoder.writePushPromise(ctx, STREAM_ID, PUSH_STREAM_ID, EmptyHttp2Headers.INSTANCE, 0, promise); assertEquals(RESERVED_LOCAL, stream(PUSH_STREAM_ID).state()); verify(writer).writePushPromise(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(promise)); }