Search in sources :

Example 56 with ExecutionInfo

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());
    }
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 57 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 58 with ExecutionInfo

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();
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) QueryTrace(com.datastax.oss.driver.api.core.cql.QueryTrace) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 59 with ExecutionInfo

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!");
}
Also used : ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) HealthCheck(org.eclipse.microprofile.health.HealthCheck) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 60 with ExecutionInfo

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]...)"));
}
Also used : SyntaxError(com.datastax.oss.driver.api.core.servererrors.SyntaxError) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)64 Test (org.junit.Test)36 Row (com.datastax.oss.driver.api.core.cql.Row)23 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)17 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)9 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)8 CqlSession (com.datastax.oss.driver.api.core.CqlSession)7 Test (org.junit.jupiter.api.Test)7 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 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)5 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4