Search in sources :

Example 46 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class ExecutionInfoWarningsIT method should_execute_query_and_not_log_server_side_warnings.

@Test
@CassandraRequirement(min = "3.0")
public void should_execute_query_and_not_log_server_side_warnings() {
    final String query = "SELECT count(*) FROM test;";
    Statement<?> st = SimpleStatement.builder(query).setExecutionProfileName("log-disabled").build();
    ResultSet result = sessionRule.session().execute(st);
    ExecutionInfo executionInfo = result.getExecutionInfo();
    assertThat(executionInfo).isNotNull();
    List<String> warnings = executionInfo.getWarnings();
    assertThat(warnings).isNotEmpty();
    String warning = warnings.get(0);
    assertThat(warning).isEqualTo("Aggregation query used without partition key");
    // verify the log was NOT generated
    verify(appender, timeout(500).times(0)).doAppend(loggingEventCaptor.capture());
}
Also used : ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 47 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class HeapCompressionIT method createAndCheckCluster.

private void createAndCheckCluster(String compressorOption) {
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_COMPRESSION, compressorOption).build();
    try (CqlSession session = SessionUtils.newSession(CCM_RULE, SCHEMA_SESSION_RULE.keyspace(), loader)) {
        // Run a couple of simple test queries
        ResultSet rs = session.execute(SimpleStatement.newInstance("INSERT INTO test (k, t, i, f) VALUES (?, ?, ?, ?)", "key", "foo", 42, 24.03f));
        assertThat(rs.iterator().hasNext()).isFalse();
        ResultSet rs1 = session.execute("SELECT * FROM test WHERE k = 'key'");
        assertThat(rs1.iterator().hasNext()).isTrue();
        Row row = rs1.iterator().next();
        assertThat(rs1.iterator().hasNext()).isFalse();
        assertThat(row.getString("k")).isEqualTo("key");
        assertThat(row.getString("t")).isEqualTo("foo");
        assertThat(row.getInt("i")).isEqualTo(42);
        assertThat(row.getFloat("f")).isEqualTo(24.03f, offset(0.1f));
        ExecutionInfo executionInfo = rs.getExecutionInfo();
        // There's not much more we can check without hard-coding sizes.
        // We are testing with small responses, so the compressed payload is not even guaranteed to be
        // smaller.
        assertThat(executionInfo.getResponseSizeInBytes()).isGreaterThan(0);
        if (session.getContext().getProtocolVersion().getCode() == 5) {
            // in protocol v5, compression is done at segment level
            assertThat(executionInfo.getCompressedResponseSizeInBytes()).isEqualTo(-1);
        } else {
            assertThat(executionInfo.getCompressedResponseSizeInBytes()).isGreaterThan(0);
        }
    }
}
Also used : ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Row(com.datastax.oss.driver.api.core.cql.Row) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 48 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class DefaultReactiveResultSetIT method should_write.

@Test
public void should_write() {
    SimpleStatement statement = SimpleStatement.builder("INSERT INTO test_reactive_write (pk, cc, v) VALUES (?, ?, ?)").addPositionalValue(0).addPositionalValue(1).addPositionalValue(2).setExecutionProfile(sessionRule.slowProfile()).build();
    ReactiveResultSet rs = sessionRule.session().executeReactive(statement);
    List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).isEmpty();
    List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1);
    List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(EmptyColumnDefinitions.INSTANCE);
    List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(true);
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) EmptyColumnDefinitions(com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) Test(org.junit.Test)

Example 49 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class DefaultReactiveResultSetIT method should_write_batch_cas.

