use of org.scassandra.Scassandra in project java-driver by datastax.
the class ExceptionsScassandraTest method beforeMethod.
@BeforeMethod(groups = "short")
public void beforeMethod() {
cluster = Cluster.builder().addContactPoints(scassandras.address(1).getAddress()).withPort(scassandras.getBinaryPort()).withRetryPolicy(FallthroughRetryPolicy.INSTANCE).build();
session = cluster.connect();
host1 = TestUtils.findHost(cluster, 1);
errors = cluster.getMetrics().getErrorMetrics();
for (Scassandra node : scassandras.nodes()) {
node.primingClient().clearAllPrimes();
node.activityClient().clearAllRecordedActivity();
}
}
use of org.scassandra.Scassandra in project java-driver by datastax.
the class AbstractRetryPolicyIntegrationTest method beforeMethod.
@BeforeMethod(groups = "short")
public void beforeMethod() {
scassandras = ScassandraCluster.builder().withNodes(3).build();
scassandras.init();
cluster = Cluster.builder().addContactPoints(scassandras.address(1).getAddress()).withPort(scassandras.getBinaryPort()).withRetryPolicy(retryPolicy).withLoadBalancingPolicy(new SortingLoadBalancingPolicy()).withPoolingOptions(new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1).setMaxConnectionsPerHost(HostDistance.LOCAL, 1).setHeartbeatIntervalSeconds(0)).withNettyOptions(nonQuietClusterCloseOptions).withQueryOptions(new QueryOptions().setDefaultIdempotence(true)).build();
session = cluster.connect();
host1 = TestUtils.findHost(cluster, 1);
host2 = TestUtils.findHost(cluster, 2);
host3 = TestUtils.findHost(cluster, 3);
errors = cluster.getMetrics().getErrorMetrics();
Mockito.reset(retryPolicy);
for (Scassandra node : scassandras.nodes()) {
node.activityClient().clearAllRecordedActivity();
}
}
use of org.scassandra.Scassandra in project java-driver by datastax.
the class ScassandraCluster method stop.
/**
* Stops a node by id and then asserts that its {@link Host} is marked down
* for the given {@link Cluster} instance within 10 seconds.
*
* @param cluster cluster to wait for down status on.
* @param node Node to stop.
*/
public void stop(Cluster cluster, int node) {
logger.debug("Stopping node {}.", node);
Scassandra scassandra = node(node);
scassandra.stop();
assertThat(cluster).host(node).goesDownWithin(10, TimeUnit.SECONDS);
}
use of org.scassandra.Scassandra in project java-driver by datastax.
the class ScassandraCluster method primeMetadata.
private void primeMetadata(Scassandra node) {
PrimingClient client = node.primingClient();
int nodeCount = 0;
ImmutableList.Builder<Map<String, ?>> rows = ImmutableList.builder();
for (Integer dc : new TreeSet<Integer>(dcNodeMap.keySet())) {
List<Scassandra> nodesInDc = dcNodeMap.get(dc);
List<Long> tokens = getTokensForDC(dc);
for (int n = 0; n < nodesInDc.size(); n++) {
String address = ipPrefix + ++nodeCount;
Scassandra peer = nodesInDc.get(n);
String query;
Map<String, Object> row;
org.scassandra.http.client.types.ColumnMetadata[] metadata;
if (node == peer) {
// prime system.local.
metadata = SELECT_LOCAL;
query = "SELECT * FROM system.local WHERE key='local'";
row = Maps.newHashMap();
addPeerInfo(row, dc, n + 1, "key", "local");
addPeerInfo(row, dc, n + 1, "bootstrapped", "COMPLETED");
addPeerInfo(row, dc, n + 1, "broadcast_address", address);
addPeerInfo(row, dc, n + 1, "cluster_name", "scassandra");
addPeerInfo(row, dc, n + 1, "cql_version", "3.2.0");
addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc));
addPeerInfo(row, dc, n + 1, "listen_address", getPeerInfo(dc, n + 1, "listen_address", address));
addPeerInfo(row, dc, n + 1, "partitioner", "org.apache.cassandra.dht.Murmur3Partitioner");
addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion));
addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(tokens.get(n)));
addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
addPeerInfo(row, dc, n + 1, "graph", false);
// These columns might not always be present, we don't have to specify them in the scassandra
// column metadata as it will default them to text columns.
addPeerInfoIfExists(row, dc, n + 1, "dse_version");
addPeerInfoIfExists(row, dc, n + 1, "workload");
} else {
// prime system.peers.
query = "SELECT * FROM system.peers WHERE peer='" + address + "'";
metadata = SELECT_PEERS;
row = Maps.newHashMap();
addPeerInfo(row, dc, n + 1, "peer", address);
addPeerInfo(row, dc, n + 1, "rpc_address", address);
addPeerInfo(row, dc, n + 1, "data_center", datacenter(dc));
addPeerInfo(row, dc, n + 1, "rack", getPeerInfo(dc, n + 1, "rack", "rack1"));
addPeerInfo(row, dc, n + 1, "release_version", getPeerInfo(dc, n + 1, "release_version", cassandraVersion));
addPeerInfo(row, dc, n + 1, "tokens", ImmutableSet.of(Long.toString(tokens.get(n))));
addPeerInfo(row, dc, n + 1, "host_id", UUIDs.random());
addPeerInfo(row, dc, n + 1, "schema_version", schemaVersion);
addPeerInfo(row, dc, n + 1, "graph", false);
addPeerInfoIfExists(row, dc, n + 1, "listen_address");
addPeerInfoIfExists(row, dc, n + 1, "dse_version");
addPeerInfoIfExists(row, dc, n + 1, "workload");
rows.add(row);
}
client.prime(PrimingRequest.queryBuilder().withQuery(query).withThen(then().withColumnTypes(metadata).withRows(Collections.<Map<String, ?>>singletonList(row)).build()).build());
}
}
client.prime(PrimingRequest.queryBuilder().withQuery("SELECT * FROM system.peers").withThen(then().withColumnTypes(SELECT_PEERS).withRows(rows.build()).build()).build());
// Needed to ensure cluster_name matches what we expect on connection.
Map<String, Object> clusterNameRow = ImmutableMap.<String, Object>builder().put("cluster_name", "scassandra").build();
client.prime(PrimingRequest.queryBuilder().withQuery("select cluster_name from system.local").withThen(then().withColumnTypes(SELECT_CLUSTER_NAME).withRows(Collections.<Map<String, ?>>singletonList(clusterNameRow)).build()).build());
client.prime(PrimingRequest.queryBuilder().withQuery(keyspaceQuery).withThen(then().withColumnTypes(keyspaceColumnTypes).withRows(keyspaceRows).build()).build());
}
Aggregations