Package org.infinispan.tree

Examples of org.infinispan.tree.Fqn


      assert 3 == tmp_fqn.size();
      assert fqn.equals(tmp_fqn);
   }

   public void testIsChildOf() {
      Fqn child = Fqn.fromString("/a/b");
      Fqn parent = Fqn.fromString("/a");
      assert child.isChildOf(parent);
      assert !parent.isChildOf(child);
      assert child.isChildOrEquals(child);

      parent = Fqn.fromString("/a/b/c");
      child = Fqn.fromString("/a/b/c/d/e/f/g/h/e/r/e/r/t/tt/");
      assert child.isChildOf(parent);


      child = Fqn.fromString("/a/b/c/d/e/f/g/h/e/r/e/r/t/tt/");
      assert child.isChildOf(parent);
   }

   public void testIsChildOf2() {
      Fqn child = Fqn.fromString("/a/b/c/d");
      assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
   }

      Fqn child = Fqn.fromString("/a/b/c/d");
      assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
   }

   public void testParentage() {
      Fqn fqnRoot = Fqn.ROOT;
      Fqn parent = fqnRoot.getParent();
      assert parent.equals(fqnRoot);

      Fqn fqnOne = Fqn.fromString("/one");
      parent = fqnOne.getParent();
      assert parent.equals(fqnRoot);
      assert fqnOne.isChildOf(parent);

      Fqn fqnTwo = Fqn.fromString("/one/two");
      parent = fqnTwo.getParent();
      assert parent.equals(fqnOne);
      assert fqnTwo.isChildOf(parent);

      Fqn fqnThree = Fqn.fromString("/one/two/three");
      parent = fqnThree.getParent();
      assert parent.equals(fqnTwo);
      assert fqnThree.isChildOf(parent);

   }

   public void testConcurrentMoveSiblings() throws Exception {
      // tests a tree structure as such:
      // /a/x, a/y, /b, /c
      // N threads try to move /a/x from /a to /b and /a/y from /a to /c
      final int N = 5;
      final Fqn X = Fqn.fromString("/x"), Y = Fqn.fromString("/y");

      // set up the initial structure.
      Node<Object, Object> rootNode = treeCache.getRoot();
      Node<Object, Object> nodeA = rootNode.addChild(A);
      nodeA.addChild(X);
      nodeA.addChild(Y);
      Node<Object, Object> nodeB = rootNode.addChild(B);
      Node<Object, Object> nodeC = rootNode.addChild(C);

      Callable<Object>[] movers = new Callable[N];
      for (int i = 0; i < N; i++) {
         final Fqn source = Fqn.fromRelativeFqn(A, i % 2 == 0 ? X : Y);
         final Fqn dest = i % 2 == 0 ? B : C;
         movers[i] = new Callable<Object>() {
            public Object call() {
               try {
                  treeCache.move(source, dest);
               } catch (Exception e) {

   public void testConcurrentMoveToSameDest() throws Exception {
      // tests a tree structure as such:
      // /a/x, /b/y, /c
      // N threads try to move /a/x to /c and /b/y to /c at the same time
      final int N = 5;
      final Fqn X = Fqn.fromString("/x"), Y = Fqn.fromString("/y");

      // set up the initial structure.
      Node<Object, Object> rootNode = treeCache.getRoot();
      Node<Object, Object> nodeA = rootNode.addChild(A);
      nodeA.addChild(X);
      Node<Object, Object> nodeB = rootNode.addChild(B);
      nodeB.addChild(Y);
      Node<Object, Object> nodeC = rootNode.addChild(C);

      Callable<Object>[] movers = new Callable[N];
      for (int i = 0; i < N; i++) {
         final Fqn source = i % 2 == 0 ? Fqn.fromRelativeFqn(A, X) : Fqn.fromRelativeFqn(B, Y);
         movers[i] = new Callable<Object>() {
            public Object call() throws Exception {
               try {
                  treeCache.move(source, C);
               } catch (Exception e) {

   public void testConcurrentMoveSameNode() throws Exception {
      // set up the initial structure
      // /a, /b, /c
      // one thread tries to move /c under /a, another tries to move /c under /b
      Node<Object, Object> rootNode = treeCache.getRoot();
      final Fqn FQN_A = A, FQN_B = B, FQN_C = C;
      Node nodeA = rootNode.addChild(FQN_A);
      Node nodeB = rootNode.addChild(FQN_B);
      Node nodeC = rootNode.addChild(FQN_C);

      final CountDownLatch nodeReadLatch = new CountDownLatch(1);

      assertEquals(Collections.emptySet(), nodeB.getChildrenNames());
   }

   public void testMoveInSamePlace() {
      Node<Object, Object> rootNode = treeCache.getRoot();
      final Fqn FQN_X = Fqn.fromString("/x");
      // set up the initial structure.
      Node aNode = rootNode.addChild(A);
      Node xNode = aNode.addChild(FQN_X);
      assertEquals(aNode.getChildren().size(), 1);

      assert fqnThree.isChildOf(parent);

   }

   public void testRoot() {
      Fqn fqn = Fqn.ROOT;
      assert fqn.isRoot();

      fqn = Fqn.fromString("/one/two");
      assert !fqn.isRoot();

      Fqn f = Fqn.fromString("/");

      assert f.isRoot();
      assert f.equals(Fqn.ROOT);
   }

      assert f.isRoot();
      assert f.equals(Fqn.ROOT);
   }

   public void testGetName() {
      Fqn integerFqn = Fqn.fromElements(1);
      assert "1".equals(integerFqn.getLastElementAsString());

      Object object = new Object();
      Fqn objectFqn = Fqn.fromElements(object);
      assert object.toString().equals(objectFqn.getLastElementAsString());
   }

   }

   // testing generics

   public void testSize() {
      Fqn f = Fqn.ROOT;
      assert f.size() == 0;
      assert f.isRoot();

      f = Fqn.fromString("/");
      assert f.size() == 0;
      assert f.isRoot();

      f = Fqn.fromString("/hello");
      assert f.size() == 1;
      assert !f.isRoot();
   }

TOP

Related Classes of org.infinispan.tree.Fqn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.