@Test
  public void vertexIndexLookupWithValue() {
    OrientGraph graph = newGraph();
    createVertexIndexLabel1(graph);
    String value = "value1";

    // verify index created
    Assert.assertEquals(
        graph.getIndexedKeys(Vertex.class, label1), new HashSet<>(Collections.singletonList(key)));
    Assert.assertEquals(
        graph.getIndexedKeys(Vertex.class, label2), new HashSet<>(Collections.emptyList()));
    Assert.assertEquals(
        graph.getIndexedKeys(Edge.class, label1), new HashSet<>(Collections.emptyList()));

    Vertex v1 = graph.addVertex(T.label, label1, key, value);
    Vertex v2 = graph.addVertex(T.label, label2, key, value);

    // looking deep into the internals here - I can't find a nicer way to
    // auto verify that an index is actually used
    GraphTraversal<Vertex, Vertex> traversal =
        graph.traversal().V().has(T.label, P.eq(label1)).has(key, P.eq(value));
    OrientGraphStepStrategy.instance().apply(traversal.asAdmin());

    OrientGraphStep orientGraphStep = (OrientGraphStep) traversal.asAdmin().getStartStep();
    OrientIndexQuery orientIndexQuery = (OrientIndexQuery) orientGraphStep.findIndex().get();

    OIndex index = orientIndexQuery.index;
    Assert.assertEquals(1, index.getSize());
    Assert.assertEquals(v1.id(), index.get(value));
  }
Beispiel #2
0
  //    @Test
  public void testLoadSchemaRemembersUncommittedSchemas() throws Exception {

    // Create a new sqlgGraph
    SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration);
    // Not entirely sure what this is for, else it seems hazelcast has not yet distributed the map
    Thread.sleep(1000);
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "a");
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "b");
    v1.addEdge("friend", v2);
    this.sqlgGraph.tx().commit();

    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Animal", "name", "b");
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Car", "name", "b");
    Assert.assertEquals(
        1, this.sqlgGraph.traversal().E().has(T.label, "friend").count().next().intValue());
    this.sqlgGraph.tx().commit();

    Assert.assertEquals(1, sqlgGraph1.traversal().E().count().next().intValue());
    Assert.assertEquals(
        1, sqlgGraph1.traversal().E().has(T.label, "friend").count().next().intValue());
    Assert.assertEquals(
        2, sqlgGraph1.traversal().V().has(T.label, "Person").count().next().intValue());

    sqlgGraph1.tx().rollback();
    sqlgGraph1.close();
  }
 @Override
 public void map(final Vertex vertex, final MapEmitter<Object, Double> emitter) {
   final Property pageRank = vertex.property(PageRankVertexProgram.PAGE_RANK);
   if (pageRank.isPresent()) {
     emitter.emit(vertex.id(), (Double) pageRank.value());
   }
 }
 @Override
 public void activate(final Collection<TinkerGraphPosLengthMatch> matches) {
   for (final TinkerGraphPosLengthMatch plm : matches) {
     final Vertex segment = plm.getSegment();
     final Integer length = plm.getLength();
     segment.property(LENGTH, -length + 1);
   }
 }
Beispiel #5
0
  //    @Test
  public void testLazyLoadTableViaEdgesHas() throws Exception {
    // Create a new sqlgGraph
    SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration);
    // Not entirely sure what this is for, else it seems hazelcast has not yet distributed the map
    Thread.sleep(1000);
    // add a vertex in the old, the new should only see it after a commit
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "a");
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "b");
    v1.addEdge("friend", v2);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(
        1, this.sqlgGraph.traversal().E().has(T.label, "friend").count().next().intValue());

    Assert.assertEquals(1, sqlgGraph1.traversal().E().count().next().intValue());
    Assert.assertEquals(
        1, sqlgGraph1.traversal().E().has(T.label, "friend").count().next().intValue());
    Assert.assertEquals(
        2, sqlgGraph1.traversal().V().has(T.label, "Person").count().next().intValue());
    sqlgGraph1.tx().rollback();
    sqlgGraph1.close();
  }
  @Test
  public void testGraphVHas() {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");

    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
    Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
    Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
    Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "name", "b4");

    a1.addEdge("b", b1);
    a1.addEdge("b", b2);
    a1.addEdge("b", b3);
    a1.addEdge("b", b4);

    a2.addEdge("b", b1);
    a2.addEdge("b", b2);
    a2.addEdge("b", b3);
    a2.addEdge("b", b4);

    this.sqlgGraph.tx().commit();

    List<Vertex> bs = this.sqlgGraph.traversal().V().has(T.label, "A").out("b").toList();
    Assert.assertEquals(8, bs.size());
  }
