Search in sources :

Example 6 with GraphBinaryModule

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");
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 7 with GraphBinaryModule

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()));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 8 with GraphBinaryModule

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);
}
Also used : RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) Message(com.datastax.oss.protocol.internal.Message) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BigInteger(java.math.BigInteger) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 9 with GraphBinaryModule

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()));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 10 with GraphBinaryModule

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);
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DseQueryOptions(com.datastax.dse.protocol.internal.request.query.DseQueryOptions) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)24 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)23 Test (org.junit.Test)23 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)20 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)14 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)11 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)9 SpeculativeExecutionPolicy (com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy)8 CapturedTimeout (com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout)8 Node (com.datastax.oss.driver.api.core.metadata.Node)7 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)7 RawBytesQuery (com.datastax.dse.protocol.internal.request.RawBytesQuery)5 Message (com.datastax.oss.protocol.internal.Message)5 ByteBuffer (java.nio.ByteBuffer)5 Error (com.datastax.oss.protocol.internal.response.Error)4 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)3 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 DefaultDriverContext (com.datastax.oss.driver.internal.core.context.DefaultDriverContext)3 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)3 Query (com.datastax.oss.protocol.internal.request.Query)3