当前位置: 首页>>代码示例>>Java>>正文


Java GenericFutureListener.operationComplete方法代码示例

本文整理汇总了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();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:ChannelPipelineFinalizerHandlerTest.java

示例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();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:ChannelPipelineFinalizerHandlerTest.java

示例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);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:17,代码来源:OpenChannelLimitHandlerTest.java

示例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);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:63,代码来源:StreamingAsyncHttpClientTest.java

示例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);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:7,代码来源:AbstractRequestContext.java


注:本文中的io.netty.util.concurrent.GenericFutureListener.operationComplete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。