Search in sources :

Example 16 with QueryOptions

use of com.datastax.driver.core.QueryOptions in project cassandra by apache.

the class ClientRequestSizeMetricsTest method testReadAndWriteMetricsAreRecordedDuringNativeRequests.

@Test
public void testReadAndWriteMetricsAreRecordedDuringNativeRequests() throws Throwable {
    // We explicitly disable scheme fetching to avoid that effect
    try {
        reinitializeNetwork(builder -> {
        }, builder -> builder.withQueryOptions(new QueryOptions().setMetadataEnabled(false)));
        // Ensure that the connection is open
        sessionNet(version);
        // We want to ignore all the messages sent by the driver upon connection as well as
        // the event sent upon schema updates
        clearMetrics();
        executeNet(version, "SELECT * from system.peers");
        long requestLength = ClientMessageSizeMetrics.bytesReceived.getCount();
        long responseLength = ClientMessageSizeMetrics.bytesSent.getCount();
        assertThat(requestLength).isGreaterThan(0);
        assertThat(responseLength).isGreaterThan(0);
        checkMetrics(1, requestLength, responseLength);
        // Let's fire the same request again and test that the changes are the same that previously
        executeNet(version, "SELECT * from system.peers");
        checkMetrics(2, requestLength, responseLength);
    } finally {
        reinitializeNetwork();
    }
}
Also used : QueryOptions(com.datastax.driver.core.QueryOptions) Test(org.junit.Test)

Example 17 with QueryOptions

use of com.datastax.driver.core.QueryOptions in project storm by apache.

the class ClusterFactory method make.

/**
 * Creates a new Cluster based on the specified configuration.
 * @param topoConf the storm configuration.
 * @return a new a new {@link com.datastax.driver.core.Cluster} instance.
 */
@Override
protected Cluster make(Map<String, Object> topoConf) {
    CassandraConf cassandraConf = new CassandraConf(topoConf);
    Cluster.Builder cluster = Cluster.builder().withoutJMXReporting().withoutMetrics().addContactPoints(cassandraConf.getNodes()).withPort(cassandraConf.getPort()).withRetryPolicy(cassandraConf.getRetryPolicy()).withReconnectionPolicy(new ExponentialReconnectionPolicy(cassandraConf.getReconnectionPolicyBaseMs(), cassandraConf.getReconnectionPolicyMaxMs())).withLoadBalancingPolicy(cassandraConf.getLoadBalancingPolicy());
    cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis((int) cassandraConf.getSocketReadTimeoutMillis());
    cluster.getConfiguration().getSocketOptions().setConnectTimeoutMillis((int) cassandraConf.getSocketConnectTimeoutMillis());
    final String username = cassandraConf.getUsername();
    final String password = cassandraConf.getPassword();
    if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
        cluster.withAuthProvider(new PlainTextAuthProvider(username, password));
    }
    QueryOptions options = new QueryOptions().setConsistencyLevel(cassandraConf.getConsistencyLevel());
    cluster.withQueryOptions(options);
    PoolingOptions poolOps = new PoolingOptions();
    poolOps.setMaxQueueSize(cassandraConf.getPoolMaxQueueSize());
    poolOps.setHeartbeatIntervalSeconds(cassandraConf.getHeartbeatIntervalSeconds());
    poolOps.setIdleTimeoutSeconds(cassandraConf.getIdleTimeoutSeconds());
    poolOps.setMaxRequestsPerConnection(HostDistance.LOCAL, cassandraConf.getMaxRequestPerConnectionLocal());
    poolOps.setMaxRequestsPerConnection(HostDistance.REMOTE, cassandraConf.getMaxRequestPerConnectionRemote());
    cluster.withPoolingOptions(poolOps);
    return cluster.build();
}
Also used : PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) ExponentialReconnectionPolicy(com.datastax.driver.core.policies.ExponentialReconnectionPolicy) QueryOptions(com.datastax.driver.core.QueryOptions)

Aggregations

QueryOptions (com.datastax.driver.core.QueryOptions)17 Cluster (com.datastax.driver.core.Cluster)7 SocketOptions (com.datastax.driver.core.SocketOptions)6 PoolingOptions (com.datastax.driver.core.PoolingOptions)5 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)5 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)4 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)3 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)3 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)3 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)3 SSLOptions (com.datastax.driver.core.SSLOptions)2 WhiteListPolicy (com.datastax.driver.core.policies.WhiteListPolicy)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 AuthProvider (com.datastax.driver.core.AuthProvider)1 Configuration (com.datastax.driver.core.Configuration)1 Host (com.datastax.driver.core.Host)1 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)1 Metadata (com.datastax.driver.core.Metadata)1 ResultSet (com.datastax.driver.core.ResultSet)1