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());
}
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);
}
}
}
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);
}
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());
}
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();
});
}
Aggregations