コード例 #1
0
  public void testAddingRemovingEdgeProperties() {
    Graph graph = graphTest.generateGraph();
    if (graph.getFeatures().supportsEdgeProperties) {
      Vertex a = graph.addVertex(convertId(graph, "1"));
      Vertex b = graph.addVertex(convertId(graph, "2"));
      Edge edge = graph.addEdge(convertId(graph, "3"), a, b, "knows");
      assertEquals(edge.getPropertyKeys().size(), 0);
      assertNull(edge.getProperty("weight"));

      if (graph.getFeatures().supportsDoubleProperty) {
        edge.setProperty("weight", 0.5);
        assertEquals(edge.getPropertyKeys().size(), 1);
        assertEquals(edge.getProperty("weight"), 0.5);

        edge.setProperty("weight", 0.6);
        assertEquals(edge.getPropertyKeys().size(), 1);
        assertEquals(edge.getProperty("weight"), 0.6);
        assertEquals(edge.removeProperty("weight"), 0.6);
        assertNull(edge.getProperty("weight"));
        assertEquals(edge.getPropertyKeys().size(), 0);
      }

      if (graph.getFeatures().supportsStringProperty) {
        edge.setProperty("blah", "marko");
        edge.setProperty("blah2", "josh");
        assertEquals(edge.getPropertyKeys().size(), 2);
      }
    }
    graph.shutdown();
  }
コード例 #2
0
  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);
    }
  }
コード例 #3
0
  public void testAddingRemovingEdgeProperties() {
    if (!graphTest.isRDFModel) {
      Graph graph = graphTest.getGraphInstance();
      Vertex a = graph.addVertex(convertId("1"));
      Vertex b = graph.addVertex(convertId("2"));
      Edge edge = graph.addEdge(convertId("3"), a, b, "knows");
      assertEquals(edge.getPropertyKeys().size(), 0);
      assertNull(edge.getProperty("weight"));
      edge.setProperty("weight", 0.5);
      assertEquals(edge.getPropertyKeys().size(), 1);
      assertEquals(edge.getProperty("weight"), 0.5);

      edge.setProperty("weight", 0.6);
      assertEquals(edge.getPropertyKeys().size(), 1);
      assertEquals(edge.getProperty("weight"), 0.6);
      assertEquals(edge.removeProperty("weight"), 0.6);
      assertNull(edge.getProperty("weight"));
      assertEquals(edge.getPropertyKeys().size(), 0);
      edge.setProperty("blah", "marko");
      edge.setProperty("blah2", "josh");
      assertEquals(edge.getPropertyKeys().size(), 2);
    }
  }
コード例 #4
0
  public void testGraphDataPersists() {
    Graph graph = graphTest.generateGraph();
    if (graph.getFeatures().isPersistent) {

      Vertex v = graph.addVertex(null);
      Vertex u = graph.addVertex(null);
      if (graph.getFeatures().supportsVertexProperties) {
        v.setProperty("name", "marko");
        u.setProperty("name", "pavel");
      }
      Edge e = graph.addEdge(null, v, u, convertId(graph, "collaborator"));
      if (graph.getFeatures().supportsEdgeProperties) e.setProperty("location", "internet");

      if (graph.getFeatures().supportsVertexIteration) {
        assertEquals(count(graph.getVertices()), 2);
      }
      if (graph.getFeatures().supportsEdgeIteration) {
        assertEquals(count(graph.getEdges()), 1);
      }

      graph.shutdown();

      this.stopWatch();
      graph = graphTest.generateGraph();
      printPerformance(graph.toString(), 1, "graph loaded", this.stopWatch());
      if (graph.getFeatures().supportsVertexIteration) {
        assertEquals(count(graph.getVertices()), 2);
        if (graph.getFeatures().supportsVertexProperties) {
          for (Vertex vertex : graph.getVertices()) {
            assertTrue(
                vertex.getProperty("name").equals("marko")
                    || vertex.getProperty("name").equals("pavel"));
          }
        }
      }
      if (graph.getFeatures().supportsEdgeIteration) {
        assertEquals(count(graph.getEdges()), 1);
        for (Edge edge : graph.getEdges()) {
          assertEquals(edge.getLabel(), convertId(graph, "collaborator"));
          if (graph.getFeatures().supportsEdgeProperties)
            assertEquals(edge.getProperty("location"), "internet");
        }
      }
    }
    graph.shutdown();
  }
コード例 #5
0
 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);
   }
 }
コード例 #6
0
  public void testPropertyTransactions() {
    TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
    if (graph.getFeatures().supportsElementProperties()) {
      this.stopWatch();
      Vertex v = graph.addVertex(null);
      Object id = v.getId();
      v.setProperty("name", "marko");
      graph.stopTransaction(Conclusion.SUCCESS);
      printPerformance(
          graph.toString(),
          1,
          "vertex added with string property in a successful transaction",
          this.stopWatch());

      this.stopWatch();
      v = graph.getVertex(id);
      assertNotNull(v);
      assertEquals(v.getProperty("name"), "marko");
      v.setProperty("age", 30);
      assertEquals(v.getProperty("age"), 30);
      graph.stopTransaction(Conclusion.FAILURE);
      printPerformance(
          graph.toString(),
          1,
          "integer property not added in a failed transaction",
          this.stopWatch());

      this.stopWatch();
      v = graph.getVertex(id);
      assertNotNull(v);
      assertEquals(v.getProperty("name"), "marko");
      assertNull(v.getProperty("age"));
      printPerformance(
          graph.toString(),
          2,
          "vertex properties checked in a successful transaction",
          this.stopWatch());

      Edge edge = graph.addEdge(null, v, graph.addVertex(null), "test");
      edgeCount(graph, 1);
      graph.stopTransaction(Conclusion.SUCCESS);
      edgeCount(graph, 1);
      edge = getOnlyElement(graph.getVertex(v.getId()).getEdges(Direction.OUT));
      assertNotNull(edge);

      this.stopWatch();
      edge.setProperty("transaction-1", "success");
      assertEquals(edge.getProperty("transaction-1"), "success");
      graph.stopTransaction(Conclusion.SUCCESS);
      printPerformance(
          graph.toString(),
          1,
          "edge property added and checked in a successful transaction",
          this.stopWatch());
      edge = getOnlyElement(graph.getVertex(v.getId()).getEdges(Direction.OUT));
      assertEquals(edge.getProperty("transaction-1"), "success");

      this.stopWatch();
      edge.setProperty("transaction-2", "failure");
      assertEquals(edge.getProperty("transaction-1"), "success");
      assertEquals(edge.getProperty("transaction-2"), "failure");
      graph.stopTransaction(Conclusion.FAILURE);
      printPerformance(
          graph.toString(),
          1,
          "edge property added and checked in a failed transaction",
          this.stopWatch());
      edge = getOnlyElement(graph.getVertex(v.getId()).getEdges(Direction.OUT));
      assertEquals(edge.getProperty("transaction-1"), "success");
      assertNull(edge.getProperty("transaction-2"));
    }
    graph.shutdown();
  }