use of io.netty.channel.EventLoop in project grpc-java by grpc.
the class WriteQueueTest method setUp.
/**
* Set up for test.
*/
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(channel.newPromise()).thenReturn(promise);
EventLoop eventLoop = Mockito.mock(EventLoop.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Runnable r = (Runnable) invocation.getArguments()[0];
r.run();
return null;
}
}).when(eventLoop).execute(any(Runnable.class));
when(eventLoop.inEventLoop()).thenReturn(true);
when(channel.eventLoop()).thenReturn(eventLoop);
when(channel.flush()).thenAnswer(new Answer<Channel>() {
@Override
public Channel answer(InvocationOnMock invocation) throws Throwable {
synchronized (lock) {
flushCalledNanos = System.nanoTime();
if (flushCalledNanos == writeCalledNanos) {
flushCalledNanos += 1;
}
}
return channel;
}
});
when(channel.write(any(QueuedCommand.class), eq(promise))).thenAnswer(new Answer<ChannelFuture>() {
@Override
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
synchronized (lock) {
writeCalledNanos = System.nanoTime();
if (writeCalledNanos == flushCalledNanos) {
writeCalledNanos += 1;
}
}
return promise;
}
});
}
use of io.netty.channel.EventLoop in project ProxProx by GoMint.
the class ConnectionHandler method flush.
private void flush(FlushItem item) {
EventLoop loop = item.channel.eventLoop();
Flusher flusher = flusherLookup.get(loop);
if (flusher == null) {
Flusher alt = flusherLookup.putIfAbsent(loop, flusher = new Flusher(loop));
if (alt != null) {
flusher = alt;
}
}
flusher.queued.add(item);
flusher.start();
}
use of io.netty.channel.EventLoop in project riposte by Nike-Inc.
the class ProxyRouterEndpointExecutionHandler method getCircuitBreaker.
protected Optional<CircuitBreaker<HttpResponse>> getCircuitBreaker(DownstreamRequestFirstChunkInfo downstreamReqFirstChunkInfo, ChannelHandlerContext ctx) {
if (downstreamReqFirstChunkInfo == null || downstreamReqFirstChunkInfo.disableCircuitBreaker)
return Optional.empty();
// custom one is not specified.
if (downstreamReqFirstChunkInfo.customCircuitBreaker.isPresent())
return downstreamReqFirstChunkInfo.customCircuitBreaker;
// No custom circuit breaker. Use the default for the given request's host.
EventLoop nettyEventLoop = ctx.channel().eventLoop();
CircuitBreaker<Integer> defaultStatusCodeCircuitBreaker = getDefaultHttpStatusCodeCircuitBreakerForKey(downstreamReqFirstChunkInfo.host, Optional.ofNullable(nettyEventLoop), Optional.ofNullable(nettyEventLoop));
return Optional.of(new CircuitBreakerDelegate<>(defaultStatusCodeCircuitBreaker, httpResponse -> (httpResponse == null ? null : httpResponse.getStatus().code())));
}
use of io.netty.channel.EventLoop in project pravega by pravega.
the class ServerConnectionInboundHandler method send.
@Override
public void send(WireCommand cmd) {
Channel c = getChannel();
// Work around for https://github.com/netty/netty/issues/3246
EventLoop eventLoop = c.eventLoop();
if (eventLoop.inEventLoop()) {
eventLoop.execute(() -> writeAndFlush(c, cmd));
} else {
writeAndFlush(c, cmd);
}
}
use of io.netty.channel.EventLoop in project riposte by Nike-Inc.
the class NonblockingEndpointExecutionHandlerTest method beforeMethod.
@Before
public void beforeMethod() {
stateMock = mock(HttpProcessingState.class);
proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
ctxMock = mock(ChannelHandlerContext.class);
channelMock = mock(Channel.class);
stateAttrMock = mock(Attribute.class);
proxyRouterStateAttrMock = mock(Attribute.class);
requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
endpointMock = mock(StandardEndpoint.class);
longRunningTaskExecutorMock = mock(Executor.class);
responseFuture = new CompletableFuture<>();
stateWorkChainFutureSpy = spy(CompletableFuture.completedFuture(null));
eventLoopMock = mock(EventLoop.class);
eventExecutorMock = mock(EventExecutor.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(stateMock).when(stateAttrMock).get();
doReturn(false).when(stateMock).isRequestHandled();
doReturn(proxyRouterStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(proxyRouterStateMock).when(proxyRouterStateAttrMock).get();
doReturn(endpointMock).when(stateMock).getEndpointForExecution();
doReturn(requestInfo).when(stateMock).getRequestInfo();
doReturn(responseFuture).when(endpointMock).execute(any(RequestInfo.class), any(Executor.class), any(ChannelHandlerContext.class));
doReturn(eventLoopMock).when(channelMock).eventLoop();
doReturn(eventExecutorMock).when(ctxMock).executor();
doReturn(true).when(eventExecutorMock).inEventLoop();
doReturn(true).when(channelMock).isActive();
doAnswer(invocation -> {
CompletableFuture actualFutureForAttaching = (CompletableFuture) invocation.callRealMethod();
futureThatWillBeAttachedToSpy = spy(actualFutureForAttaching);
return futureThatWillBeAttachedToSpy;
}).when(stateWorkChainFutureSpy).thenCompose(any(Function.class));
doReturn(stateWorkChainFutureSpy).when(stateMock).getPreEndpointExecutionWorkChain();
handlerSpy = spy(new NonblockingEndpointExecutionHandler(longRunningTaskExecutorMock, defaultCompletableFutureTimeoutMillis));
}
Aggregations