Example #1
0
 public void testCreateRelationBetweenNewNodes() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("createrelationtrans");
   NodeManager news = t.getNodeManager("news");
   Node n = news.createNode();
   NodeManager urls = t.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t.getRelationManager("news", "urls", "posrel");
   Relation r = n.createRelation(url, rm);
   t.commit();
 }
Example #2
0
  // MMB-1860 (3)
  public void testCreateRelateAndDeleteRelation() {

    // Create new node. Make a relation to it. Delete the relation again. Commit the transaction.
    // The new node must exist, but the relation shouldn't.

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());
    int relCount = Queries.count(cloud.getNodeManager("insrel").createQuery());

    Transaction t = cloud.getTransaction("testcreateandelete");

    Node news = t.getNode(newNode);
    Node url = t.getNodeManager("urls").createNode();
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(news, rm);
    r.commit();

    r.delete();

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount + 1, urlCountAfter);

    // Bit the relation should not exist, because it was deleted angain

    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());

    assertEquals(relCount, relCountAfter);
  }
Example #3
0
  public void testCreateAndDelete2() {
    // Create new node. Request the node again. Delete  that. Commit the transaction.
    // The new node must not exist.

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testcreateandelete");
    Node url = t.getNodeManager("urls").createNode();
    url.commit();
    assertEquals(1, t.getNodes().size());

    Node reurl = t.getNode(url.getNumber());
    reurl.delete();

    assertEquals(
        1,
        t.getNodes()
            .size()); // 0 would also be an option, but the node remaisn in the transaction as
                      // 'NOLONGER'

    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());

    assertEquals(urlCount, urlCountAfter);
  }
Example #4
0
  // same case as above, only no changes are made to the node.
  public void testDeleteNodeOutsideTransactionNodeInTransactionButNotChanged() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar11");
    Node nodeInTransaction = t.getNode(newNode2);
    // nodeInTransaction.setStringValue("title", "foo2");
    {
      // now delete the node
      Node nodeOutTransaction = cloud.getNode(newNode2);
      nodeOutTransaction.delete();
      assertFalse(cloud.hasNode(newNode2));
    }

    try {
      // make a relation to the (deleted) node, but in the transaction, where the node still
      // exists.
      // This demonstrate that there is an actual problem if the node ends up non-existing now.
      Node url = t.getNodeManager("urls").createNode();
      RelationManager rm = t.getRelationManager("news", "urls", "posrel");
      Relation r = nodeInTransaction.createRelation(url, rm);
      t.commit();
    } catch (Exception e) {
      // should not give exception. MMB-1680
      log.error(e.getMessage(), e);
      fail(e.getMessage());
    }

    assertTrue(cloud.hasNode(newNode2));
    assertEquals(1, cloud.getNode(newNode2).countRelations());
  }
Example #5
0
 // old node as argument
 public void testCreateRelationToNewNode2() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("createrelationtrans");
   Node n = t.getNode(newNode);
   NodeManager urls = t.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t.getRelationManager("urls", "news", "posrel");
   Relation r = url.createRelation(n, rm);
   t.commit();
 }
Example #6
0
  public void testGetNode() {
    // Create new node. Request the node again.
    // Should work

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").createQuery());

    Transaction t = cloud.getTransaction("testgetnode");
    Node url = t.getNodeManager("urls").createNode();
    url.setStringValue("url", "http://bla");
    url.commit();

    Node reurl = t.getNode(url.getNumber());

    assertEquals("http://bla", reurl.getStringValue("url"));
  }
Example #7
0
 public void testTransactionsAreEqual() {
   Cloud cloud = getCloud();
   Transaction t1 = cloud.getTransaction("testequals");
   Transaction t2 = cloud.getTransaction("testequals");
   assertEquals(t1, t2);
   Node n = t1.getNode(newNode);
   NodeManager urls = t2.getNodeManager("urls");
   Node url = urls.createNode();
   RelationManager rm = t2.getRelationManager("urls", "news", "posrel");
   Relation r = url.createRelation(n, rm);
   t2.commit();
   assertTrue(t2.isCommitted());
   assertTrue(t1.isCommitted());
   // assertTrue(t1 == t2); // FAILS IN RMMCI. Perhaps we should simply implement .equals on
   // transactions
 }
Example #8
0
  public void testSetContextSubTransaction() {
    Cloud cloud = getCloud();

    Transaction ot = cloud.getTransaction("bar8");
    Transaction t = ot.getTransaction("bar9");
    Node n = t.getNodeManager("news").createNode();
    n.setContext("non_default");
    assertEquals("non_default", n.getContext());
    t.commit();

    Node n2 = ot.getNode(n.getNumber());
    assertEquals("non_default", n2.getContext());

    ot.commit();
    Node n3 = cloud.getNode(n.getNumber());
    assertEquals("non_default", n3.getContext());
  }
Example #9
0
  public void testSetContext() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar7");
    Node n = t.getNodeManager("news").createNode();

    assertEquals(1, t.getNodes().size());

    n.setContext("non_default");

    assertEquals(1, t.getNodes().size());

    assertEquals("non_default", n.getStringValue("owner"));
    assertEquals("non_default", n.getContext());

    assertEquals(1, t.getNodes().size());

    t.commit();

    Node n2 = cloud.getNode(n.getNumber());
    assertEquals("non_default", n2.getStringValue("owner"));
    assertEquals("non_default", n2.getContext());
  }
Example #10
0
  // MMB-1857
  public void testGetNodes() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("testgetnodes");
    Node n = t.getNode(newNode);
    Node url = t.getNodeManager("urls").createNode();
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = url.createRelation(n, rm);

    {
      // should not give NPE's or so
      n.commit();
      url.commit();
      r.commit();
    }

    assertEquals(3, t.getNodes().size()); // 2 nodes and one relation

    for (Node rn : t.getNodes()) {
      // should occur no exceptions
      rn.commit(); // should have little effect in trans
    }
    t.cancel();
  }