use of com.linkedin.r2.netty.handler.http2.Http2AlpnHandler 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.netty.handler.http2.Http2AlpnHandler in project rest.li by linkedin.
the class TestHttp2AlpnHandler method testWriteBeforeNegotiation.
@Test
public void testWriteBeforeNegotiation() 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);
// Write should not succeed before negotiation completes
RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
Assert.assertFalse(channel.writeOutbound(request));
Assert.assertFalse(channel.finish());
}
use of com.linkedin.r2.netty.handler.http2.Http2AlpnHandler in project rest.li by linkedin.
the class Http2ChannelInitializer method configureSsl.
/**
* Configure the pipeline for TLS ALPN negotiation to HTTP/2.
*/
private void configureSsl(NioSocketChannel channel) throws SSLException {
final SslContext sslCtx = createSslContext();
final ChannelPromise alpnPromise = channel.newPromise();
channel.attr(NettyChannelAttributes.INITIALIZATION_FUTURE).set(alpnPromise);
channel.pipeline().addLast(SessionResumptionSslHandler.PIPELINE_SESSION_RESUMPTION_HANDLER, new SessionResumptionSslHandler(sslCtx, _enableSSLSessionResumption, _sslHandShakeTimeout));
channel.pipeline().addLast(new Http2AlpnHandler(alpnPromise, createHttp2Settings()));
}
Aggregations