本文整理匯總了Java中io.netty.util.concurrent.GenericFutureListener.operationComplete方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericFutureListener.operationComplete方法的具體用法?Java GenericFutureListener.operationComplete怎麽用?Java GenericFutureListener.operationComplete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.concurrent.GenericFutureListener
的用法示例。
在下文中一共展示了GenericFutureListener.operationComplete方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mock
import io.netty.util.concurrent.GenericFutureListener; //導入方法依賴的package包/類
@Test
public void finalizeChannelPipeline_should_send_event_to_metricsListener_for_successful_response_and_flush_context() throws Exception {
// given
ChannelFuture responseWriterChannelFuture = mock(ChannelFuture.class);
state.setResponseWriterFinalChunkChannelFuture(responseWriterChannelFuture);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
ChannelFuture responseWriteFutureResult = mock(ChannelFuture.class);
doReturn(true).when(responseWriteFutureResult).isSuccess();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
// when
handler.finalizeChannelPipeline(ctxMock, null, stateSpy, null);
// then
ArgumentCaptor<GenericFutureListener> channelFutureListenerArgumentCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
verify(responseWriterChannelFuture).addListener(channelFutureListenerArgumentCaptor.capture());
GenericFutureListener futureListener = channelFutureListenerArgumentCaptor.getValue();
assertThat(futureListener, notNullValue());
futureListener.operationComplete(responseWriteFutureResult);
verify(metricsListenerMock).onEvent(eq(ServerMetricsEvent.RESPONSE_SENT), any(HttpProcessingState.class));
verify(ctxMock).flush();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
}
示例2: finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context
import io.netty.util.concurrent.GenericFutureListener; //導入方法依賴的package包/類
@Test
public void finalizeChannelPipeline_should_send_event_to_metricsListener_for_failure_response_and_flush_context() throws Exception {
// given
ChannelFuture responseWriterChannelFuture = mock(ChannelFuture.class);
state.setResponseWriterFinalChunkChannelFuture(responseWriterChannelFuture);
HttpProcessingState stateSpy = spy(state);
doReturn(stateSpy).when(stateAttributeMock).get();
ChannelFuture responseWriteFutureResult = mock(ChannelFuture.class);
doReturn(false).when(responseWriteFutureResult).isSuccess();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isFalse();
// when
handler.finalizeChannelPipeline(ctxMock, null, stateSpy, null);
// then
ArgumentCaptor<GenericFutureListener> channelFutureListenerArgumentCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
verify(responseWriterChannelFuture).addListener(channelFutureListenerArgumentCaptor.capture());
GenericFutureListener futureListener = channelFutureListenerArgumentCaptor.getValue();
assertThat(futureListener, notNullValue());
futureListener.operationComplete(responseWriteFutureResult);
verify(metricsListenerMock).onEvent(ServerMetricsEvent.RESPONSE_WRITE_FAILED, null);
verify(ctxMock).flush();
Assertions.assertThat(stateSpy.isRequestMetricsRecordedOrScheduled()).isTrue();
}
示例3: verifyCloseFutureListener
import io.netty.util.concurrent.GenericFutureListener; //導入方法依賴的package包/類
private void verifyCloseFutureListener(GenericFutureListener closeFutureListener) throws Exception {
// If the double-check ScheduledFuture is not done then it cancels it.
reset(doubleCheckScheduledFutureMock);
doReturn(false).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verify(doubleCheckScheduledFutureMock).cancel(false);
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
// And when the double-check ScheduledFuture is done, then nothing happens.
reset(doubleCheckScheduledFutureMock);
doReturn(true).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
}
示例4: mock
import io.netty.util.concurrent.GenericFutureListener; //導入方法依賴的package包/類
@Test
public void StreamingChannel_streamChunk_sets_up_task_in_event_loop_to_call_doStreamChunk_and_adds_listener_to_complete_promise()
throws Exception {
// given
ChannelFuture doStreamChunkFutureMock = mock(ChannelFuture.class);
doReturn(doStreamChunkFutureMock).when(streamingChannelSpy).doStreamChunk(any(HttpContent.class));
// when
ChannelFuture result = streamingChannelSpy.streamChunk(contentChunkMock);
// then
assertThat(result).isSameAs(streamChunkChannelPromiseMock);
verifyZeroInteractions(streamChunkChannelPromiseMock); // not yet completed
ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(eventLoopMock).execute(taskCaptor.capture());
Runnable task = taskCaptor.getValue();
// and given
verify(streamingChannelSpy, never()).doStreamChunk(any(HttpContent.class)); // not yet called
// when
task.run();
// then
verify(streamingChannelSpy).doStreamChunk(contentChunkMock);
ArgumentCaptor<GenericFutureListener> listenerCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
verify(doStreamChunkFutureMock).addListener(listenerCaptor.capture());
GenericFutureListener listener = listenerCaptor.getValue();
assertThat(listener).isNotNull();
// and when
listener.operationComplete(getFutureForCase(true, false, null));
// then
verify(streamChunkChannelPromiseMock).cancel(true);
verifyNoMoreInteractions(streamChunkChannelPromiseMock);
// and when
listener.operationComplete(getFutureForCase(false, true, null));
// then
verify(streamChunkChannelPromiseMock).setSuccess();
verifyNoMoreInteractions(streamChunkChannelPromiseMock);
// and when
Throwable normalFutureFailure = new RuntimeException("normal future failure");
listener.operationComplete(getFutureForCase(false, false, normalFutureFailure));
// then
verify(streamChunkChannelPromiseMock).setFailure(normalFutureFailure);
verifyNoMoreInteractions(streamChunkChannelPromiseMock);
// and when
reset(streamChunkChannelPromiseMock);
listener.operationComplete(getFutureForCase(false, false, null));
// then
ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(streamChunkChannelPromiseMock).setFailure(throwableCaptor.capture());
assertThat(throwableCaptor.getValue()).hasMessage("Received ChannelFuture that was in an impossible state");
verifyNoMoreInteractions(streamChunkChannelPromiseMock);
}
示例5: invokeOperationComplete
import io.netty.util.concurrent.GenericFutureListener; //導入方法依賴的package包/類
private <T extends Future<?>> void invokeOperationComplete(
GenericFutureListener<T> listener, T future) throws Exception {
try (SafeCloseable ignored = propagateContextIfNotPresent()) {
listener.operationComplete(future);
}
}