private Set<String> getRandomUsers(PreparedStatement ps) { // lots of code. try { SimpleStatement query = new SimpleStatement(sql); query.setConsistencyLevel(ConsistencyLevel.QUORUM); // abstract the handling of the cache to it's own class. // this will need some work to make sure it's thread safe // as currently it's not. ResultSet res = session.execute(psCache.getStatement(sql));
protected ResultSet queryWithCL(ConsistencyLevel cl) { Statement statement = new SimpleStatement("mock query").setConsistencyLevel(cl); return session.execute(statement); }
@Test(groups = "short") public void should_pass_wrapped_statement_to_retry_policy() { retryPolicy.customStatementsHandled.set(0); // Set CL TWO with only one node, so the statement will always cause UNAVAILABLE, // which our custom policy ignores. Statement s = new SimpleStatement("select * from system.local").setConsistencyLevel(ConsistencyLevel.TWO); session().execute(s); assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(0); session().execute(new CustomStatement(s)); assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); }
/** * Validates that if a query gets retried, the second internal query will still have tracing * enabled. * * <p>To force a retry, we use the downgrading policy with an impossible CL. * * @test_category tracing * @jira_ticket JAVA-815 * @expected_result {@link ResultSet} where {@link ExecutionInfo} contains trace information after * a retry. */ @Test(groups = "short") public void should_preserve_tracing_status_across_retries() { SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); st.setConsistencyLevel(ConsistencyLevel.THREE).enableTracing(); ResultSet result = session().execute(st); // sleep 10 seconds to make sure the trace will be complete Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); assertThat(result.getExecutionInfo().getQueryTrace()).isNotNull(); } }
@Test(groups = "short") public void retriesTest() { retryDecision = RetryDecision.retry(ConsistencyLevel.ONE); // We only have one node, this will throw an unavailable exception Statement statement = new SimpleStatement("SELECT v FROM test WHERE k = 1") .setConsistencyLevel(ConsistencyLevel.TWO); session().execute(statement); Errors errors = cluster().getMetrics().getErrorMetrics(); assertEquals(errors.getUnavailables().getCount(), 1); assertEquals(errors.getRetries().getCount(), 1); assertEquals(errors.getRetriesOnUnavailable().getCount(), 1); retryDecision = RetryDecision.ignore(); session().execute(statement); assertEquals(errors.getUnavailables().getCount(), 2); assertEquals(errors.getIgnores().getCount(), 1); assertEquals(errors.getIgnoresOnUnavailable().getCount(), 1); }
protected void query(int n, boolean usePrepared, ConsistencyLevel cl) { if (usePrepared) { BoundStatement bs = prepared.bind(0); for (int i = 0; i < n; ++i) addCoordinator(session().execute(bs)); } else { ByteBuffer routingKey = ByteBuffer.allocate(4); routingKey.putInt(0, 0); for (int i = 0; i < n; ++i) addCoordinator( session() .execute( new SimpleStatement(String.format("SELECT * FROM %s WHERE k = 0", tableName)) .setRoutingKey(routingKey) .setConsistencyLevel(cl))); } } }
@Test(groups = "short") public void should_preserve_timestamp_when_retrying() { SimpleStatement statement = new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)"); statement.setDefaultTimestamp(10); // This will fail since we test against a single-host cluster. The // DowngradingConsistencyRetryPolicy // will retry it at ONE. statement.setConsistencyLevel(ConsistencyLevel.TWO); session().execute(statement); Errors metrics = session().getCluster().getMetrics().getErrorMetrics(); assertEquals(metrics.getRetriesOnUnavailable().getCount(), 1); long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); assertEquals(writeTime, 10); } }
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; }
protected void write(int n, boolean batch, ConsistencyLevel cl) { // We don't use insert for our test because the resultSet don't ship the queriedHost // Also note that we don't use tracing because this would trigger requests that screw up the // test for (int i = 0; i < n; ++i) if (batch) // BUG: WriteType == SIMPLE session() .execute( batch() .add(insertInto(tableName).values(new String[] {"k", "i"}, new Object[] {0, 0})) .setConsistencyLevel(cl)); else session() .execute( new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", tableName)) .setConsistencyLevel(cl)); }
.execute( new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)) .setConsistencyLevel(ConsistencyLevel.ONE)), key); .executeAsync( new SimpleStatement(String.format(TestUtils.SELECT_ALL_FORMAT, TABLE1)) .setConsistencyLevel(ConsistencyLevel.ONE)) .getUninterruptibly(), key);
checkExecuteResultSet( compressedSession.execute( new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)), key); compressedSession .executeAsync( new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)) .getUninterruptibly(), key);
private void executeStatement(String statement) { if (!statement.isEmpty()) { SimpleStatement simpleStatement = new SimpleStatement(statement); simpleStatement.setConsistencyLevel(this.consistencyLevel); session.execute(simpleStatement); } }
private void executeStatement(String statement) { if (!statement.isEmpty()) { SimpleStatement simpleStatement = new SimpleStatement(statement); simpleStatement.setConsistencyLevel(this.consistencyLevel); session.execute(simpleStatement); } }
statement.setConsistencyLevel(ConsistencyLevel.TWO); ResultSet rs = session.execute(statement); Row row = rs.one();
protected ResultSet queryWithCL(ConsistencyLevel cl) { Statement statement = new SimpleStatement("mock query").setConsistencyLevel(cl); return session.execute(statement); }
@Test(groups = "short") public void should_pass_wrapped_statement_to_retry_policy() { retryPolicy.customStatementsHandled.set(0); // Set CL TWO with only one node, so the statement will always cause UNAVAILABLE, // which our custom policy ignores. Statement s = new SimpleStatement("select * from system.local").setConsistencyLevel(ConsistencyLevel.TWO); session().execute(s); assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(0); session().execute(new CustomStatement(s)); assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); }
protected void query(int n, boolean usePrepared, ConsistencyLevel cl) { if (usePrepared) { BoundStatement bs = prepared.bind(0); for (int i = 0; i < n; ++i) addCoordinator(session().execute(bs)); } else { ByteBuffer routingKey = ByteBuffer.allocate(4); routingKey.putInt(0, 0); for (int i = 0; i < n; ++i) addCoordinator( session() .execute( new SimpleStatement(String.format("SELECT * FROM %s WHERE k = 0", tableName)) .setRoutingKey(routingKey) .setConsistencyLevel(cl))); } } }
@Test(groups = "short") public void should_preserve_timestamp_when_retrying() { SimpleStatement statement = new SimpleStatement("INSERT INTO foo (k, v) VALUES (1, 1)"); statement.setDefaultTimestamp(10); // This will fail since we test against a single-host cluster. The // DowngradingConsistencyRetryPolicy // will retry it at ONE. statement.setConsistencyLevel(ConsistencyLevel.TWO); session().execute(statement); Errors metrics = session().getCluster().getMetrics().getErrorMetrics(); assertEquals(metrics.getRetriesOnUnavailable().getCount(), 1); long writeTime = session().execute("SELECT writeTime(v) FROM foo WHERE k = 1").one().getLong(0); assertEquals(writeTime, 10); } }
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; }
protected void write(int n, boolean batch, ConsistencyLevel cl) { // We don't use insert for our test because the resultSet don't ship the queriedHost // Also note that we don't use tracing because this would trigger requests that screw up the // test for (int i = 0; i < n; ++i) if (batch) // BUG: WriteType == SIMPLE session() .execute( batch() .add(insertInto(tableName).values(new String[] {"k", "i"}, new Object[] {0, 0})) .setConsistencyLevel(cl)); else session() .execute( new SimpleStatement(String.format("INSERT INTO %s(k, i) VALUES (0, 0)", tableName)) .setConsistencyLevel(cl)); }