Search in sources :

Example 1 with SocketChannelMonitor

use of com.datastax.driver.core.utils.SocketChannelMonitor in project java-driver by datastax.

the class TimeoutStressTest method createClusterBuilder.

@Override
public Cluster.Builder createClusterBuilder() {
    channelMonitor = register(new SocketChannelMonitor());
    PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 8, 8);
    return Cluster.builder().withPoolingOptions(poolingOptions).withNettyOptions(channelMonitor.nettyOptions()).withReconnectionPolicy(new ConstantReconnectionPolicy(1000));
}
Also used : SocketChannelMonitor(com.datastax.driver.core.utils.SocketChannelMonitor) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 2 with SocketChannelMonitor

use of com.datastax.driver.core.utils.SocketChannelMonitor in project java-driver by datastax.

the class SessionLeakTest method should_not_leak_session_when_wrong_keyspace.

@Test(groups = "short")
public void should_not_leak_session_when_wrong_keyspace() throws Exception {
    // Checking for JAVA-806
    channelMonitor = new SocketChannelMonitor();
    channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
    Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withNettyOptions(channelMonitor.nettyOptions()).build());
    cluster.init();
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    try {
        // Should be 1 control connection after initialization.
        assertOpenConnections(1, cluster);
        cluster.connect("wrong_keyspace");
        fail("Should not have connected to a wrong keyspace");
    } catch (InvalidQueryException e) {
    // ok
    }
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    cluster.close();
    // Ensure no channels remain open.
    channelMonitor.stop();
    channelMonitor.report();
    assertThat(channelMonitor.openChannels(ccm().addressOfNode(1), ccm().addressOfNode(2)).size()).isEqualTo(0);
}
Also used : SocketChannelMonitor(com.datastax.driver.core.utils.SocketChannelMonitor) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) Test(org.testng.annotations.Test)

Example 3 with SocketChannelMonitor

use of com.datastax.driver.core.utils.SocketChannelMonitor in project java-driver by datastax.

the class SessionLeakTest method connectionLeakTest.

@Test(groups = "long")
public void connectionLeakTest() throws Exception {
    // Checking for JAVA-342
    channelMonitor = new SocketChannelMonitor();
    channelMonitor.reportAtFixedInterval(1, TimeUnit.SECONDS);
    Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withNettyOptions(channelMonitor.nettyOptions()).withQueryOptions(nonDebouncingQueryOptions()).build());
    cluster.init();
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    // Should be 1 control connection after initialization.
    assertOpenConnections(1, cluster);
    // ensure sessions.size() returns with 1 control connection + core pool size.
    int corePoolSize = TestUtils.numberOfLocalCoreConnections(cluster);
    Session session = cluster.connect();
    assertThat(cluster.manager.sessions.size()).isEqualTo(1);
    assertOpenConnections(1 + corePoolSize, cluster);
    // ensure sessions.size() returns to 0 with only 1 active connection (the control connection)
    session.close();
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    assertOpenConnections(1, cluster);
    // ensure bootstrapping a node does not create additional connections
    ccm().add(2);
    ccm().start(2);
    ccm().waitForUp(2);
    assertThat(cluster).host(2).comesUpWithin(2, MINUTES);
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    assertOpenConnections(1, cluster);
    // ensure a new session gets registered and core connections are established
    // there should be corePoolSize more connections to accommodate for the new host.
    Session thisSession = cluster.connect();
    assertThat(cluster.manager.sessions.size()).isEqualTo(1);
    assertOpenConnections(1 + (corePoolSize * 2), cluster);
    // ensure bootstrapping a node does not create additional connections that won't get cleaned up
    thisSession.close();
    assertThat(cluster.manager.sessions.size()).isEqualTo(0);
    assertOpenConnections(1, cluster);
    cluster.close();
    // Ensure no channels remain open.
    channelMonitor.stop();
    channelMonitor.report();
    assertThat(channelMonitor.openChannels(newArrayList(ccm().addressOfNode(1), ccm().addressOfNode(2))).size()).isEqualTo(0);
}
Also used : SocketChannelMonitor(com.datastax.driver.core.utils.SocketChannelMonitor) Test(org.testng.annotations.Test)

Aggregations

SocketChannelMonitor (com.datastax.driver.core.utils.SocketChannelMonitor)3 Test (org.testng.annotations.Test)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)1 ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)1