public void stop() { logger.debug("Stopping ScassandraCluster."); for (Scassandra node : instances) { node.stop(); } }
public void clearActivityLog() { for (Scassandra node : sCluster.nodes()) { node.activityClient().clearAllRecordedActivity(); } }
@BeforeClass(groups = {"short", "long"}) public void beforeTestClass() { scassandra = TestUtils.createScassandraServer(); scassandra.start(); primingClient = scassandra.primingClient(); activityClient = scassandra.activityClient(); currentClient = scassandra.currentClient(); hostAddress = new InetSocketAddress(ip, scassandra.getBinaryPort()); }
protected void simulateError(int hostNumber, Result result, Config config) { PrimingRequest.Then.ThenBuilder then = then().withResult(result); PrimingRequestBuilder builder = PrimingRequest.queryBuilder().withQuery("mock query"); if (config != null) then = then.withConfig(config); builder = builder.withThen(then); scassandras.node(hostNumber).primingClient().prime(builder.build()); }
protected void simulateNormalResponse(int hostNumber) { scassandras .node(hostNumber) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery("mock query") .withThen(then().withRows(row("result", "result1"))) .build()); }
@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(); } }
public Query executeSimple( Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { SimpleStatement simpleStatement = new SimpleStatement(statement); if (level != null) { simpleStatement.setConsistencyLevel(level); } if (serialLevel != null) { simpleStatement.setSerialConsistencyLevel(serialLevel); } session.execute(simpleStatement); // Find the unique query in the activity log. List<Query> queries = sCluster.node(1).activityClient().retrieveQueries(); for (Query query : queries) { if (query.getQuery().equals(statement)) return query; } return null; }
/** * Ensures that if all connections fail to a host on pool init that the host is marked down. * * @jira_ticket JAVA-544 * @test_category connection:connection_pool * @since 2.0.11 */ @Test(groups = "short") public void should_mark_host_down_if_all_connections_fail_on_init() { // Prevent any connections on node 2. scassandra.node(2).currentClient().disableListener(); createCluster(8, 8); // Node 2 should be in a down state while node 1 stays up. assertThat(cluster).host(2).goesDownWithin(10, SECONDS); assertThat(cluster).host(1).isUp(); // Node 2 should come up as soon as it is able to reconnect. scassandra.node(2).currentClient().enableListener(); assertThat(cluster).host(2).comesUpWithin(2, SECONDS); }
@AfterMethod(groups = "short", alwaysRun = true) public void afterMethod() { for (Scassandra node : scassandras.nodes()) { node.primingClient().clearAllPrimes(); } if (cluster != null) cluster.close(); }
protected void assertQueried(int hostNumber, int times) { assertThat(scassandras.node(hostNumber).activityClient().retrieveQueries()).hasSize(times); }
public BatchExecution executeBatch( Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) { BatchStatement batch = new BatchStatement(); batch.add(new SimpleStatement(statement)); if (level != null) { batch.setConsistencyLevel(level); } if (serialLevel != null) { batch.setSerialConsistencyLevel(serialLevel); } session.execute(batch); List<BatchExecution> batches = sCluster.node(1).activityClient().retrieveBatches(); assertEquals(batches.size(), 1); return batches.get(0); }
public void init() { for (Map.Entry<Integer, List<Scassandra>> dc : dcNodeMap.entrySet()) { for (Scassandra node : dc.getValue()) { node.start(); primeMetadata(node); } } }
/** * @return A Scassandra instance with an arbitrarily chosen binary port from 8042-8142 and admin * port from 8052-8152. */ public static Scassandra createScassandraServer() { int binaryPort = findAvailablePort(); int adminPort = findAvailablePort(); return ScassandraFactory.createServer(ipOfNode(1), binaryPort, ipOfNode(1), adminPort); }
protected Cluster.Builder createClusterBuilder() { return Cluster.builder() .withPort(scassandra.getBinaryPort()) .addContactPoints(hostAddress.getAddress()) .withPort(scassandra.getBinaryPort()) .withPoolingOptions( new PoolingOptions() .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) .setHeartbeatIntervalSeconds(0)); }
private void prime(int node, Result result) { sCluster .node(node) .primingClient() .prime( queryBuilder() .withQuery(QueryTracker.QUERY) .withThen(then().withResult(result)) .build()); }
public void clearActivityLog() { for (Scassandra node : sCluster.nodes()) { node.activityClient().clearAllRecordedActivity(); } }
@AfterClass(groups = {"short", "long"}) public void afterTestClass() { if (scassandra != null) scassandra.stop(); }
/** * Starts a node by id and then asserts that its {@link Host} is marked up for the given {@link * Cluster} instance within 10 seconds. * * @param cluster cluster to wait for up status on. * @param node Node to start. */ public void start(Cluster cluster, int node) { logger.debug("Starting node {}.", node); Scassandra scassandra = node(node); scassandra.start(); assertThat(cluster).host(node).comesUpWithin(10, TimeUnit.SECONDS); }
protected void simulateError(int hostNumber, Result result) { scassandras .node(hostNumber) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery("mock query") .withThen(then().withResult(result)) .build()); }
/** * 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); }