public void testRemoveManyEdges() {
    Graph graph = graphTest.getGraphInstance();
    long counter = 200000l;
    int edgeCount = 100;
    Set<Edge> edges = new HashSet<Edge>();
    for (int i = 0; i < edgeCount; i++) {
      Vertex out = graph.addVertex(convertId("" + counter++));
      Vertex in = graph.addVertex(convertId("" + counter++));
      edges.add(graph.addEdge(null, out, in, convertId("a" + UUID.randomUUID().toString())));
    }
    assertEquals(edgeCount, edges.size());

    if (graphTest.supportsVertexIteration) {
      this.stopWatch();
      assertEquals(edgeCount * 2, count(graph.getVertices()));
      BaseTest.printPerformance(
          graph.toString(), edgeCount * 2, "vertices counted", this.stopWatch());
    }

    if (graphTest.supportsEdgeIteration) {
      this.stopWatch();
      assertEquals(edgeCount, count(graph.getEdges()));
      BaseTest.printPerformance(graph.toString(), edgeCount, "edges counted", this.stopWatch());

      int i = edgeCount;
      this.stopWatch();
      for (Edge edge : edges) {
        graph.removeEdge(edge);
        i--;
        assertEquals(i, count(graph.getEdges()));
        if (graphTest.supportsVertexIteration) {
          int x = 0;
          for (Vertex vertex : graph.getVertices()) {
            if (count(vertex.getOutEdges()) > 0) {
              assertEquals(1, count(vertex.getOutEdges()));
              assertFalse(count(vertex.getInEdges()) > 0);
            } else if (count(vertex.getInEdges()) > 0) {
              assertEquals(1, count(vertex.getInEdges()));
              assertFalse(count(vertex.getOutEdges()) > 0);
            } else {
              x++;
            }
          }
          assertEquals((edgeCount - i) * 2, x);
        }
      }
      BaseTest.printPerformance(
          graph.toString(), edgeCount, "edges removed and graph checked", this.stopWatch());
    }
    graph.shutdown();
  }
示例#2
0
  public void testAddManyVertexProperties(final Graph graph) {
    if (!config.isRDFModel) {
      Set<Vertex> vertices = new HashSet<Vertex>();
      this.stopWatch();
      for (int i = 0; i < 50; i++) {
        Vertex vertex = graph.addVertex(null);
        for (int j = 0; j < 15; j++) {
          vertex.setProperty(UUID.randomUUID().toString(), UUID.randomUUID().toString());
        }
        vertices.add(vertex);
      }
      BaseTest.printPerformance(
          graph.toString(),
          15 * 50,
          "vertex properties added (with vertices being added too)",
          this.stopWatch());

      if (config.supportsVertexIteration) assertEquals(50, count(graph.getVertices()));
      assertEquals(50, vertices.size());
      for (Vertex vertex : vertices) {
        assertEquals(15, vertex.getPropertyKeys().size());
      }
    } else {
      Set<Vertex> vertices = new HashSet<Vertex>();
      this.stopWatch();
      for (int i = 0; i < 50; i++) {
        Vertex vertex = graph.addVertex("\"" + UUID.randomUUID().toString() + "\"");
        for (int j = 0; j < 15; j++) {
          vertex.setProperty(SailTokens.DATATYPE, "http://www.w3.org/2001/XMLSchema#anyURI");
        }
        vertices.add(vertex);
      }
      BaseTest.printPerformance(
          graph.toString(),
          15 * 50,
          "vertex properties added (with vertices being added too)",
          this.stopWatch());
      if (config.supportsVertexIteration) assertEquals(count(graph.getVertices()), 50);
      assertEquals(vertices.size(), 50);
      for (Vertex vertex : vertices) {
        assertEquals(2, vertex.getPropertyKeys().size());
        assertTrue(vertex.getPropertyKeys().contains(SailTokens.DATATYPE));
        assertEquals(
            "http://www.w3.org/2001/XMLSchema#anyURI", vertex.getProperty(SailTokens.DATATYPE));
        assertTrue(vertex.getPropertyKeys().contains(SailTokens.VALUE));
      }
    }
  }
  public void testGetEdges() {
    Graph graph = graphTest.getGraphInstance();
    if (!graphTest.isRDFModel) {
      Vertex v1 = graph.addVertex(null);
      Vertex v2 = graph.addVertex(null);
      Vertex v3 = graph.addVertex(null);

      Edge e1 = graph.addEdge(null, v1, v2, "test1");
      Edge e2 = graph.addEdge(null, v2, v3, "test2");
      Edge e3 = graph.addEdge(null, v3, v1, "test3");

      this.stopWatch();
      assertEquals(graph.getEdge(e1.getId()), e1);
      assertEquals(graph.getEdge(e1.getId()).getInVertex(), v2);
      assertEquals(graph.getEdge(e1.getId()).getOutVertex(), v1);

      assertEquals(graph.getEdge(e2.getId()), e2);
      assertEquals(graph.getEdge(e2.getId()).getInVertex(), v3);
      assertEquals(graph.getEdge(e2.getId()).getOutVertex(), v2);

      assertEquals(graph.getEdge(e3.getId()), e3);
      assertEquals(graph.getEdge(e3.getId()).getInVertex(), v1);
      assertEquals(graph.getEdge(e3.getId()).getOutVertex(), v3);

      BaseTest.printPerformance(graph.toString(), 3, "edges retrieved", this.stopWatch());
    }
    graph.shutdown();
  }
