Search in sources :

Example 11 with ExecutionInfo

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

the class AsyncPagingIterableWrapperTest method mockExecutionInfo.

private ExecutionInfo mockExecutionInfo() {
    ExecutionInfo executionInfo = mock(ExecutionInfo.class);
    when(executionInfo.getRequest()).thenAnswer(invocation -> statement);
    return executionInfo;
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo)

Example 12 with ExecutionInfo

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

the class AsyncPagingIterableWrapperTest method should_wrap_result_set.

@Test
public void should_wrap_result_set() throws Exception {
    // Given
    // two pages of data:
    ExecutionInfo executionInfo1 = mockExecutionInfo();
    DefaultAsyncResultSet resultSet1 = new DefaultAsyncResultSet(columnDefinitions, executionInfo1, mockData(0, 5), session, context);
    DefaultAsyncResultSet resultSet2 = new DefaultAsyncResultSet(columnDefinitions, mockExecutionInfo(), mockData(5, 10), session, context);
    // chain them together:
    ByteBuffer mockPagingState = ByteBuffer.allocate(0);
    when(executionInfo1.getPagingState()).thenReturn(mockPagingState);
    Statement<?> mockNextStatement = mock(Statement.class);
    when(((Statement) statement).copy(mockPagingState)).thenReturn(mockNextStatement);
    when(session.executeAsync(mockNextStatement)).thenAnswer(invocation -> CompletableFuture.completedFuture(resultSet2));
    // When
    MappedAsyncPagingIterable<Integer> iterable1 = resultSet1.map(row -> row.getInt("i"));
    // Then
    for (int i = 0; i < 5; i++) {
        assertThat(iterable1.one()).isEqualTo(i);
        assertThat(iterable1.remaining()).isEqualTo(resultSet1.remaining()).isEqualTo(4 - i);
    }
    assertThat(iterable1.hasMorePages()).isTrue();
    MappedAsyncPagingIterable<Integer> iterable2 = iterable1.fetchNextPage().toCompletableFuture().get();
    for (int i = 5; i < 10; i++) {
        assertThat(iterable2.one()).isEqualTo(i);
        assertThat(iterable2.remaining()).isEqualTo(resultSet2.remaining()).isEqualTo(9 - i);
    }
    assertThat(iterable2.hasMorePages()).isFalse();
}
Also used : DefaultAsyncResultSet(com.datastax.oss.driver.internal.core.cql.DefaultAsyncResultSet) Statement(com.datastax.oss.driver.api.core.cql.Statement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 13 with ExecutionInfo

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

the class GraphExecutionInfoConverterTest method should_convert_from_graph_execution_info.

@Test
public void should_convert_from_graph_execution_info() {
    // given
    com.datastax.dse.driver.api.core.graph.GraphExecutionInfo graphExecutionInfo = mock(com.datastax.dse.driver.api.core.graph.GraphExecutionInfo.class);
    when(graphExecutionInfo.getStatement()).thenAnswer(args -> request);
    when(graphExecutionInfo.getCoordinator()).thenReturn(node);
    when(graphExecutionInfo.getSpeculativeExecutionCount()).thenReturn(42);
    when(graphExecutionInfo.getSuccessfulExecutionIndex()).thenReturn(10);
    when(graphExecutionInfo.getErrors()).thenReturn(errors);
    when(graphExecutionInfo.getWarnings()).thenReturn(warnings);
    when(graphExecutionInfo.getIncomingPayload()).thenReturn(payload);
    // when
    ExecutionInfo executionInfo = GraphExecutionInfoConverter.convert(graphExecutionInfo);
    // then
    assertThat(executionInfo.getRequest()).isSameAs(request);
    assertThatThrownBy(executionInfo::getStatement).isInstanceOf(ClassCastException.class);
    assertThat(executionInfo.getCoordinator()).isSameAs(node);
    assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(42);
    assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(10);
    assertThat(executionInfo.getErrors()).isEqualTo(errors);
    assertThat(executionInfo.getWarnings()).isEqualTo(warnings);
    assertThat(executionInfo.getIncomingPayload()).isEqualTo(payload);
    assertThat(executionInfo.getPagingState()).isNull();
    assertThat(executionInfo.isSchemaInAgreement()).isTrue();
    assertThat(executionInfo.getQueryTraceAsync()).isCompletedExceptionally();
    assertThatThrownBy(executionInfo::getQueryTrace).isInstanceOf(IllegalStateException.class).hasMessage("Tracing was disabled for this request");
    assertThat(executionInfo.getResponseSizeInBytes()).isEqualTo(-1L);
    assertThat(executionInfo.getCompressedResponseSizeInBytes()).isEqualTo(-1L);
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Test(org.junit.Test)

Example 14 with ExecutionInfo

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

the class ReactiveGraphRequestProcessorTest method should_complete_single_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
    when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
    when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
    GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (GraphRequestHandlerTestHarness harness = builder.build()) {
        DefaultSession session = harness.getSession();
        DefaultDriverContext context = harness.getContext();
        GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
        GraphBinaryModule graphBinaryModule = createGraphBinaryModule(context);
        when(asyncProcessor.getGraphBinaryModule()).thenReturn(graphBinaryModule);
        ReactiveGraphResultSet publisher = new ReactiveGraphRequestProcessor(asyncProcessor).process(graphStatement, session, context, "test");
        Flowable<ReactiveGraphNode> rowsPublisher = Flowable.fromPublisher(publisher).cache();
        rowsPublisher.subscribe();
        // emulate single page
        node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, true)));
        List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
        assertThat(rows).hasSize(10);
        checkResultSet(rows);
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).hasSize(1).containsExactly(rows.get(0).getExecutionInfo());
    }
}
Also used : GraphRequestHandlerTestHarness(com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) ReactiveGraphResultSet(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with ExecutionInfo

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

the class ContinuousCqlRequestReactiveProcessorTest method should_complete_single_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).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 : ContinuousCqlRequestAsyncProcessor(com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor) 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) ContinuousReactiveResultSet(com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet) 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)

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