public DownstreamChannelClosedUnexpectedlyException(Channel channel) { super("The channel used to talk to the downstream system was closed while the call was active - probably by " + "the downstream system, but also possibly by us if an unrecoverable error occurred and we " + "preemptively closed the channel. closed_channel_id=" + getChannelId(channel) ); this.channelId = getChannelId(channel); }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (logger.isDebugEnabled()) { runnableWithTracingAndMdc( () -> logger.debug( "Downstream channel closing. call_active={}, last_chunk_sent_downstream={}, channel_id={}", callActiveHolder.heldObject, lastChunkSentDownstreamHolder.heldObject, ctx.channel().toString() ), distributedSpanStackToUse, mdcContextToUse ).run(); } // We only care if the channel was closed while the call was active. if (callActiveHolder.heldObject) doErrorHandlingConsumer.accept(new DownstreamChannelClosedUnexpectedlyException(ch)); super.channelInactive(ctx); } };
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (logger.isDebugEnabled()) { runnableWithTracingAndMdc( () -> logger.debug( "Downstream channel closing. call_active={}, last_chunk_sent_downstream={}, channel_id={}", callActiveHolder.heldObject, lastChunkSentDownstreamHolder.heldObject, ctx.channel().toString() ), distributedSpanStackToUse, mdcContextToUse ).run(); } // We only care if the channel was closed while the call was active. if (callActiveHolder.heldObject) doErrorHandlingConsumer.accept(new DownstreamChannelClosedUnexpectedlyException(ch)); super.channelInactive(ctx); } };
@Test public void constructor_works_with_valid_channel() { // given Channel channelMock = mock(Channel.class); String channelToStringVal = UUID.randomUUID().toString(); doReturn(channelToStringVal).when(channelMock).toString(); // when DownstreamChannelClosedUnexpectedlyException ex = new DownstreamChannelClosedUnexpectedlyException(channelMock); // then assertThat(ex.channelId).isEqualTo(channelToStringVal); }
@Test public void constructor_works_with_null_channel() { // when DownstreamChannelClosedUnexpectedlyException ex = new DownstreamChannelClosedUnexpectedlyException(null); // then assertThat(ex.channelId).isEqualTo("null"); }
@Test public void should_handle_DownstreamChannelClosedUnexpectedlyException() { verifyExceptionHandled(new DownstreamChannelClosedUnexpectedlyException(null), singletonError(testProjectApiErrors.getTemporaryServiceProblemApiError())); }