Example #1
0
  // MMB-1889
  public void testCreateRelationAndDeleteNode() {
    // Make a relation to an existing node. Then delete that node with the 'delete relations'
    // option'. Commit the transaction.
    // The new relations should not exist, since the node was deleted.
    // No errors.

    Cloud cloud = getCloud();

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

    Node url = cloud.getNodeManager("urls").createNode();
    url.commit();

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

    Node turl = t.getNode(url.getNumber());
    Node news = t.getNode(newNode);
    RelationManager rm = t.getRelationManager("urls", "news", "posrel");
    Relation r = turl.createRelation(news, rm);
    r.commit();
    turl.delete(true);
    t.commit();

    int urlCountAfter = Queries.count(cloud.getNodeManager("urls").createQuery());
    assertEquals(urlCount, urlCountAfter);
    int relCountAfter = Queries.count(cloud.getNodeManager("insrel").createQuery());
    assertEquals(relCount, relCountAfter);
  }
Example #2
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 #3
0
  // MMB-1860 (4)
  public void testRelateAndDeleteRelation() {

    //  Make a relation between two nodes. Delete the relation again. Commit the transaction.
    // Te relation shouldn't exist

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

    Node newUrl = cloud.getNodeManager("urls").createNode();
    newUrl.commit();

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

    Node news = t.getNode(newNode);
    Node url = t.getNode(newUrl.getNumber());
    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);

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

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

    assertEquals(relCount, relCountAfter);
  }
Example #4
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 #5
0
  public void testAlias() {
    Cloud cloud = getCloud();
    {
      Node node = cloud.getNode(newNode2);
      node.setStringValue("title", "abcdef");
      node.commit();
      assertEquals("abcdef", node.getStringValue("title"));
      node = cloud.getNode("test.news." + seq);
      assertEquals("abcdef", node.getStringValue("title"));
    }

    {
      Transaction t = cloud.getTransaction("bar12");

      Node node = t.getNode(newNode2);
      node.setStringValue("title", "abcdefg");
      node.commit();
      assertEquals("abcdefg", node.getStringValue("title"));
      t.commit();
      assertEquals("abcdefg", node.getStringValue("title"));

      node = cloud.getNode("test.news." + seq);
      assertEquals("abcdefg", node.getStringValue("title"));

      node = cloud.getNode(newNode2);
      assertEquals("abcdefg", node.getStringValue("title"));
    }
  }
Example #6
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 #7
0
 public void testCommitDelete() {
   Cloud cloud = getCloud();
   Transaction t = cloud.getTransaction("bar6");
   Node node = t.getNode(newNode);
   node.delete();
   t.commit();
   assertFalse(cloud.hasNode(newNode));
 }
Example #8
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 #9
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 #10
0
  public void testCommit() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar3");
    Node node = t.getNode(newNode);
    node.setStringValue("title", "yyyyy");
    node.commit();
    t.commit();

    node = cloud.getNode(newNode);

    assertEquals("yyyyy", node.getStringValue("title"));
  }
Example #11
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 #12
0
  public void testEditNodeOutsideTransaction2() {
    Cloud cloud = getCloud();
    Transaction t = cloud.getTransaction("bar10");
    Node nodeInTransaction = t.getNode(newNode2);
    nodeInTransaction.setStringValue("title", "foo2");
    Node nodeOutTransaction = cloud.getNode(newNode2);
    nodeOutTransaction.setStringValue("title", "bar2");

    t.commit();
    nodeOutTransaction.commit();

    // transaction was committed _earlier_ so the commit of the node must have won
    assertEquals("bar2", cloud.getNode(newNode2).getStringValue("title"));
    // assertEquals("bar2", nodeInTransaction.getStringValue("title"));// not sure what this should
    // have done, but anyhow, it now fails
    assertEquals("bar2", nodeOutTransaction.getStringValue("title"));
  }
Example #13
0
  // Test for http://www.mmbase.org/jira/browse/MMB-1621
  public void testGetValue() {
    Cloud cloud = getCloud();

    String value = cloud.getNode(newNode).getStringValue("title");
    assertFalse("zzzzz".equals(value));

    Transaction t = cloud.getTransaction("bar4");
    System.out.println("Transaction now " + t);
    Node node = t.getNode(newNode);
    assertEquals(1, t.getNodes().size());
    node.setStringValue("title", "zzzzz");
    assertEquals("zzzzz", node.getStringValue("title"));
    node.commit(); // committing inside transaction

    assertEquals("zzzzz", node.getStringValue("title"));
    assertEquals(value, cloud.getNode(newNode).getStringValue("title"));

    t.commit();
    assertEquals("zzzzz", cloud.getNode(newNode).getStringValue("title"));
  }
Example #14
0
  public void testDeleteNodeOutsideTransaction() {
    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 {
      t.commit();
    } catch (Exception e) {
      // should not give exception. MMB-1680
      log.error(e.getMessage(), e);
      fail(e.getMessage());
    }

    assertTrue(cloud.hasNode(newNode2));
  }
Example #15
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 #16
0
  // MMB-1860 (2)
  public void testCreateRelateAndDelete() {

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

    Cloud cloud = getCloud();
    int urlCount = Queries.count(cloud.getNodeManager("urls").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);

    url.delete(true);

    t.commit();

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

    assertEquals(urlCount, urlCountAfter);
  }