use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class GraphRequestHandlerTest method should_return_results_for_statements.
@Test
@UseDataProvider("supportedGraphProtocolsWithDseVersions")
public void should_return_results_for_statements(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
PoolBehavior node1Behavior = builder.customBehavior(node);
GraphRequestHandlerTestHarness harness = builder.build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// ideally we would be able to provide a function here to
// produce results instead of a static predefined response.
// Function to which we would pass the harness instance or a (mocked)DriverContext.
// Since that's not possible in the RequestHandlerTestHarness API at the moment, we
// have to use another DseDriverContext and GraphBinaryModule here,
// instead of reusing the one in the harness' DriverContext
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
GraphSupportChecker graphSupportChecker = mock(GraphSupportChecker.class);
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestAsyncProcessor p = Mockito.spy(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker));
when(p.getGraphBinaryModule()).thenReturn(module);
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
GraphResultSet grs = new GraphRequestSyncProcessor(p).process(graphStatement, harness.getSession(), harness.getContext(), "test-graph");
List<GraphNode> nodes = grs.all();
assertThat(nodes.size()).isEqualTo(1);
GraphNode graphNode = nodes.get(0);
assertThat(graphNode.isVertex()).isTrue();
Vertex vRead = graphNode.asVertex();
assertThat(vRead.label()).isEqualTo("person");
assertThat(vRead.id()).isEqualTo(1);
if (!graphProtocol.isGraphBinary()) {
// GraphBinary does not encode properties regardless of whether they are present in the
// parent element or not :/
assertThat(vRead.property("name").id()).isEqualTo(11);
assertThat(vRead.property("name").value()).isEqualTo("marko");
}
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_payload_from_config_options.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_payload_from_config_options(GraphProtocol subProtocol) {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Map<String, ByteBuffer> requestPayload = GraphConversions.createCustomPayload(graphStatement, subProtocol, executionProfile, harness.getContext(), module);
// checks
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_TRAVERSAL_SOURCE, null);
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_NAME, null);
Mockito.verify(executionProfile).getBoolean(DseDriverOption.GRAPH_IS_SYSTEM_QUERY, false);
Mockito.verify(executionProfile).getDuration(DseDriverOption.GRAPH_TIMEOUT, Duration.ZERO);
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_READ_CONSISTENCY_LEVEL, null);
Mockito.verify(executionProfile).getString(DseDriverOption.GRAPH_WRITE_CONSISTENCY_LEVEL, null);
assertThat(requestPayload.get(GraphConversions.GRAPH_SOURCE_OPTION_KEY)).isEqualTo(TEXT.encode("a", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_RESULTS_OPTION_KEY)).isEqualTo(TEXT.encode(subProtocol.toInternalCode(), harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_NAME_OPTION_KEY)).isEqualTo(TEXT.encode("mockGraph", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_LANG_OPTION_KEY)).isEqualTo(TEXT.encode("gremlin-groovy", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_TIMEOUT_OPTION_KEY)).isEqualTo(BIGINT.encode(2L, harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_READ_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("LOCAL_TWO", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_WRITE_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("LOCAL_THREE", harness.getContext().getProtocolVersion()));
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_batch_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_batch_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
@SuppressWarnings("rawtypes") List<GraphTraversal> traversalsTest = ImmutableList.of(// GraphDataTypesTest
DseGraph.g.addV("person").property("p1", 2.3f).property("p2", LocalDateTime.now(ZoneOffset.UTC)), DseGraph.g.addV("software").property("p3", new BigInteger("123456789123456789123456789123456789")).property("p4", ImmutableList.of(Point.fromCoordinates(30.4, 25.63746284))));
GraphStatement<?> graphStatement = BatchGraphStatement.builder().addTraversals(traversalsTest).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(RawBytesQuery.class);
testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_payload_from_statement_options.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_payload_from_statement_options(GraphProtocol subProtocol) {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.builder("mockQuery").setGraphName("mockGraph").setTraversalSource("a").setTimeout(Duration.ofMillis(2)).setReadConsistencyLevel(DefaultConsistencyLevel.TWO).setWriteConsistencyLevel(DefaultConsistencyLevel.THREE).setSystemQuery(false).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Map<String, ByteBuffer> requestPayload = GraphConversions.createCustomPayload(graphStatement, subProtocol, executionProfile, harness.getContext(), module);
// checks
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_TRAVERSAL_SOURCE, null);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_NAME, null);
Mockito.verify(executionProfile, never()).getBoolean(DseDriverOption.GRAPH_IS_SYSTEM_QUERY, false);
Mockito.verify(executionProfile, never()).getDuration(DseDriverOption.GRAPH_TIMEOUT, Duration.ZERO);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_READ_CONSISTENCY_LEVEL, null);
Mockito.verify(executionProfile, never()).getString(DseDriverOption.GRAPH_WRITE_CONSISTENCY_LEVEL, null);
assertThat(requestPayload.get(GraphConversions.GRAPH_SOURCE_OPTION_KEY)).isEqualTo(TEXT.encode("a", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_RESULTS_OPTION_KEY)).isEqualTo(TEXT.encode(subProtocol.toInternalCode(), harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_NAME_OPTION_KEY)).isEqualTo(TEXT.encode("mockGraph", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_LANG_OPTION_KEY)).isEqualTo(TEXT.encode("gremlin-groovy", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_TIMEOUT_OPTION_KEY)).isEqualTo(BIGINT.encode(2L, harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_READ_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("TWO", harness.getContext().getProtocolVersion()));
assertThat(requestPayload.get(GraphConversions.GRAPH_WRITE_CONSISTENCY_LEVEL_OPTION_KEY)).isEqualTo(TEXT.encode("THREE", harness.getContext().getProtocolVersion()));
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class GraphRequestHandlerTest method should_set_correct_query_options_from_graph_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_set_correct_query_options_from_graph_statement(GraphProtocol subProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setQueryParam("name", "value");
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, subProtocol, executionProfile, harness.getContext(), module);
// checks
Query query = ((Query) m);
DseQueryOptions options = ((DseQueryOptions) query.options);
assertThat(options.consistency).isEqualTo(DefaultConsistencyLevel.valueOf(executionProfile.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).getProtocolCode());
// set by the mock timestamp generator
assertThat(options.defaultTimestamp).isEqualTo(-9223372036854775808L);
assertThat(options.positionalValues).isEqualTo(ImmutableList.of(serialize(ImmutableMap.of("name", "value"), subProtocol, module)));
m = GraphConversions.createMessageFromGraphStatement(graphStatement.setTimestamp(2L), subProtocol, executionProfile, harness.getContext(), module);
query = ((Query) m);
options = ((DseQueryOptions) query.options);
assertThat(options.defaultTimestamp).isEqualTo(2L);
}
Aggregations