From afb7d62139ac3140f3e2cdeb8a5aacddf7d60009 Mon Sep 17 00:00:00 2001 From: Nic Munroe Date: Wed, 26 Apr 2017 17:25:12 -0700 Subject: [PATCH] Replace OneTimeTask references with lambdas --- .../NonblockingEndpointExecutionHandler.java | 8 +------ .../ProxyRouterEndpointExecutionHandler.java | 22 +++---------------- ...nblockingEndpointExecutionHandlerTest.java | 7 +++--- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/riposte-core/src/main/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandler.java b/riposte-core/src/main/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandler.java index 6d86b8e2..ac5799ea 100644 --- a/riposte-core/src/main/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandler.java +++ b/riposte-core/src/main/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandler.java @@ -23,7 +23,6 @@ import io.netty.handler.codec.http.LastHttpContent; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.ScheduledFuture; -import io.netty.util.internal.OneTimeTask; import static com.nike.riposte.util.AsyncNettyHelper.executeOnlyIfChannelIsActive; import static com.nike.riposte.util.AsyncNettyHelper.functionWithTracingAndMdc; @@ -180,12 +179,7 @@ protected void asyncCallback(ChannelHandlerContext ctx, ResponseInfo response setResponseInfoAndActivatePipelineForResponse(state, responseInfo, ctx); } else { - executor.execute(new OneTimeTask() { - @Override - public void run() { - setResponseInfoAndActivatePipelineForResponse(state, responseInfo, ctx); - } - }); + executor.execute(() -> setResponseInfoAndActivatePipelineForResponse(state, responseInfo, ctx)); } } ); diff --git a/riposte-core/src/main/java/com/nike/riposte/server/handler/ProxyRouterEndpointExecutionHandler.java b/riposte-core/src/main/java/com/nike/riposte/server/handler/ProxyRouterEndpointExecutionHandler.java index 92938455..ddf06120 100644 --- a/riposte-core/src/main/java/com/nike/riposte/server/handler/ProxyRouterEndpointExecutionHandler.java +++ b/riposte-core/src/main/java/com/nike/riposte/server/handler/ProxyRouterEndpointExecutionHandler.java @@ -48,7 +48,6 @@ import io.netty.handler.codec.http.LastHttpContent; import io.netty.util.Attribute; import io.netty.util.concurrent.EventExecutor; -import io.netty.util.internal.OneTimeTask; import static com.nike.fastbreak.CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey; import static com.nike.riposte.util.AsyncNettyHelper.executeOnlyIfChannelIsActive; @@ -585,12 +584,7 @@ public void messageReceived(HttpObject msg) { sendFirstChunkDownPipeline(state, responseInfo); } else { - executor.execute(new OneTimeTask() { - @Override - public void run() { - sendFirstChunkDownPipeline(state, responseInfo); - } - }); + executor.execute(() -> sendFirstChunkDownPipeline(state, responseInfo)); } } }, @@ -619,12 +613,7 @@ else if (msg instanceof HttpContent) { sendContentChunkDownPipeline(contentChunk, contentChunkToSend); } else { - executor.execute(new OneTimeTask() { - @Override - public void run() { - sendContentChunkDownPipeline(contentChunk, contentChunkToSend); - } - }); + executor.execute(() -> sendContentChunkDownPipeline(contentChunk, contentChunkToSend)); } } else { @@ -691,12 +680,7 @@ public void unrecoverableErrorOccurred(Throwable error) { sendUnrecoverableErrorDownPipeline(error); } else { - executor.execute(new OneTimeTask() { - @Override - public void run() { - sendUnrecoverableErrorDownPipeline(error); - } - }); + executor.execute(() -> sendUnrecoverableErrorDownPipeline(error)); } } diff --git a/riposte-core/src/test/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandlerTest.java b/riposte-core/src/test/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandlerTest.java index b868b40e..5feb1002 100644 --- a/riposte-core/src/test/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandlerTest.java +++ b/riposte-core/src/test/java/com/nike/riposte/server/handler/NonblockingEndpointExecutionHandlerTest.java @@ -32,7 +32,6 @@ import io.netty.util.Attribute; import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.ScheduledFuture; -import io.netty.util.internal.OneTimeTask; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -362,7 +361,7 @@ public void asyncCallback_calls_setResponseInfoAndActivatePipelineForResponse_if } @Test - public void asyncCallback_calls_setResponseInfoAndActivatePipelineForResponse_via_EventExecutor_with_OneTimeTask_if_we_are_not_in_executor_event_loop() { + public void asyncCallback_calls_setResponseInfoAndActivatePipelineForResponse_via_EventExecutor_if_we_are_not_in_executor_event_loop() { // given ResponseInfo responseInfo = ResponseInfo.newBuilder().build(); doReturn(false).when(eventExecutorMock).inEventLoop(); @@ -374,8 +373,8 @@ public void asyncCallback_calls_setResponseInfoAndActivatePipelineForResponse_vi // Verify that the EventExecutor was passed a runnable and extract it so we can verify it. ArgumentCaptor eventExecutorArgCaptor = ArgumentCaptor.forClass(Runnable.class); verify(eventExecutorMock).execute(eventExecutorArgCaptor.capture()); - assertThat(eventExecutorArgCaptor.getValue()).isInstanceOf(OneTimeTask.class); - OneTimeTask task = (OneTimeTask)eventExecutorArgCaptor.getValue(); + assertThat(eventExecutorArgCaptor.getValue()).isNotNull(); + Runnable task = eventExecutorArgCaptor.getValue(); // Verify setResponseInfoAndActivatePipelineForResponse() not called yet verify(handlerSpy, never()).setResponseInfoAndActivatePipelineForResponse(