Skip to content

Commit

Permalink
Merge pull request #52 from nicmunroe/bugfix/remove-references-to-net…
Browse files Browse the repository at this point in the history
…ty-internal-classes

Replace OneTimeTask references with lambdas
  • Loading branch information
nicmunroe authored Apr 27, 2017
2 parents 3784980 + afb7d62 commit 8c07cc9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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<Runnable> 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(
Expand Down

0 comments on commit 8c07cc9

Please sign in to comment.