示例#4
0
  public void testVertexEquality(final Graph graph) {
    List<String> ids = generateIds(1);

    if (!config.ignoresSuppliedIds) {
      Vertex v = graph.addVertex(convertId(ids.get(0)));
      Vertex u = graph.getVertex(convertId(ids.get(0)));
      assertEquals(v, u);
    }

    this.stopWatch();
    Vertex v = graph.addVertex(null);
    Vertex u = graph.getVertex(v.getId());
    BaseTest.printPerformance(graph.toString(), 1, "vertex added and retrieved", this.stopWatch());

    assertEquals(v, u);
    assertEquals(graph.getVertex(u.getId()), graph.getVertex(u.getId()));
    assertEquals(graph.getVertex(v.getId()), graph.getVertex(u.getId()));
    assertEquals(graph.getVertex(v.getId()), graph.getVertex(v.getId()));

    graph.clear();

    if (!config.ignoresSuppliedIds) {
      v = graph.addVertex(convertId(ids.get(0)));
      u = graph.getVertex(convertId(ids.get(0)));
      Set<Vertex> set = new HashSet<Vertex>();
      set.add(v);
      set.add(v);
      set.add(u);
      set.add(u);
      set.add(graph.getVertex(convertId(ids.get(0))));
      set.add(graph.getVertex(convertId(ids.get(0))));
      if (config.supportsVertexIndex) set.add(graph.getVertices().iterator().next());
      assertEquals(1, set.size());
    }
  }
