use of com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle in project rest.li by linkedin.
the class Http2AlpnHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (!(msg instanceof RequestWithCallback)) {
ctx.write(msg, promise);
return;
}
_alpnPromise.addListener(f -> {
ChannelFuture future = (ChannelFuture) f;
if (future.isSuccess()) {
ctx.write(msg, promise);
} else {
@SuppressWarnings("unchecked") TimeoutAsyncPoolHandle<?> handle = ((RequestWithCallback<?, ?, TimeoutAsyncPoolHandle<?>>) msg).handle();
handle.error().release();
TransportCallback<?> callback = ((RequestWithCallback) msg).callback();
callback.onResponse(TransportResponseImpl.error(future.cause()));
}
});
}
use of com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle in project rest.li by linkedin.
the class TestHttp2AlpnHandler method testChannelCloseBeforeNegotiation.
@Test(timeOut = 10000)
@SuppressWarnings("unchecked")
public void testChannelCloseBeforeNegotiation() throws Exception {
SslContext sslContext = Mockito.mock(SslContext.class);
Http2StreamCodec http2StreamCodec = Mockito.mock(Http2StreamCodec.class);
Http2AlpnHandler handler = new Http2AlpnHandler(sslContext, http2StreamCodec, true, Integer.MAX_VALUE);
EmbeddedChannel channel = new EmbeddedChannel(handler);
RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
TimeoutAsyncPoolHandle handle = Mockito.mock(TimeoutAsyncPoolHandle.class);
TimeoutTransportCallback callback = Mockito.mock(TimeoutTransportCallback.class);
Mockito.when(request.handle()).thenReturn(handle);
Mockito.when(request.callback()).thenReturn(callback);
// Write should not succeed before negotiation completes
Assert.assertFalse(channel.writeOutbound(request));
Assert.assertFalse(channel.finish());
// Synchronously waiting for channel to close
channel.close().sync();
Mockito.verify(request).handle();
Mockito.verify(request).callback();
Mockito.verify(handle).dispose();
Mockito.verify(callback).onResponse(Mockito.any(TransportResponse.class));
}
use of com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle in project rest.li by linkedin.
the class TestTimeoutAsyncPoolHandle method testGoodReleaseAfterTimeout.
@Test
public void testGoodReleaseAfterTimeout() throws Exception {
FakePool<Object> pool = new FakePool<>();
TimeoutAsyncPoolHandle<Object> handle = new TimeoutAsyncPoolHandle<>(pool, _scheduler, IMMEDIATE_TIMEOUT, TIME_UNIT, new Object());
CountDownLatch latch = new CountDownLatch(1);
handle.addTimeoutTask(() -> latch.countDown());
latch.await(OPERATION_TIMEOUT, TIME_UNIT);
handle.release();
Assert.assertEquals(pool.getPutCount(), 1);
Assert.assertEquals(pool.getDisposeCount(), 0);
}
use of com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle in project rest.li by linkedin.
the class TestTimeoutAsyncPoolHandle method testTimeout.
@Test
public void testTimeout() throws Exception {
FakePool<Object> pool = new FakePool<>();
TimeoutAsyncPoolHandle<Object> handle = new TimeoutAsyncPoolHandle<>(pool, _scheduler, IMMEDIATE_TIMEOUT, TIME_UNIT, new Object());
CountDownLatch latch = new CountDownLatch(1);
handle.addTimeoutTask(() -> latch.countDown());
latch.await(OPERATION_TIMEOUT, TIME_UNIT);
Assert.assertEquals(pool.getPutCount(), 1);
Assert.assertEquals(pool.getDisposeCount(), 0);
}
use of com.linkedin.r2.transport.http.client.TimeoutAsyncPoolHandle in project rest.li by linkedin.
the class TestTimeoutAsyncPoolHandle method testBadReleaseAfterTimeout.
@Test
public void testBadReleaseAfterTimeout() throws Exception {
FakePool<Object> pool = new FakePool<>();
TimeoutAsyncPoolHandle<Object> handle = new TimeoutAsyncPoolHandle<>(pool, _scheduler, IMMEDIATE_TIMEOUT, TIME_UNIT, new Object());
CountDownLatch latch = new CountDownLatch(1);
handle.addTimeoutTask(() -> latch.countDown());
latch.await(OPERATION_TIMEOUT, TIME_UNIT);
handle.dispose();
Assert.assertEquals(pool.getPutCount(), 1);
Assert.assertEquals(pool.getDisposeCount(), 0);
}
Aggregations