use of com.datastax.oss.simulacron.common.cluster.QueryLog in project java-driver by datastax.
the class BoundStatementSimulacronIT method should_use_consistencies_from_simple_statement.
@Test
public void should_use_consistencies_from_simple_statement() {
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
PreparedStatement prepared = session.prepare(st);
SIMULACRON_RULE.cluster().clearLogs();
// since query is unprimed, we use a text value for bind parameter as this is
// what simulacron expects for unprimed statements.
session.execute(prepared.bind("0"));
List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
assertThat(logs).hasSize(1);
QueryLog log = logs.get(0);
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute execute = (Execute) message;
assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.TWO.getProtocolCode());
assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.LOCAL_SERIAL.getProtocolCode());
}
}
use of com.datastax.oss.simulacron.common.cluster.QueryLog in project java-driver by datastax.
the class BoundStatementSimulacronIT method should_use_consistencies.
@Test
public void should_use_consistencies() {
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
// set consistencies on simple statement, but they will be unused since
// overridden by bound statement.
SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
PreparedStatement prepared = session.prepare(st);
SIMULACRON_RULE.cluster().clearLogs();
// since query is unprimed, we use a text value for bind parameter as this is
// what simulacron expects for unprimed statements.
session.execute(prepared.boundStatementBuilder("0").setConsistencyLevel(DefaultConsistencyLevel.THREE).setSerialConsistencyLevel(DefaultConsistencyLevel.SERIAL).build());
List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
assertThat(logs).hasSize(1);
QueryLog log = logs.get(0);
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute execute = (Execute) message;
assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.THREE.getProtocolCode());
assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.SERIAL.getProtocolCode());
}
}
use of com.datastax.oss.simulacron.common.cluster.QueryLog in project java-driver by datastax.
the class DriverExecutionProfileSimulacronIT method should_use_profile_consistency.
@Test
public void should_use_profile_consistency() {
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().startProfile("cl").withString(DefaultDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM").withString(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY, "LOCAL_SERIAL").build();
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE, loader)) {
String query = "mockquery";
// Execute query without profile, should use default CLs (LOCAL_ONE, SERIAL).
session.execute(query);
Optional<QueryLog> log = SIMULACRON_RULE.cluster().getLogs().getQueryLogs().stream().filter(q -> q.getQuery().equals(query)).findFirst();
assertThat(log).isPresent().hasValueSatisfying((l) -> {
assertThat(l.getConsistency().toString()).isEqualTo("LOCAL_ONE");
assertThat(l.getSerialConsistency().toString()).isEqualTo("SERIAL");
});
SIMULACRON_RULE.cluster().clearLogs();
// Execute query with profile, should use profile CLs
session.execute(SimpleStatement.builder(query).setExecutionProfileName("cl").build());
log = SIMULACRON_RULE.cluster().getLogs().getQueryLogs().stream().filter(q -> q.getQuery().equals(query)).findFirst();
assertThat(log).isPresent().hasValueSatisfying((l) -> {
assertThat(l.getConsistency().toString()).isEqualTo("LOCAL_QUORUM");
assertThat(l.getSerialConsistency().toString()).isEqualTo("LOCAL_SERIAL");
});
}
}
use of com.datastax.oss.simulacron.common.cluster.QueryLog in project java-driver by datastax.
the class ProfileIT method assertServerSideCl.
private void assertServerSideCl(ConsistencyLevel expectedCl) {
List<QueryLog> queryLogs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
QueryLog lastLog = queryLogs.get(queryLogs.size() - 1);
Message message = lastLog.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute queryExecute = (Execute) message;
assertThat(queryExecute.options.consistency).isEqualTo(expectedCl.getProtocolCode());
}
use of com.datastax.oss.simulacron.common.cluster.QueryLog in project java-driver by datastax.
the class SimpleStatementSimulacronIT method should_use_consistencies.
@Test
public void should_use_consistencies() {
SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
SESSION_RULE.session().execute(st);
List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
assertThat(logs).hasSize(1);
QueryLog log = logs.get(0);
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Query.class);
Query query = (Query) message;
assertThat(query.options.consistency).isEqualTo(DefaultConsistencyLevel.TWO.getProtocolCode());
assertThat(query.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.LOCAL_SERIAL.getProtocolCode());
}
Aggregations