@Test
  public void deletesWithinTransactionArentWorking() throws IOException {
    OGraphDatabase db = new OGraphDatabase(url);
    db.open("admin", "admin");

    try {
      if (db.getVertexType("Foo") == null) db.createVertexType("Foo");
      if (db.getVertexType("Bar") == null) db.createVertexType("Bar");
      if (db.getVertexType("Sees") == null) db.createEdgeType("Sees");

      // Commenting out the transaction will result in the test succeeding.
      db.begin(TXTYPE.OPTIMISTIC);
      ODocument foo = (ODocument) db.createVertex("Foo").field("prop", "test1").save();

      // Comment out these two lines and the test will succeed. The issue appears to be related to
      // an edge
      // connecting a deleted vertex during a transaction
      ODocument bar = (ODocument) db.createVertex("Bar").field("prop", "test1").save();
      ODocument sees = db.createEdge(foo, bar, "Sees");
      db.commit();

      List<ODocument> foos = db.query(new OSQLSynchQuery("select * from Foo"));
      Assert.assertEquals(foos.size(), 1);

      db.begin(TXTYPE.OPTIMISTIC);
      db.removeVertex(foos.get(0));
      db.commit();

    } finally {
      db.close();
    }
  }
Exemple #2
0
  @Test
  public void multipleDatabasesSameThread() throws IOException {
    OGraphDatabase db1 = OGraphDatabasePool.global().acquire(DB_URL, "admin", "admin");
    ODocument doc1 = db1.createVertex();

    doc1.field("key", "value");
    doc1.save();
    db1.close();

    OGraphDatabase db2 = OGraphDatabasePool.global().acquire(DB_URL, "admin", "admin");

    ODocument doc2 = db2.createVertex();
    doc2.field("key", "value");
    doc2.save();
    db2.close();

    db1 = OGraphDatabasePool.global().acquire(DB_URL, "admin", "admin");

    final List<?> result =
        db1.query(
            new OSQLSynchQuery<ODocument>(
                "select out[weight=3].size() from V where out.size() > 0"));

    doc1 = db1.createVertex();
    doc1.field("newkey", "newvalue");
    doc1.save();
    db1.close();
  }
  @Test
  public void testConsistencyOnDelete() {
    OGraphDatabase db = new OGraphDatabase(url);
    db.open("admin", "admin");

    if (db.getVertexType("Foo") == null) db.createVertexType("Foo");

    try {
      // Step 1
      // Create several foo's
      db.createVertex("Foo").field("address", "test1").save();
      db.createVertex("Foo").field("address", "test2").save();
      db.createVertex("Foo").field("address", "test3").save();

      // just show what is there
      List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

      // remove those foos in a transaction
      // Step 2
      db.begin(TXTYPE.OPTIMISTIC);

      // Step 3a
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test1'"));
      Assert.assertEquals(1, result.size());
      // Step 4a
      db.removeVertex(result.get(0));

      // Step 3b
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test2'"));
      Assert.assertEquals(1, result.size());
      // Step 4b
      db.removeVertex(result.get(0));

      // Step 3c
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test3'"));
      Assert.assertEquals(1, result.size());
      // Step 4c
      db.removeVertex(result.get(0));

      // Step 6
      db.commit();

      // just show what is there
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

    } finally {
      db.close();
    }
  }
  @Test
  public void testQueryIsolation() {
    OGraphDatabase db = new OGraphDatabase(url);
    db.open("admin", "admin");

    try {
      db.begin();

      ODocument v1 = db.createVertex();
      v1.field("purpose", "testQueryIsolation");
      v1.save();

      if (!url.startsWith("remote")) {
        List<OIdentifiable> result =
            db.query(
                new OSQLSynchQuery<Object>("select from V where purpose = 'testQueryIsolation'"));
        Assert.assertEquals(result.size(), 1);
      }

      db.commit();

      List<OIdentifiable> result =
          db.query(
              new OSQLSynchQuery<Object>("select from V where purpose = 'testQueryIsolation'"));
      Assert.assertEquals(result.size(), 1);

    } finally {
      db.close();
    }
  }