コード例 #1
0
  public void testDefensiveCopyOfChildren() {

    Node<Object, Object> rootNode = cache.getRoot();

    Fqn childFqn = Fqn.fromString("/child");
    rootNode.addChild(childFqn).put("k", "v");
    Set<Node<Object, Object>> children = rootNode.getChildren();
    Set<Object> childrenNames = rootNode.getChildrenNames();

    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);

    // now change stuff.

    rootNode.addChild(Fqn.fromString("/child2"));

    // assert that the collections we initially got have not changed.
    assert childrenNames.size() == 1;
    assert childrenNames.contains(childFqn.getLastElement());

    assert children.size() == 1;
    assert children.iterator().next().getFqn().equals(childFqn);
  }
コード例 #2
0
ファイル: NodeImpl.java プロジェクト: snowolfex/infinispan
 private boolean hasChild(AdvancedCache<?, ?> cache, Fqn f) {
   if (f.size() > 1) {
     // indirect child.
     Fqn absoluteFqn = Fqn.fromRelativeFqn(fqn, f);
     return exists(cache, absoluteFqn);
   } else {
     return hasChild(f.getLastElement());
   }
 }
コード例 #3
0
 @Override
 public boolean hasChild(Fqn f) {
   if (f.size() > 1) {
     // indirect child.
     Fqn absoluteFqn = Fqn.fromRelativeFqn(fqn, f);
     return exists(absoluteFqn);
   } else {
     return hasChild(f.getLastElement());
   }
 }
コード例 #4
0
  public void testGetChildrenNames() throws Exception {

    Node<Object, Object> rootNode = cache.getRoot();

    rootNode.addChild(A).put("k", "v");
    rootNode.addChild(B).put("k", "v");

    Set<Object> childrenNames = new HashSet<Object>();
    childrenNames.add(A.getLastElement());
    childrenNames.add(B.getLastElement());

    assertEquals(childrenNames, rootNode.getChildrenNames());

    // now delete a child, within a tx
    tm.begin();
    rootNode.removeChild(B);
    assertFalse(rootNode.hasChild(B));
    childrenNames.remove(B.getLastElement());
    assertEquals(childrenNames, rootNode.getChildrenNames());
    tm.commit();
    assertEquals(childrenNames, rootNode.getChildrenNames());
  }
コード例 #5
0
ファイル: NodeImpl.java プロジェクト: snowolfex/infinispan
  private Node<K, V> addChild(AdvancedCache<?, ?> cache, Fqn f) {
    startAtomic();
    try {
      Fqn absoluteChildFqn = Fqn.fromRelativeFqn(fqn, f);

      // 1) first register it with the parent
      AtomicMap<Object, Fqn> structureMap = getStructure(cache);
      structureMap.put(f.getLastElement(), absoluteChildFqn);

      // 2) then create the structure and data maps
      createNodeInCache(cache, absoluteChildFqn);

      return new NodeImpl<K, V>(absoluteChildFqn, cache, batchContainer);
    } finally {
      endAtomic();
    }
  }
コード例 #6
0
  /** Remember, Fqns are relative!! */
  public void testParentsAndChildren() {

    Node<Object, Object> rootNode = cache.getRoot();

    Node<Object, Object> nodeA = rootNode.addChild(A);
    Node<Object, Object> nodeB = nodeA.addChild(B);
    Node<Object, Object> nodeC = nodeA.addChild(C);
    Node<Object, Object> nodeD = rootNode.addChild(D);

    assertEquals(rootNode, nodeA.getParent());
    assertEquals(nodeA, nodeB.getParent());
    assertEquals(nodeA, nodeC.getParent());
    assertEquals(rootNode, nodeD.getParent());

    assertTrue(rootNode.hasChild(A));
    assertFalse(rootNode.hasChild(B));
    assertFalse(rootNode.hasChild(C));
    assertTrue(rootNode.hasChild(D));

    assertTrue(nodeA.hasChild(B));
    assertTrue(nodeA.hasChild(C));

    assertEquals(nodeA, rootNode.getChild(A));
    assertEquals(nodeD, rootNode.getChild(D));
    assertEquals(nodeB, nodeA.getChild(B));
    assertEquals(nodeC, nodeA.getChild(C));

    assertTrue(nodeA.getChildren().contains(nodeB));
    assertTrue(nodeA.getChildren().contains(nodeC));
    assertEquals(2, nodeA.getChildren().size());

    assertTrue(rootNode.getChildren().contains(nodeA));
    assertTrue(rootNode.getChildren().contains(nodeD));
    assertEquals(2, rootNode.getChildren().size());

    assertEquals(true, rootNode.removeChild(A));
    assertFalse(rootNode.getChildren().contains(nodeA));
    assertTrue(rootNode.getChildren().contains(nodeD));
    assertEquals(1, rootNode.getChildren().size());

    assertEquals("double remove", false, rootNode.removeChild(A));
    assertEquals("double remove", false, rootNode.removeChild(A.getLastElement()));
  }
コード例 #7
0
ファイル: NodeImpl.java プロジェクト: snowolfex/infinispan
 public boolean removeChild(AdvancedCache<?, ?> cache, Fqn f) {
   return removeChild(cache, f.getLastElement());
 }
コード例 #8
0
 @Override
 public boolean removeChild(Fqn f) {
   return removeChild(f.getLastElement());
 }