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();
}
}
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();
}
Aggregations