use of com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method should_create_reactive_result_set.
@Test
public void should_create_reactive_result_set() {
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(DSE_V1);
try (GraphRequestHandlerTestHarness harness = builder.build()) {
ReactiveGraphRequestProcessor processor = new ReactiveGraphRequestProcessor(asyncProcessor);
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
assertThat(processor.process(graphStatement, harness.getSession(), harness.getContext(), "test")).isInstanceOf(DefaultReactiveGraphResultSet.class);
}
}
use of com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness 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.internal.core.graph.GraphRequestHandlerTestHarness 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());
}
}
Aggregations