Beispiel #7
0
  //    @Test
  public void testLazyLoadTableViaVertexHasWithKeyMissingColumn() throws Exception {
    // Create a new sqlgGraph
    SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration);
    // Not entirely sure what this is for, else it seems hazelcast has not yet distributed the map
    Thread.sleep(1000);
    // add a vertex in the old, the new should only see it after a commit
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "a");
    this.sqlgGraph.tx().commit();
    Assert.assertEquals(1, sqlgGraph1.traversal().V().count().next().intValue());
    Assert.assertEquals(
        1,
        sqlgGraph1
            .traversal()
            .V()
            .has(T.label, "Person")
            .has("name", "a")
            .count()
            .next()
            .intValue());
    Vertex v11 = sqlgGraph1.traversal().V().has(T.label, "Person").<Vertex>has("name", "a").next();
    Assert.assertFalse(v11.property("surname").isPresent());
    // the next alter will lock if this transaction is still active
    sqlgGraph1.tx().rollback();

    // add column in one
    v1.property("surname", "bbb");
    this.sqlgGraph.tx().commit();

    Vertex v12 = sqlgGraph1.addVertex(T.label, "Person", "surname", "ccc");
    Assert.assertEquals("ccc", v12.value("surname"));
    sqlgGraph1.tx().rollback();
    sqlgGraph1.close();
  }
Beispiel #8
0
  // Fails via maven for Hsqldb
  //    @Test
  public void testLazyLoadTableViaEdgeCreation() throws Exception {
    // Create a new sqlgGraph
    SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration);
    Thread.sleep(1000);
    // add a vertex in the old, the new should only see it after a commit
    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "a");
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "b");
    this.sqlgGraph.tx().commit();
    Vertex v11 = sqlgGraph1.addVertex(T.label, "Person", "surname", "ccc");
    Vertex v12 = sqlgGraph1.addVertex(T.label, "Person", "surname", "ccc");
    sqlgGraph1.tx().commit();

    v1.addEdge("friend", v2);
    this.sqlgGraph.tx().commit();

    v11.addEdge("friend", v12);
    sqlgGraph1.tx().commit();

    Assert.assertEquals(1, vertexTraversal(v11).out("friend").count().next().intValue());
    sqlgGraph1.tx().rollback();
    sqlgGraph1.close();
  }
  public static void validateVertexEquality(
      final Vertex originalVertex, final Vertex otherVertex, boolean testEdges) {
    assertEquals(originalVertex, otherVertex);
    assertEquals(otherVertex, originalVertex);
    assertEquals(originalVertex.id(), otherVertex.id());
    assertEquals(originalVertex.label(), otherVertex.label());
    assertEquals(originalVertex.keys().size(), otherVertex.keys().size());
    for (final String key : originalVertex.keys()) {
      final List<VertexProperty<Object>> originalVertexProperties =
          IteratorUtils.list(originalVertex.properties(key));
      final List<VertexProperty<Object>> otherVertexProperties =
          IteratorUtils.list(otherVertex.properties(key));
      assertEquals(originalVertexProperties.size(), otherVertexProperties.size());
      for (VertexProperty<Object> originalVertexProperty : originalVertexProperties) {
        final VertexProperty<Object> otherVertexProperty =
            otherVertexProperties
                .parallelStream()
                .filter(vp -> vp.equals(originalVertexProperty))
                .findAny()
                .get();
        validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty);
      }
    }
    if (testEdges) {
      Iterator<Edge> originalEdges =
          IteratorUtils.list(originalVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR)
              .iterator();
      Iterator<Edge> otherEdges =
          IteratorUtils.list(otherVertex.edges(Direction.OUT), Comparators.ELEMENT_COMPARATOR)
              .iterator();
      while (originalEdges.hasNext()) {
        validateEdgeEquality(originalEdges.next(), otherEdges.next());
      }
      assertFalse(otherEdges.hasNext());

      originalEdges =
          IteratorUtils.list(originalVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR)
              .iterator();
      otherEdges =
          IteratorUtils.list(otherVertex.edges(Direction.IN), Comparators.ELEMENT_COMPARATOR)
              .iterator();
      while (originalEdges.hasNext()) {
        validateEdgeEquality(originalEdges.next(), otherEdges.next());
      }
      assertFalse(otherEdges.hasNext());
    }
  }