use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_use_vertex_id_as_parameter.
/**
* Ensures that a previously returned {@link Vertex}'s {@link Vertex#id()} can be used as an input
* to {@link
* org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource#V(Object...)} to
* retrieve the {@link Vertex} and that the returned {@link Vertex} is the same.
*
* @test_category dse:graph
*/
@Test
public void should_use_vertex_id_as_parameter() {
GraphTraversal<Vertex, Vertex> query = graphTraversalSource().V().hasLabel("person").has("name", "marko");
GraphResultSet resultSet = session().execute(newInstance(query));
List<GraphNode> results = resultSet.all();
assertThat(results.size()).isEqualTo(1);
Vertex marko = results.get(0).asVertex();
if (isGraphBinary()) {
Map<Object, Object> properties = session().execute(newInstance(query.elementMap("name"))).one().asMap();
assertThatContainsProperties(properties, "name", "marko");
} else {
assertThat(marko).hasProperty("name", "marko");
}
resultSet = session().execute(newInstance(graphTraversalSource().V(marko.id())));
results = resultSet.all();
assertThat(results.size()).isEqualTo(1);
Vertex marko2 = results.get(0).asVertex();
// Ensure that the returned vertex is the same as the first.
assertThat(marko2).isEqualTo(marko);
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_resolve_path_without_labels.
/**
* Validates that when traversing a path and labeling none of the elements during the traversal
* that all the labels are empty in the result.
*
* @test_category dse:graph
*/
@Test
public void should_resolve_path_without_labels() {
GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko").outE("knows").inV().outE("created").inV().path()));
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(2);
for (GraphNode result : results) {
Path path = result.asPath();
validatePathObjects(path);
assertThat(path.labels()).hasSize(5);
for (int i = 0; i < 5; i++) assertThat(path).hasNoLabel(i);
}
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_allow_use_of_dsl_graph_binary.
/**
* A simple smoke test to ensure that a user can supply a custom {@link GraphTraversalSource} for
* use with DSLs.
*
* @test_category dse:graph
*/
@Test
public void should_allow_use_of_dsl_graph_binary() throws Exception {
Assumptions.assumeThat(isGraphBinary()).isTrue();
SocialTraversalSource gSocial = socialTraversalSource();
GraphStatement gs = newInstance(gSocial.persons("marko").knows("vadas").elementMap("name", "age"));
GraphResultSet rs = session().execute(gs);
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(1);
assertThatContainsProperties(results.get(0).asMap(), "name", "marko", "age", 29);
Assertions.assertThat(results.get(0).asMap().values()).contains("person");
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalMetaPropertiesIT method should_parse_meta_properties.
/**
* Ensures that a traversal that yields a vertex with a property that has its own properties that
* is appropriately parsed and made accessible via {@link VertexProperty#property(String)}.
*
* @test_category dse:graph
*/
@Test
public void should_parse_meta_properties() {
SESSION_RULE.session().execute(ScriptGraphStatement.newInstance(META_PROPS));
GraphResultSet result = SESSION_RULE.session().execute(newInstance(g.addV("meta_v").property("meta_prop", "hello", "sub_prop", "hi", "sub_prop2", "hi2")));
Vertex v = result.one().asVertex();
assertThat(v).hasProperty("meta_prop");
VertexProperty<String> metaProp = v.property("meta_prop");
assertThat(metaProp).hasValue("hello").hasProperty("sub_prop", "hi").hasProperty("sub_prop2", "hi2");
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphRequestHandlerTest method should_invoke_request_tracker_and_update_metrics.
@Test
@UseDataProvider("dseVersionsWithDefaultGraphProtocol")
public void should_invoke_request_tracker_and_update_metrics(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME)).thenReturn(true);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
PoolBehavior node1Behavior = builder.customBehavior(node);
GraphRequestHandlerTestHarness harness = builder.build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
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);
RequestTracker requestTracker = mock(RequestTracker.class);
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
GraphResultSet grs = new GraphRequestSyncProcessor(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker)).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 actual = graphNode.asVertex();
assertThat(actual.label()).isEqualTo("person");
assertThat(actual.id()).isEqualTo(1);
if (!graphProtocol.isGraphBinary()) {
// GraphBinary does not encode properties regardless of whether they are present in the
// parent element or not :/
assertThat(actual.property("name").id()).isEqualTo(11);
assertThat(actual.property("name").value()).isEqualTo("marko");
}
verify(requestTracker).onSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onNodeSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
verifyNoMoreInteractions(requestTracker);
verify(nodeMetricUpdater1).isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).updateTimer(eq(DseNodeMetric.GRAPH_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
verify(harness.getSession().getMetricUpdater()).isEnabled(DseSessionMetric.GRAPH_REQUESTS, DriverExecutionProfile.DEFAULT_NAME);
verify(harness.getSession().getMetricUpdater()).updateTimer(eq(DseSessionMetric.GRAPH_REQUESTS), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(harness.getSession().getMetricUpdater());
}
Aggregations