@Test
public void should_write_batch_cas() {
    BatchStatement batch = createCASBatch();
    CqlSession session = sessionRule.session();
    // execute batch for the first time: all inserts should succeed and the server should return
    // only one acknowledgement row with just the [applied] column = true
    ReactiveResultSet rs = session.executeReactive(batch);
    List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).hasSize(1);
    ReactiveRow row = results.get(0);
    assertThat(row.getExecutionInfo()).isNotNull();
    assertThat(row.getColumnDefinitions()).hasSize(1);
    assertThat(row.wasApplied()).isTrue();
    assertThat(row.getBoolean("[applied]")).isTrue();
    List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
    List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
    List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
    // delete 5 out of 10 rows
    partiallyDeleteInsertedRows();
    // re-execute same statement: server should return 5 rows for the 5 failed inserts, each one
    // with [applied] = false
    rs = session.executeReactive(batch);
    results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).hasSize(5);
    for (int i = 0; i < 5; i++) {
        row = results.get(i);
        assertThat(row.getExecutionInfo()).isNotNull();
        assertThat(row.getColumnDefinitions()).hasSize(4);
        assertThat(row.wasApplied()).isFalse();
        assertThat(row.getBoolean("[applied]")).isFalse();
        assertThat(row.getInt("pk")).isEqualTo(0);
        assertThat(row.getInt("cc")).isEqualTo(i);
        assertThat(row.getInt("v")).isEqualTo(i + 1);
    }
    execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
    assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
    colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
    assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
    wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
    assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) EmptyColumnDefinitions(com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions) BatchStatement(com.datastax.oss.driver.api.core.cql.BatchStatement) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 50 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class ExceptionIT method should_expose_execution_info_on_exceptions.

@Test
public void should_expose_execution_info_on_exceptions() {
    // Given
    SIMULACRON_RULE.cluster().node(0).prime(when(QUERY_STRING).then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ONE, 1, 0)));
    SIMULACRON_RULE.cluster().node(1).prime(when(QUERY_STRING).then(PrimeDsl.invalid("Mock error message")));
    // Then
    assertThatThrownBy(() -> SESSION_RULE.session().execute(QUERY_STRING)).isInstanceOf(InvalidQueryException.class).satisfies(exception -> {
        ExecutionInfo info = ((InvalidQueryException) exception).getExecutionInfo();
        assertThat(info).isNotNull();
        assertThat(info.getCoordinator().getEndPoint().resolve()).isEqualTo(SIMULACRON_RULE.cluster().node(1).inetSocketAddress());
        assertThat(((SimpleStatement) info.getRequest()).getQuery()).isEqualTo(QUERY_STRING);
        // specex disabled => the initial execution completed the response
        assertThat(info.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(info.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(info.getTracingId()).isNull();
        assertThat(info.getPagingState()).isNull();
        assertThat(info.getIncomingPayload()).isEmpty();
        assertThat(info.getWarnings()).isEmpty();
        assertThat(info.isSchemaInAgreement()).isTrue();
        assertThat(info.getResponseSizeInBytes()).isEqualTo(info.getCompressedResponseSizeInBytes()).isEqualTo(-1);
        List<Map.Entry<Node, Throwable>> errors = info.getErrors();
        assertThat(errors).hasSize(1);
        Map.Entry<Node, Throwable> entry0 = errors.get(0);
        assertThat(entry0.getKey().getEndPoint().resolve()).isEqualTo(SIMULACRON_RULE.cluster().node(0).inetSocketAddress());
        Throwable node0Exception = entry0.getValue();
        assertThat(node0Exception).isInstanceOf(UnavailableException.class);
        // ExecutionInfo is not exposed for retried errors
        assertThat(((UnavailableException) node0Exception).getExecutionInfo()).isNull();
    });
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Node(com.datastax.oss.driver.api.core.metadata.Node) UnavailableException(com.datastax.oss.driver.api.core.servererrors.UnavailableException) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Map(java.util.Map) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) Test(org.junit.Test)

Aggregations

ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)50 Test (org.junit.Test)36 Row (com.datastax.oss.driver.api.core.cql.Row)20 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)13 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)13 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)12 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)12 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)8 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)6 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)6 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)5 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)5 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)5 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 EmptyColumnDefinitions (com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions)4