Search in sources :

Example 1 with SessionWrapper

use of com.datastax.oss.driver.internal.core.session.SessionWrapper in project java-driver by datastax.

the class ChannelSocketOptionsIT method should_report_socket_options.

@Test
public void should_report_socket_options() {
    Session session = SESSION_RULE.session();
    DriverExecutionProfile config = session.getContext().getConfig().getDefaultProfile();
    assertThat(config.getBoolean(SOCKET_TCP_NODELAY)).isTrue();
    assertThat(config.getBoolean(SOCKET_KEEP_ALIVE)).isFalse();
    assertThat(config.getBoolean(SOCKET_REUSE_ADDRESS)).isFalse();
    assertThat(config.getInt(SOCKET_LINGER_INTERVAL)).isEqualTo(10);
    assertThat(config.getInt(SOCKET_RECEIVE_BUFFER_SIZE)).isEqualTo(123456);
    assertThat(config.getInt(SOCKET_SEND_BUFFER_SIZE)).isEqualTo(123456);
    Node node = session.getMetadata().getNodes().values().iterator().next();
    if (session instanceof SessionWrapper) {
        session = ((SessionWrapper) session).getDelegate();
    }
    DriverChannel channel = ((DefaultSession) session).getChannel(node, "test");
    assertThat(channel).isNotNull();
    assertThat(channel.config()).isInstanceOf(SocketChannelConfig.class);
    SocketChannelConfig socketConfig = (SocketChannelConfig) channel.config();
    assertThat(socketConfig.isTcpNoDelay()).isTrue();
    assertThat(socketConfig.isKeepAlive()).isFalse();
    assertThat(socketConfig.isReuseAddress()).isFalse();
    assertThat(socketConfig.getSoLinger()).isEqualTo(10);
    RecvByteBufAllocator allocator = socketConfig.getRecvByteBufAllocator();
    assertThat(allocator).isInstanceOf(FixedRecvByteBufAllocator.class);
    assertThat(allocator.newHandle().guess()).isEqualTo(123456);
// cannot assert around SO_RCVBUF and SO_SNDBUF, such values are just hints
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) RecvByteBufAllocator(io.netty.channel.RecvByteBufAllocator) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SocketChannelConfig(io.netty.channel.socket.SocketChannelConfig) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) SessionWrapper(com.datastax.oss.driver.internal.core.session.SessionWrapper) Test(org.junit.Test)

Aggregations

CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 Session (com.datastax.oss.driver.api.core.session.Session)1 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)1 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)1 SessionWrapper (com.datastax.oss.driver.internal.core.session.SessionWrapper)1 FixedRecvByteBufAllocator (io.netty.channel.FixedRecvByteBufAllocator)1 RecvByteBufAllocator (io.netty.channel.RecvByteBufAllocator)1 SocketChannelConfig (io.netty.channel.socket.SocketChannelConfig)1 Test (org.junit.Test)1