@Test public void StreamingChannel_doStreamChunk_works_as_expected_when_crazy_exception_is_thrown() { // given Throwable crazyEx = new RuntimeException("kaboom"); doThrow(crazyEx).when(channelMock).writeAndFlush(any(Object.class)); // when ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock); // then verify(channelMock).writeAndFlush(any(Object.class)); verify(contentChunkMock, never()).release(); verifyFailedChannelFuture( result, "StreamingChannel.doStreamChunk() threw an exception", crazyEx ); }
@Test public void StreamingChannel_doStreamChunk_works_as_expected_when_downstream_call_is_not_active() { // given streamingChannelSpy.callActiveHolder.heldObject = false; // when ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock); // then verify(channelMock, never()).writeAndFlush(any(Object.class)); verify(contentChunkMock).release(); verifyFailedChannelFuture( result, "Unable to stream chunk - downstream call is no longer active.", null ); }
@Test public void StreamingChannel_streamChunk_fails_promise_with_unexpected_exception() { // given Throwable crazyEx = new RuntimeException("kaboom"); doThrow(crazyEx).when(eventLoopMock).execute(any(Runnable.class)); // when ChannelFuture result = streamingChannelSpy.streamChunk(contentChunkMock); // then verifyFailedChannelFuture(result, "StreamingChannel.streamChunk() threw an exception", crazyEx); }
@Test public void StreamingChannel_doStreamChunk_works_as_expected_when_closeChannelDueToUnrecoverableError_was_called_previously() { // given streamingChannelSpy.channelClosedDueToUnrecoverableError = true; // when ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock); // then verify(channelMock, never()).writeAndFlush(any(Object.class)); verify(contentChunkMock).release(); verifyFailedChannelFuture( result, "Unable to stream chunks downstream - the channel was closed previously due to an unrecoverable error", null ); }