@Test public void StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_even_if_crazy_exception_occurs() { // given streamingChannelSpy.channelClosedDueToUnrecoverableError = false; streamingChannelSpy.callActiveHolder.heldObject = true; Throwable crazyEx = new RuntimeException("kaboom"); doThrow(crazyEx).when(channelMock).eventLoop(); // when Throwable caughtEx = catchThrowable( () -> streamingChannelSpy.closeChannelDueToUnrecoverableError(new RuntimeException("some other error")) ); // then assertThat(caughtEx).isSameAs(crazyEx); assertThat(streamingChannelSpy.channelClosedDueToUnrecoverableError).isTrue(); }
@Test public void StreamingChannel_closeChannelDueToUnrecoverableError_calls_the_do_method_and_sets_field_to_true_when_not_closed_and_call_active() { // given Throwable unrecoverableError = new RuntimeException("kaboom"); streamingChannelSpy.channelClosedDueToUnrecoverableError = false; streamingChannelSpy.callActiveHolder.heldObject = true; // when streamingChannelSpy.closeChannelDueToUnrecoverableError(unrecoverableError); // then assertThat(streamingChannelSpy.channelClosedDueToUnrecoverableError).isTrue(); ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(eventLoopMock).execute(taskCaptor.capture()); Runnable task = taskCaptor.getValue(); assertThat(task).isNotNull(); // and given verify(streamingChannelSpy, never()).doCloseChannelDueToUnrecoverableError(any(Throwable.class)); // when task.run(); // then verify(streamingChannelSpy).doCloseChannelDueToUnrecoverableError(unrecoverableError); }
public void cancelDownstreamRequest(Throwable reason) { if (streamingCallback != null) streamingCallback.cancelStreamingToOriginalCaller(); // Do nothing else if a StreamingChannel was never started. if (streamingChannelCompletableFuture == null) return; streamingChannelCompletableFuture.whenComplete((sc, error) -> { if (sc != null) { // A StreamingChannel was created. Tell it to stop if it's still going. if (sc.isDownstreamCallActive()) sc.closeChannelDueToUnrecoverableError(reason); } }); }
sc.closeChannelDueToUnrecoverableError(future.cause()); scToNotify.closeChannelDueToUnrecoverableError(cause);
sc.closeChannelDueToUnrecoverableError(future.cause()); scToNotify.closeChannelDueToUnrecoverableError(cause);
@DataProvider(value = { "true | true", "false | false", "true | false" }, splitBy = "\\|") @Test public void StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_but_otherwise_does_nothing_if_already_closed_or_call_inactive( boolean alreadyClosed, boolean callActive ) { // given Throwable unrecoverableError = new RuntimeException("kaboom"); streamingChannelSpy.channelClosedDueToUnrecoverableError = alreadyClosed; streamingChannelSpy.callActiveHolder.heldObject = callActive; // when streamingChannelSpy.closeChannelDueToUnrecoverableError(unrecoverableError); // then assertThat(streamingChannelSpy.channelClosedDueToUnrecoverableError).isTrue(); verifyZeroInteractions(channelMock); }
public void cancelDownstreamRequest(Throwable reason) { if (streamingCallback != null) streamingCallback.cancelStreamingToOriginalCaller(); // Do nothing else if a StreamingChannel was never started. if (streamingChannelCompletableFuture == null) return; streamingChannelCompletableFuture.whenComplete((sc, error) -> { if (sc != null) { // A StreamingChannel was created. Tell it to stop if it's still going. if (sc.isDownstreamCallActive()) sc.closeChannelDueToUnrecoverableError(reason); } }); }