示例#5
0
 public void testVertexIterator(final Graph graph) {
   int vertexCount = 5000;
   if (config.supportsVertexIteration) {
     this.stopWatch();
     Set ids = new HashSet();
     for (int i = 0; i < vertexCount; i++) {
       ids.add(graph.addVertex(null).getId());
     }
     BaseTest.printPerformance(graph.toString(), vertexCount, "vertices added", this.stopWatch());
     this.stopWatch();
     assertEquals(vertexCount, count(graph.getVertices()));
     BaseTest.printPerformance(
         graph.toString(), vertexCount, "vertices counted", this.stopWatch());
     // must create unique ids
     assertEquals(vertexCount, ids.size());
   }
 }
  public void testReadingTinkerGraph(Graph graph) throws Exception {
    if (!config.ignoresSuppliedIds) {

      this.stopWatch();
      GraphMLReader.inputGraph(
          graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
      BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());

      assertEquals(count(graph.getVertex("1").getOutEdges()), 3);
      assertEquals(count(graph.getVertex("1").getInEdges()), 0);
      Vertex marko = graph.getVertex("1");
      assertEquals(marko.getProperty("name"), "marko");
      assertEquals(marko.getProperty("age"), 29);
      int counter = 0;
      for (Edge e : graph.getVertex("1").getOutEdges()) {
        if (e.getInVertex().getId().equals("2")) {
          // assertEquals(e.getProperty("weight"), 0.5);
          assertEquals(e.getLabel(), "knows");
          assertEquals(e.getId(), "7");
          counter++;
        } else if (e.getInVertex().getId().equals("3")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 0);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "9");
          counter++;
        } else if (e.getInVertex().getId().equals("4")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 1);
          assertEquals(e.getLabel(), "knows");
          assertEquals(e.getId(), "8");
          counter++;
        }
      }

      assertEquals(count(graph.getVertex("4").getOutEdges()), 2);
      assertEquals(count(graph.getVertex("4").getInEdges()), 1);
      Vertex josh = graph.getVertex("4");
      assertEquals(josh.getProperty("name"), "josh");
      assertEquals(josh.getProperty("age"), 32);
      for (Edge e : graph.getVertex("4").getOutEdges()) {
        if (e.getInVertex().getId().equals("3")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 0);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "11");
          counter++;
        } else if (e.getInVertex().getId().equals("5")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 1);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "10");
          counter++;
        }
      }

      assertEquals(counter, 5);
    }
  }
  public void testAddManyEdges() {
    Graph graph = graphTest.getGraphInstance();
    int edgeCount = 1000;
    int vertexCount = 2000;
    long counter = 0l;
    this.stopWatch();
    for (int i = 0; i < edgeCount; i++) {
      Vertex out = graph.addVertex(convertId("" + counter++));
      Vertex in = graph.addVertex(convertId("" + counter++));
      graph.addEdge(null, out, in, convertId(UUID.randomUUID().toString()));
    }
    BaseTest.printPerformance(
        graph.toString(), vertexCount + edgeCount, "elements added", this.stopWatch());
    if (graphTest.supportsEdgeIteration) {
      this.stopWatch();
      assertEquals(edgeCount, count(graph.getEdges()));
      BaseTest.printPerformance(graph.toString(), edgeCount, "edges counted", this.stopWatch());
    }
    if (graphTest.supportsVertexIteration) {
      this.stopWatch();
      assertEquals(vertexCount, count(graph.getVertices()));
      BaseTest.printPerformance(
          graph.toString(), vertexCount, "vertices counted", this.stopWatch());
      this.stopWatch();
      for (Vertex vertex : graph.getVertices()) {
        if (count(vertex.getOutEdges()) > 0) {
          assertEquals(1, count(vertex.getOutEdges()));
          assertFalse(count(vertex.getInEdges()) > 0);

        } else {
          assertEquals(1, count(vertex.getInEdges()));
          assertFalse(count(vertex.getOutEdges()) > 0);
        }
      }
      BaseTest.printPerformance(
          graph.toString(), vertexCount, "vertices checked", this.stopWatch());
    }
    graph.shutdown();
  }
  public void testNeo4jRaw() throws Exception {
    double totalTime = 0.0d;
    Graph graph = graphTest.getGraphInstance();
    GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
    graph.shutdown();

    for (int i = 0; i < TOTAL_RUNS; i++) {
      graph = graphTest.getGraphInstance();
      GraphDatabaseService neo4j = ((Neo4jGraph) graph).getRawGraph();
      int counter = 0;
      this.stopWatch();
      for (final Node node : neo4j.getAllNodes()) {
        counter++;
        for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
          counter++;
          final Node node2 = relationship.getEndNode();
          counter++;
          for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
            counter++;
            final Node node3 = relationship2.getEndNode();
            counter++;
            for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
              counter++;
              relationship3.getEndNode();
              counter++;
            }
          }
        }
      }
      double currentTime = this.stopWatch();
      totalTime = totalTime + currentTime;
      BaseTest.printPerformance(
          neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
      graph.shutdown();
    }
    BaseTest.printPerformance(
        "Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
  }
示例#9
0
  public void testRemoveVertexNullId(final Graph graph) {
    int vertexCount = 1000;
    Vertex v1 = graph.addVertex(null);
    if (config.supportsVertexIteration) assertEquals(1, count(graph.getVertices()));
    graph.removeVertex(v1);
    if (config.supportsVertexIteration) assertEquals(0, count(graph.getVertices()));

    Set<Vertex> vertices = new HashSet<Vertex>();

    this.stopWatch();
    for (int i = 0; i < vertexCount; i++) {
      vertices.add(graph.addVertex(null));
    }
    BaseTest.printPerformance(graph.toString(), vertexCount, "vertices added", this.stopWatch());
    if (config.supportsVertexIteration) assertEquals(vertexCount, count(graph.getVertices()));

    this.stopWatch();
    for (Vertex v : vertices) {
      graph.removeVertex(v);
    }
    BaseTest.printPerformance(graph.toString(), vertexCount, "vertices deleted", this.stopWatch());
    if (config.supportsVertexIteration) assertEquals(0, count(graph.getVertices()));
  }
  public void testNeo4jGraph() throws Exception {
    double totalTime = 0.0d;
    Graph graph = graphTest.getGraphInstance();
    GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
    graph.shutdown();

    for (int i = 0; i < TOTAL_RUNS; i++) {
      graph = graphTest.getGraphInstance();
      this.stopWatch();
      int counter = 0;
      for (final Vertex vertex : graph.getVertices()) {
        counter++;
        for (final Edge edge : vertex.getOutEdges()) {
          counter++;
          final Vertex vertex2 = edge.getInVertex();
          counter++;
          for (final Edge edge2 : vertex2.getOutEdges()) {
            counter++;
            final Vertex vertex3 = edge2.getInVertex();
            counter++;
            for (final Edge edge3 : vertex3.getOutEdges()) {
              counter++;
              edge3.getOutVertex();
              counter++;
            }
          }
        }
      }
      double currentTime = this.stopWatch();
      totalTime = totalTime + currentTime;
      BaseTest.printPerformance(
          graph.toString(), counter, "Neo4jGraph elements touched", currentTime);
      graph.shutdown();
    }
    BaseTest.printPerformance(
        "Neo4jGraph", 1, "Neo4jGraph experiment average", totalTime / (double) TOTAL_RUNS);
  }
