Search in sources :

Example 1 with QueryLog

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());
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 2 with QueryLog

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());
    }
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 3 with QueryLog

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");
        });
    }
}
Also used : ClusterSpec(com.datastax.oss.simulacron.common.cluster.ClusterSpec) PrimeDsl.serverError(com.datastax.oss.simulacron.common.stubbing.PrimeDsl.serverError) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PrimeDsl.when(com.datastax.oss.simulacron.common.stubbing.PrimeDsl.when) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ParallelizableTests(com.datastax.oss.driver.categories.ParallelizableTests) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) CqlSession(com.datastax.oss.driver.api.core.CqlSession) SimulacronRule(com.datastax.oss.driver.api.testinfra.simulacron.SimulacronRule) Duration(java.time.Duration) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Before(org.junit.Before) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) SessionUtils(com.datastax.oss.driver.api.testinfra.session.SessionUtils) PrimeDsl.noRows(com.datastax.oss.simulacron.common.stubbing.PrimeDsl.noRows) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Optional(java.util.Optional) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 4 with QueryLog

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());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Execute(com.datastax.oss.protocol.internal.request.Execute) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog)

Example 5 with QueryLog

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());
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) Test(org.junit.Test)

Aggregations

QueryLog (com.datastax.oss.simulacron.common.cluster.QueryLog)5 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)4 Message (com.datastax.oss.protocol.internal.Message)4 Test (org.junit.Test)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 Execute (com.datastax.oss.protocol.internal.request.Execute)3 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 ServerError (com.datastax.oss.driver.api.core.servererrors.ServerError)1 SessionUtils (com.datastax.oss.driver.api.testinfra.session.SessionUtils)1 SimulacronRule (com.datastax.oss.driver.api.testinfra.simulacron.SimulacronRule)1 ParallelizableTests (com.datastax.oss.driver.categories.ParallelizableTests)1 Query (com.datastax.oss.protocol.internal.request.Query)1 ClusterSpec (com.datastax.oss.simulacron.common.cluster.ClusterSpec)1 PrimeDsl.noRows (com.datastax.oss.simulacron.common.stubbing.PrimeDsl.noRows)1 PrimeDsl.serverError (com.datastax.oss.simulacron.common.stubbing.PrimeDsl.serverError)1 PrimeDsl.when (com.datastax.oss.simulacron.common.stubbing.PrimeDsl.when)1