Search in sources :

Example 1 with SocketOptions

use of io.grpc.InternalChannelz.SocketOptions in project grpc-java by grpc.

the class UtilsTest method channelOptionsTest_noLinger.

@Test
public void channelOptionsTest_noLinger() {
    Channel channel = new EmbeddedChannel();
    assertNull(channel.config().getOption(ChannelOption.SO_LINGER));
    InternalChannelz.SocketOptions socketOptions = Utils.getSocketOptions(channel);
    assertNull(socketOptions.lingerSeconds);
}
Also used : SocketOptions(io.grpc.InternalChannelz.SocketOptions) InternalChannelz(io.grpc.InternalChannelz) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test)

Example 2 with SocketOptions

use of io.grpc.InternalChannelz.SocketOptions in project grpc-java by grpc.

the class UtilsTest method channelOptionsTest_oio.

@Test
@SuppressWarnings("deprecation")
public void channelOptionsTest_oio() {
    Channel channel = new io.netty.channel.socket.oio.OioSocketChannel();
    SocketOptions socketOptions = setAndValidateGeneric(channel);
    assertEquals(250, (int) socketOptions.soTimeoutMillis);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) SocketOptions(io.grpc.InternalChannelz.SocketOptions) Test(org.junit.Test)

Example 3 with SocketOptions

use of io.grpc.InternalChannelz.SocketOptions in project grpc-java by grpc.

the class UtilsTest method channelOptionsTest_nio.

@Test
public void channelOptionsTest_nio() {
    Channel channel = new NioSocketChannel();
    SocketOptions socketOptions = setAndValidateGeneric(channel);
    assertNull(socketOptions.soTimeoutMillis);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) SocketOptions(io.grpc.InternalChannelz.SocketOptions) Test(org.junit.Test)

Example 4 with SocketOptions

use of io.grpc.InternalChannelz.SocketOptions in project grpc-java by grpc.

the class ChannelzProtoUtilTest method toSocket_withDataWithOptions.

@Test
public void toSocket_withDataWithOptions() throws Exception {
    socket.socketOptions = new SocketOptions(null, null, null, ImmutableMap.of("test_name", "test_value"));
    assertEquals(Socket.newBuilder().setRef(socketRef).setLocal(localAddress).setRemote(remoteAddress).setData(SocketData.newBuilder(socketDataWithDataNoSockOpts).addOption(SocketOption.newBuilder().setName("test_name").setValue("test_value"))).build(), ChannelzProtoUtil.toSocket(socket));
}
Also used : SocketOptions(io.grpc.InternalChannelz.SocketOptions) Test(org.junit.Test)

Example 5 with SocketOptions

use of io.grpc.InternalChannelz.SocketOptions in project grpc-java by grpc.

the class UtilsTest method getSocketOptions.

@Test
public void getSocketOptions() throws Exception {
    Socket socket = new Socket();
    socket.setSoLinger(true, 2);
    socket.setSoTimeout(3);
    socket.setTcpNoDelay(true);
    socket.setReuseAddress(true);
    socket.setReceiveBufferSize(4000);
    socket.setSendBufferSize(5000);
    socket.setKeepAlive(true);
    socket.setOOBInline(true);
    // note: see javadoc for valid input values
    socket.setTrafficClass(8);
    SocketOptions socketOptions = Utils.getSocketOptions(socket);
    assertEquals(2, (int) socketOptions.lingerSeconds);
    assertEquals(3, (int) socketOptions.soTimeoutMillis);
    assertEquals("true", socketOptions.others.get("TCP_NODELAY"));
    assertEquals("true", socketOptions.others.get("SO_REUSEADDR"));
    assertEquals("4000", socketOptions.others.get("SO_RECVBUF"));
    assertEquals("5000", socketOptions.others.get("SO_SNDBUF"));
    assertEquals("true", socketOptions.others.get("SO_KEEPALIVE"));
    assertEquals("true", socketOptions.others.get("SO_OOBINLINE"));
    assertEquals("8", socketOptions.others.get("IP_TOS"));
}
Also used : SocketOptions(io.grpc.InternalChannelz.SocketOptions) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

SocketOptions (io.grpc.InternalChannelz.SocketOptions)6 Test (org.junit.Test)5 Channel (io.netty.channel.Channel)3 ServerChannel (io.netty.channel.ServerChannel)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 InternalChannelz (io.grpc.InternalChannelz)2 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)1 Socket (java.net.Socket)1