示例#11
0
  public void testAddEdges() {
    Graph graph = graphTest.getGraphInstance();
    List<String> ids = generateIds(3);

    this.stopWatch();
    Vertex v1 = graph.addVertex(convertId(ids.get(0)));
    Vertex v2 = graph.addVertex(convertId(ids.get(1)));
    Vertex v3 = graph.addVertex(convertId(ids.get(2)));
    graph.addEdge(null, v1, v2, convertId("knows"));
    graph.addEdge(null, v2, v3, convertId("pets"));
    graph.addEdge(null, v2, v3, convertId("cares_for"));
    assertEquals(1, count(v1.getOutEdges()));
    assertEquals(2, count(v2.getOutEdges()));
    assertEquals(0, count(v3.getOutEdges()));
    assertEquals(0, count(v1.getInEdges()));
    assertEquals(1, count(v2.getInEdges()));
    assertEquals(2, count(v3.getInEdges()));
    BaseTest.printPerformance(graph.toString(), 6, "elements added and checked", this.stopWatch());
    graph.shutdown();
  }
 public void testTinkerGraphSoftwareVertices(Graph graph) throws Exception {
   if (config.supportsVertexIteration) {
     this.stopWatch();
     GraphMLReader.inputGraph(
         graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
     BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
     Set<Vertex> softwareVertices = new HashSet<Vertex>();
     int count = 0;
     for (Vertex v : graph.getVertices()) {
       count++;
       String name = v.getProperty("name").toString();
       if (name.equals("lop") || name.equals("ripple")) {
         softwareVertices.add(v);
       }
     }
     assertEquals(count, 6);
     assertEquals(softwareVertices.size(), 2);
     for (Vertex v : softwareVertices) {
       assertEquals(v.getProperty("lang"), "java");
     }
   }
 }
 public void testTinkerGraphVertices(Graph graph) throws Exception {
   if (config.supportsVertexIteration) {
     this.stopWatch();
     GraphMLReader.inputGraph(
         graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
     BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
     Set<String> vertexNames = new HashSet<String>();
     int count = 0;
     for (Vertex v : graph.getVertices()) {
       count++;
       vertexNames.add(v.getProperty("name").toString());
       // System.out.println(v);
     }
     assertEquals(count, 6);
     assertEquals(vertexNames.size(), 6);
     assertTrue(vertexNames.contains("marko"));
     assertTrue(vertexNames.contains("josh"));
     assertTrue(vertexNames.contains("peter"));
     assertTrue(vertexNames.contains("vadas"));
     assertTrue(vertexNames.contains("ripple"));
     assertTrue(vertexNames.contains("lop"));
   }
 }
 public void testTinkerGraphEdges(Graph graph) throws Exception {
   if (config.supportsEdgeIteration) {
     this.stopWatch();
     GraphMLReader.inputGraph(
         graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
     BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
     Set<String> edgeIds = new HashSet<String>();
     Set<String> edgeKeys = new HashSet<String>();
     Set<String> edgeValues = new HashSet<String>();
     int count = 0;
     for (Edge e : graph.getEdges()) {
       count++;
       edgeIds.add(e.getId().toString());
       for (String key : e.getPropertyKeys()) {
         edgeKeys.add(key);
         edgeValues.add(e.getProperty(key).toString());
       }
     }
     assertEquals(count, 6);
     assertEquals(edgeIds.size(), 6);
     assertEquals(edgeKeys.size(), 1);
     assertEquals(edgeValues.size(), 4);
   }
 }
  public void testTinkerGraphVertexAndEdges(Graph graph) throws Exception {
    if (config.supportsVertexIteration) {
      this.stopWatch();
      GraphMLReader.inputGraph(
          graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
      BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
      Vertex marko = null;
      Vertex peter = null;
      Vertex josh = null;
      Vertex vadas = null;
      Vertex lop = null;
      Vertex ripple = null;
      int count = 0;
      for (Vertex v : graph.getVertices()) {
        count++;
        String name = v.getProperty("name").toString();
        if (name.equals("marko")) {
          marko = v;
        } else if (name.equals("peter")) {
          peter = v;
        } else if (name.equals("josh")) {
          josh = v;
        } else if (name.equals("vadas")) {
          vadas = v;
        } else if (name.equals("lop")) {
          lop = v;
        } else if (name.equals("ripple")) {
          ripple = v;
        } else {
          assertTrue(false);
        }
      }
      assertEquals(count, 6);
      assertTrue(null != marko);
      assertTrue(null != peter);
      assertTrue(null != josh);
      assertTrue(null != vadas);
      assertTrue(null != lop);
      assertTrue(null != ripple);

      // test marko
      Set<Vertex> vertices = new HashSet<Vertex>();
      assertEquals(marko.getProperty("name"), "marko");
      assertEquals(marko.getProperty("age"), 29);
      assertEquals(marko.getPropertyKeys().size(), 2);
      assertEquals(count(marko.getOutEdges()), 3);
      assertEquals(count(marko.getInEdges()), 0);
      for (Edge e : marko.getOutEdges()) {
        vertices.add(e.getInVertex());
      }
      assertEquals(vertices.size(), 3);
      assertTrue(vertices.contains(lop));
      assertTrue(vertices.contains(josh));
      assertTrue(vertices.contains(vadas));
      // test peter
      vertices = new HashSet<Vertex>();
      assertEquals(peter.getProperty("name"), "peter");
      assertEquals(peter.getProperty("age"), 35);
      assertEquals(peter.getPropertyKeys().size(), 2);
      assertEquals(count(peter.getOutEdges()), 1);
      assertEquals(count(peter.getInEdges()), 0);
      for (Edge e : peter.getOutEdges()) {
        vertices.add(e.getInVertex());
      }
      assertEquals(vertices.size(), 1);
      assertTrue(vertices.contains(lop));
      // test josh
      vertices = new HashSet<Vertex>();
      assertEquals(josh.getProperty("name"), "josh");
      assertEquals(josh.getProperty("age"), 32);
      assertEquals(josh.getPropertyKeys().size(), 2);
      assertEquals(count(josh.getOutEdges()), 2);
      assertEquals(count(josh.getInEdges()), 1);
      for (Edge e : josh.getOutEdges()) {
        vertices.add(e.getInVertex());
      }
      assertEquals(vertices.size(), 2);
      assertTrue(vertices.contains(lop));
      assertTrue(vertices.contains(ripple));
      vertices = new HashSet<Vertex>();
      for (Edge e : josh.getInEdges()) {
        vertices.add(e.getOutVertex());
      }
      assertEquals(vertices.size(), 1);
      assertTrue(vertices.contains(marko));
      // test vadas
      vertices = new HashSet<Vertex>();
      assertEquals(vadas.getProperty("name"), "vadas");
      assertEquals(vadas.getProperty("age"), 27);
      assertEquals(vadas.getPropertyKeys().size(), 2);
      assertEquals(count(vadas.getOutEdges()), 0);
      assertEquals(count(vadas.getInEdges()), 1);
      for (Edge e : vadas.getInEdges()) {
        vertices.add(e.getOutVertex());
      }
      assertEquals(vertices.size(), 1);
      assertTrue(vertices.contains(marko));
      // test lop
      vertices = new HashSet<Vertex>();
      assertEquals(lop.getProperty("name"), "lop");
      assertEquals(lop.getProperty("lang"), "java");
      assertEquals(lop.getPropertyKeys().size(), 2);
      assertEquals(count(lop.getOutEdges()), 0);
      assertEquals(count(lop.getInEdges()), 3);
      for (Edge e : lop.getInEdges()) {
        vertices.add(e.getOutVertex());
      }
      assertEquals(vertices.size(), 3);
      assertTrue(vertices.contains(marko));
      assertTrue(vertices.contains(josh));
      assertTrue(vertices.contains(peter));
      // test ripple
      vertices = new HashSet<Vertex>();
      assertEquals(ripple.getProperty("name"), "ripple");
      assertEquals(ripple.getProperty("lang"), "java");
      assertEquals(ripple.getPropertyKeys().size(), 2);
      assertEquals(count(ripple.getOutEdges()), 0);
      assertEquals(count(ripple.getInEdges()), 1);
      for (Edge e : ripple.getInEdges()) {
        vertices.add(e.getOutVertex());
      }
      assertEquals(vertices.size(), 1);
      assertTrue(vertices.contains(josh));
    }
  }