Search in sources :

Example 1 with ReactiveGraphNode

use of com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode 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 2 with ReactiveGraphNode

use of com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode in project java-driver by datastax.

the class ReactiveGraphResultSetSubscription method toPage.

/**
 * Converts the received result object into a {@link Page}.
 *
 * @param rs the result object to convert.
 * @return a new page.
 */
@NonNull
private Page toPage(@NonNull AsyncGraphResultSet rs) {
    ExecutionInfo executionInfo = rs.getRequestExecutionInfo();
    Iterator<ReactiveGraphNode> results = Iterators.transform(rs.currentPage().iterator(), row -> new DefaultReactiveGraphNode(Objects.requireNonNull(row), executionInfo));
    return new Page(results, rs.hasMorePages() ? rs::fetchNextPage : null);
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 3 with ReactiveGraphNode

use of com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode in project java-driver by datastax.

the class ReactiveGraphRequestProcessorTest method should_complete_multi_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
    when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(true);
    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 page 1
        node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, false)));
        // emulate page 2
        node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 2, true)));
        List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
        assertThat(rows).hasSize(20);
        checkResultSet(rows);
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).hasSize(2).containsExactly(rows.get(0).getExecutionInfo(), rows.get(10).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 4 with ReactiveGraphNode

use of com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode in project java-driver by datastax.

the class ReactiveGraphRequestProcessorTest method checkResultSet.

private void checkResultSet(List<ReactiveGraphNode> rows) {
    for (ReactiveGraphNode row : rows) {
        assertThat(row.isVertex()).isTrue();
        ExecutionInfo executionInfo = row.getExecutionInfo();
        assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(executionInfo.getErrors()).isEmpty();
        assertThat(executionInfo.getIncomingPayload()).isEmpty();
        assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(executionInfo.getWarnings()).isEmpty();
    }
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)

Aggregations

ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)4 ReactiveGraphResultSet (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet)2 GraphRequestHandlerTestHarness (com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness)2 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 DefaultDriverContext (com.datastax.oss.driver.internal.core.context.DefaultDriverContext)2 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)2 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Test (org.junit.Test)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1