use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project grpc-java by grpc.
the class NettyServerTest method connectionSettingsPropagated.
@Test(timeout = 60000)
public void connectionSettingsPropagated() throws Exception {
final int originalLowWaterMark = 2097169;
final int originalHighWaterMark = 2097211;
Map<ChannelOption<?>, Object> childChannelOptions = new HashMap<>();
childChannelOptions.put(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(originalLowWaterMark, originalHighWaterMark));
class TestChannelHandler extends ChannelHandlerAdapter {
CountDownLatch countDownLatch = new CountDownLatch(1);
int lowWaterMark;
int highWaterMark;
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
Channel channel = ctx.channel();
WriteBufferWaterMark writeBufferWaterMark = channel.config().getOption(ChannelOption.WRITE_BUFFER_WATER_MARK);
lowWaterMark = writeBufferWaterMark.low();
highWaterMark = writeBufferWaterMark.high();
countDownLatch.countDown();
}
}
final TestChannelHandler channelHandler = new TestChannelHandler();
class TestProtocolNegotiator implements ProtocolNegotiator {
Attributes eagAttributes;
@Override
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler handler) {
eagAttributes = handler.getEagAttributes();
return channelHandler;
}
@Override
public void close() {
}
@Override
public AsciiString scheme() {
return Utils.HTTP;
}
}
Attributes eagAttributes = Attributes.newBuilder().set(Attributes.Key.create("foo"), "bar").build();
TestProtocolNegotiator protocolNegotiator = new TestProtocolNegotiator();
InetSocketAddress addr = new InetSocketAddress(0);
NettyServer ns = new NettyServer(Arrays.asList(addr), new ReflectiveChannelFactory<>(NioServerSocketChannel.class), new HashMap<ChannelOption<?>, Object>(), childChannelOptions, new FixedObjectPool<>(eventLoop), new FixedObjectPool<>(eventLoop), false, protocolNegotiator, Collections.<ServerStreamTracer.Factory>emptyList(), TransportTracer.getDefaultFactory(), // ignore
1, // ignore
false, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
true, // ignore
0, eagAttributes, channelz);
ns.start(new ServerListener() {
@Override
public ServerTransportListener transportCreated(ServerTransport transport) {
return new NoopServerTransportListener();
}
@Override
public void serverShutdown() {
}
});
Socket socket = new Socket();
socket.connect(ns.getListenSocketAddress(), /* timeout= */
8000);
channelHandler.countDownLatch.await();
socket.close();
assertThat(protocolNegotiator.eagAttributes).isSameInstanceAs(eagAttributes);
assertThat(channelHandler.lowWaterMark).isEqualTo(originalLowWaterMark);
assertThat(channelHandler.highWaterMark).isEqualTo(originalHighWaterMark);
ns.shutdown();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project grpc-java by grpc.
the class NettyServerTest method channelzListenSocket.
@Test
public void channelzListenSocket() throws Exception {
InetSocketAddress addr = new InetSocketAddress(0);
NettyServer ns = new NettyServer(Arrays.asList(addr), new ReflectiveChannelFactory<>(NioServerSocketChannel.class), new HashMap<ChannelOption<?>, Object>(), new HashMap<ChannelOption<?>, Object>(), new FixedObjectPool<>(eventLoop), new FixedObjectPool<>(eventLoop), false, ProtocolNegotiators.plaintext(), Collections.<ServerStreamTracer.Factory>emptyList(), TransportTracer.getDefaultFactory(), // ignore
1, // ignore
false, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
1, // ignore
true, // ignore
0, Attributes.EMPTY, channelz);
final SettableFuture<Void> shutdownCompleted = SettableFuture.create();
ns.start(new ServerListener() {
@Override
public ServerTransportListener transportCreated(ServerTransport transport) {
return new NoopServerTransportListener();
}
@Override
public void serverShutdown() {
shutdownCompleted.set(null);
}
});
assertThat(((InetSocketAddress) ns.getListenSocketAddress()).getPort()).isGreaterThan(0);
// SocketStats won't be available until the event loop task of adding SocketStats created by
// ns.start() complete. So submit a noop task and await until it's drained.
eventLoop.submit(new Runnable() {
@Override
public void run() {
}
}).await(5, TimeUnit.SECONDS);
InternalInstrumented<SocketStats> listenSocket = ns.getListenSocketStats();
assertSame(listenSocket, channelz.getSocket(id(listenSocket)));
// very basic sanity check of the contents
SocketStats socketStats = listenSocket.getStats().get();
assertEquals(ns.getListenSocketAddress(), socketStats.local);
assertNull(socketStats.remote);
// by default, there are some socket options set on the listen socket
assertThat(socketStats.socketOptions.others).isNotEmpty();
// Cleanup
ns.shutdown();
shutdownCompleted.get();
// listen socket is removed
assertNull(channelz.getSocket(id(listenSocket)));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project netty by netty.
the class BootstrapTest method testChannelOptionOrderPreserve.
@Test
public void testChannelOptionOrderPreserve() throws InterruptedException {
final BlockingQueue<ChannelOption<?>> options = new LinkedBlockingQueue<ChannelOption<?>>();
class ChannelConfigValidator extends DefaultChannelConfig {
ChannelConfigValidator(Channel channel) {
super(channel);
}
@Override
public <T> boolean setOption(ChannelOption<T> option, T value) {
options.add(option);
return super.setOption(option, value);
}
}
final CountDownLatch latch = new CountDownLatch(1);
final Bootstrap bootstrap = new Bootstrap().handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) {
latch.countDown();
}
}).group(groupA).channelFactory(new ChannelFactory<Channel>() {
@Override
public Channel newChannel() {
return new LocalChannel() {
private ChannelConfigValidator config;
@Override
public synchronized ChannelConfig config() {
if (config == null) {
config = new ChannelConfigValidator(this);
}
return config;
}
};
}
}).option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1).option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 2);
bootstrap.register().syncUninterruptibly();
latch.await();
// Check the order is the same as what we defined before.
assertSame(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, options.take());
assertSame(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, options.take());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOption in project netty by netty.
the class ServerBootstrapConfig method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder(super.toString());
buf.setLength(buf.length() - 1);
buf.append(", ");
EventLoopGroup childGroup = childGroup();
if (childGroup != null) {
buf.append("childGroup: ");
buf.append(StringUtil.simpleClassName(childGroup));
buf.append(", ");
}
Map<ChannelOption<?>, Object> childOptions = childOptions();
if (!childOptions.isEmpty()) {
buf.append("childOptions: ");
buf.append(childOptions);
buf.append(", ");
}
Map<AttributeKey<?>, Object> childAttrs = childAttrs();
if (!childAttrs.isEmpty()) {
buf.append("childAttrs: ");
buf.append(childAttrs);
buf.append(", ");
}
ChannelHandler childHandler = childHandler();
if (childHandler != null) {
buf.append("childHandler: ");
buf.append(childHandler);
buf.append(", ");
}
if (buf.charAt(buf.length() - 1) == '(') {
buf.append(')');
} else {
buf.setCharAt(buf.length() - 2, ')');
buf.setLength(buf.length() - 1);
}
return buf.toString();
}
Aggregations