@Test public void testQueryPatternWithRegexAtEnd() throws Exception { // given PrimingRequest primingRequest = PrimingRequest.queryBuilder() .withQueryPattern("select name from people where name = .*") .withThen(then().withRows(ImmutableMap.of("name", "Chris")).build()) .build(); primingClient.prime(primingRequest); // when CassandraResult results = cassandra().executeQuery("select name from people where name = 'Chris'"); // then List<CassandraRow> rows = results.rows(); assertEquals(1, rows.size()); assertEquals("Chris", rows.get(0).getString("name")); }
@Test public void preparedStatementPatternDelay() { // given long primedDelay = 500; primingClient.primePreparedStatement( preparedStatementBuilder().withFixedDelay(primedDelay).withQueryPattern(".*").build()); // when long before = System.currentTimeMillis(); CassandraResult results = cassandra().prepareAndExecute("select * from people where name = ?", "Chris"); long duration = System.currentTimeMillis() - before; // then assertEquals(success, results.status().getResult()); assertTrue( "Expected delay of " + primedDelay + " got " + duration, duration > primedDelay && duration < (primedDelay + 200)); }
private void testPrimingUnavailable( UnavailableConfig unavailableConfig, Consistency statementCL, Consistency expectedCL) { String query = "select * from people"; PrimingRequest prime = PrimingRequest.queryBuilder() .withQuery(query) .withResult(unavailable) .withConfig(unavailableConfig) .build(); primingClient.prime(prime); CassandraResult cassandraResult = cassandra().executeSimpleStatement(query, statementCL.name()); CassandraResult.ResponseStatus status = cassandraResult.status(); assertEquals(unavailable, status.getResult()); assertEquals(expectedCL.name(), ((CassandraResult.UnavailableStatus) status).getConsistency()); assertEquals(4, ((CassandraResult.UnavailableStatus) status).getRequiredAcknowledgements()); assertEquals(3, ((CassandraResult.UnavailableStatus) status).getAlive()); }
private void testPrimingWriteTimeout( WriteTimeoutConfig writeTimeoutConfig, Consistency statementCL, Consistency expectedCL) { String query = "select * from people"; PrimingRequest prime = PrimingRequest.queryBuilder() .withQuery(query) .withResult(write_request_timeout) .withConfig(writeTimeoutConfig) .build(); primingClient.prime(prime); CassandraResult cassandraResult = cassandra().executeSimpleStatement(query, statementCL.name()); CassandraResult.ResponseStatus status = cassandraResult.status(); assertEquals(write_request_timeout, status.getResult()); assertEquals(expectedCL.name(), ((CassandraResult.WriteTimeoutStatus) status).getConsistency()); assertEquals(2, ((CassandraResult.WriteTimeoutStatus) status).getReceivedAcknowledgements()); assertEquals(3, ((CassandraResult.WriteTimeoutStatus) status).getRequiredAcknowledgements()); assertEquals(BATCH_LOG, ((CassandraResult.WriteTimeoutStatus) status).getWriteTypePrime()); }
private CassandraResult assertErrorMessageStatus( Result result, Config config, String expectedMsg, Result expectedResult) { String query = "select * from people"; String consistency = "LOCAL_ONE"; PrimingRequest prime = PrimingRequest.queryBuilder() .withQuery(query) .withResult(result) .withConfig(config) .build(); primingClient.prime(prime); CassandraResult cassandraResult = cassandra().executeSimpleStatement(query, consistency); CassandraResult.ResponseStatus status = cassandraResult.status(); assertEquals(expectedResult, status.getResult()); String actualErrorMessage = ((CassandraResult.ErrorMessageStatus) status).getMessage(); assertTrue( "Expected error message to contain: " + expectedMsg + " Got: " + actualErrorMessage, actualErrorMessage.contains(expectedMsg)); return cassandraResult; }