本文整理汇总了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);
}
}