use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project grpc-java by grpc.
the class NettyClientTransportTest method setSoLingerChannelOption.
@Test
public void setSoLingerChannelOption() throws IOException {
startServer();
Map<ChannelOption<?>, Object> channelOptions = new HashMap<>();
// set SO_LINGER option
int soLinger = 123;
channelOptions.put(ChannelOption.SO_LINGER, soLinger);
NettyClientTransport transport = new NettyClientTransport(address, new ReflectiveChannelFactory<>(NioSocketChannel.class), channelOptions, group, newNegotiator(), false, DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, KEEPALIVE_TIME_NANOS_DISABLED, 1L, false, authority, null, /* user agent */
tooManyPingsRunnable, new TransportTracer(), Attributes.EMPTY, new SocketPicker(), new FakeChannelLogger(), false);
transports.add(transport);
callMeMaybe(transport.start(clientTransportListener));
// verify SO_LINGER has been set
ChannelConfig config = transport.channel().config();
assertTrue(config instanceof SocketChannelConfig);
assertEquals(soLinger, ((SocketChannelConfig) config).getSoLinger());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project grpc-java by grpc.
the class NettyClientTransportTest method failingToConstructChannelShouldFailGracefully.
@Test
public void failingToConstructChannelShouldFailGracefully() throws Exception {
address = TestUtils.testServerAddress(new InetSocketAddress(12345));
authority = GrpcUtil.authorityFromHostAndPort(address.getHostString(), address.getPort());
NettyClientTransport transport = new NettyClientTransport(address, new ReflectiveChannelFactory<>(CantConstructChannel.class), new HashMap<ChannelOption<?>, Object>(), group, newNegotiator(), false, DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, KEEPALIVE_TIME_NANOS_DISABLED, 1, false, authority, null, tooManyPingsRunnable, new TransportTracer(), Attributes.EMPTY, new SocketPicker(), new FakeChannelLogger(), false);
transports.add(transport);
// Should not throw
callMeMaybe(transport.start(clientTransportListener));
// And RPCs and PINGs should fail cleanly, reporting the failure
Rpc rpc = new Rpc(transport);
try {
rpc.waitForResponse();
fail("Expected exception");
} catch (Exception ex) {
if (!(getRootCause(ex) instanceof CantConstructChannelError)) {
throw new AssertionError("Could not find expected error", ex);
}
}
final SettableFuture<Object> pingResult = SettableFuture.create();
FakeClock clock = new FakeClock();
ClientTransport.PingCallback pingCallback = new ClientTransport.PingCallback() {
@Override
public void onSuccess(long roundTripTimeNanos) {
pingResult.set(roundTripTimeNanos);
}
@Override
public void onFailure(Throwable cause) {
pingResult.setException(cause);
}
};
transport.ping(pingCallback, clock.getScheduledExecutorService());
assertFalse(pingResult.isDone());
clock.runDueTasks();
assertTrue(pingResult.isDone());
try {
pingResult.get();
fail("Expected exception");
} catch (Exception ex) {
if (!(getRootCause(ex) instanceof CantConstructChannelError)) {
throw new AssertionError("Could not find expected error", ex);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project spring-boot by spring-projects.
the class NettyWebServerFactoryCustomizerTests method verifyConnectionTimeout.
private void verifyConnectionTimeout(NettyReactiveWebServerFactory factory, Integer expected) {
if (expected == null) {
then(factory).should(never()).addServerCustomizers(any(NettyServerCustomizer.class));
return;
}
then(factory).should(times(2)).addServerCustomizers(this.customizerCaptor.capture());
NettyServerCustomizer serverCustomizer = this.customizerCaptor.getAllValues().get(0);
HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
Map<ChannelOption<?>, ?> options = httpServer.configuration().options();
assertThat(options.get(ChannelOption.CONNECT_TIMEOUT_MILLIS)).isEqualTo(expected);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project java by wavefrontHQ.
the class TcpIngester method run.
public void run() {
activeListeners.inc();
ServerBootstrap b = new ServerBootstrap();
EventLoopGroup parentGroup;
EventLoopGroup childGroup;
Class<? extends ServerChannel> socketChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + listeningPort);
parentGroup = new EpollEventLoopGroup(1);
childGroup = new EpollEventLoopGroup();
socketChannelClass = EpollServerSocketChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + listeningPort);
parentGroup = new NioEventLoopGroup(1);
childGroup = new NioEventLoopGroup();
socketChannelClass = NioServerSocketChannel.class;
}
try {
b.group(parentGroup, childGroup).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, 1024).localAddress(listeningPort).childHandler(initializer);
if (parentChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : parentChannelOptions.entrySet()) {
b.option((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
if (childChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : childChannelOptions.entrySet()) {
b.childOption((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
// Start the server.
ChannelFuture f = b.bind().sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} catch (final InterruptedException e) {
logger.log(Level.WARNING, "Interrupted");
parentGroup.shutdownGracefully();
childGroup.shutdownGracefully();
logger.info("Listener on port " + String.valueOf(listeningPort) + " shut down");
} catch (Exception e) {
// ChannelFuture throws undeclared checked exceptions, so we need to handle it
if (e instanceof BindException) {
logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
} else {
logger.log(Level.SEVERE, "TcpIngester exception: ", e);
}
} finally {
activeListeners.dec();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project grpc-java by grpc.
the class NettyClientTransportTest method newTransport.
private NettyClientTransport newTransport(ProtocolNegotiator negotiator, int maxMsgSize, int maxHeaderListSize, String userAgent, boolean enableKeepAlive, long keepAliveTimeNano, long keepAliveTimeoutNano, ChannelFactory<? extends Channel> channelFactory, EventLoopGroup group) {
if (!enableKeepAlive) {
keepAliveTimeNano = KEEPALIVE_TIME_NANOS_DISABLED;
}
NettyClientTransport transport = new NettyClientTransport(address, channelFactory, new HashMap<ChannelOption<?>, Object>(), group, negotiator, false, DEFAULT_WINDOW_SIZE, maxMsgSize, maxHeaderListSize, keepAliveTimeNano, keepAliveTimeoutNano, false, authority, userAgent, tooManyPingsRunnable, new TransportTracer(), eagAttributes, new SocketPicker(), new FakeChannelLogger(), false);
transports.add(transport);
return transport;
}
Aggregations