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