use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestReactiveProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseAndOssProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(ProtocolVersion version) {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(singleDseRow())).build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ReactiveResultSet publisher = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
List<ReactiveRow> rows = Flowable.fromPublisher(publisher).toList().blockingGet();
assertThat(rows).hasSize(1);
ReactiveRow row = rows.get(0);
assertThat(row.getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = row.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(executionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(row.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(row.wasApplied());
}
}
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 stargate by stargate.
the class BoundStatementTest method tracingTest.
@Test
@DisplayName("Should execute statement with tracing and retrieve trace")
public void tracingTest(CqlSession session, StargateEnvironmentInfo stargate) {
PreparedStatement prepared = session.prepare("SELECT v FROM test WHERE k=?");
BoundStatement statement = prepared.bind(KEY);
ExecutionInfo executionInfo = session.execute(statement).getExecutionInfo();
assertThat(executionInfo.getTracingId()).isNull();
executionInfo = session.execute(statement.setTracing(true)).getExecutionInfo();
assertThat(executionInfo.getTracingId()).isNotNull();
QueryTrace queryTrace = executionInfo.getQueryTrace();
assertThat(queryTrace).isNotNull();
assertThat(stargate.nodes()).extracting(StargateConnectionInfo::seedAddress).contains(queryTrace.getCoordinatorAddress().getAddress().getHostAddress());
assertThat(queryTrace.getRequestType()).isEqualTo("Execute CQL3 prepared query");
assertThat(queryTrace.getEvents()).isNotEmpty();
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project trellis-extensions by trellis-ldp.
the class CassandraLivenessCheckTest method testHealthy.
@Test
void testHealthy() {
final CqlSession mockSession = mock(CqlSession.class);
final ResultSet mockResultSet = mock(ResultSet.class);
final ExecutionInfo mockExecutionInfo = mock(ExecutionInfo.class);
when(mockSession.execute(anyString())).thenReturn(mockResultSet);
when(mockResultSet.getExecutionInfo()).thenReturn(mockExecutionInfo);
when(mockExecutionInfo.getErrors()).thenReturn(emptyList());
final HealthCheck check = new CassandraLivenessCheck(mockSession);
assertEquals(HealthCheckResponse.Status.UP, check.call().getStatus(), "Connection isn't healthy!");
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project dsbulk by datastax.
the class NonContinuousBulkExecutorTestBase method setUpSession.
@BeforeEach
void setUpSession() {
when(session.executeAsync(any(SimpleStatement.class))).thenAnswer(invocation -> {
SimpleStatement stmt = (SimpleStatement) invocation.getArguments()[0];
switch(stmt.getQuery()) {
case "read should succeed 1":
return futureReadSuccess1a;
case "read should succeed 2":
return futureReadSuccess2a;
case "write should succeed 1":
return futureWriteSuccess1;
case "write should succeed 2":
return futureWriteSuccess2;
case "should fail":
default:
return failedFuture;
}
});
// read request 1a
futureReadSuccess1a.complete(successfulReadResultSet1a);
when(successfulReadResultSet1a.currentPage()).thenReturn(page1a);
when(successfulReadResultSet1a.hasMorePages()).thenReturn(true);
ExecutionInfo executionInfo1a = mock(ExecutionInfo.class);
when(successfulReadResultSet1a.getExecutionInfo()).thenReturn(executionInfo1a);
when(executionInfo1a.getPagingState()).thenReturn(pagingState);
when(successfulReadResultSet1a.fetchNextPage()).thenReturn(futureReadSuccess1b);
// read request 1b
futureReadSuccess1b.complete(successfulReadResultSet1b);
when(successfulReadResultSet1b.currentPage()).thenReturn(page1b);
when(successfulReadResultSet1b.hasMorePages()).thenReturn(false);
ExecutionInfo executionInfo1b = mock(ExecutionInfo.class);
when(successfulReadResultSet1b.getExecutionInfo()).thenReturn(executionInfo1b);
when(executionInfo1b.getPagingState()).thenReturn(null);
// read request 2a
futureReadSuccess2a.complete(successfulReadResultSet2a);
when(successfulReadResultSet2a.currentPage()).thenReturn(page2a);
when(successfulReadResultSet2a.hasMorePages()).thenReturn(false);
ExecutionInfo executionInfo2a = mock(ExecutionInfo.class);
when(successfulReadResultSet2a.getExecutionInfo()).thenReturn(executionInfo2a);
when(executionInfo2a.getPagingState()).thenReturn(null);
// write request 1
futureWriteSuccess1.complete(successfulWriteResultSet1);
when(successfulWriteResultSet1.currentPage()).thenReturn(Collections.emptyList());
when(successfulWriteResultSet1.hasMorePages()).thenReturn(false);
when(successfulWriteResultSet1.getExecutionInfo()).thenReturn(executionInfo1a);
when(executionInfo1a.getPagingState()).thenReturn(null);
// write request 2
futureWriteSuccess2.complete(successfulWriteResultSet2);
when(successfulWriteResultSet2.currentPage()).thenReturn(Collections.emptyList());
when(successfulWriteResultSet2.hasMorePages()).thenReturn(false);
when(successfulWriteResultSet2.getExecutionInfo()).thenReturn(executionInfo2a);
when(executionInfo2a.getPagingState()).thenReturn(null);
// failed request
failedFuture.completeExceptionally(new SyntaxError(mock(Node.class), "line 1:0 no viable alternative at input 'should' ([should]...)"));
}
Aggregations