Package org.infinispan.tree

Examples of org.infinispan.tree.Fqn


      assert f.size() == 1;
      assert !f.isRoot();
   }

   public void testGenerations() {
      Fqn f = Fqn.fromElements(1, 2, 3, 4, 5, 6, 7);

      assert f.equals(f.getAncestor(f.size()));
      assert f.getParent().equals(f.getAncestor(f.size() - 1));
      assert Fqn.ROOT.equals(f.getAncestor(0));
      assert Fqn.fromElements(1).equals(f.getAncestor(1));
      assert Fqn.fromElements(1, 2).equals(f.getAncestor(2));
      assert Fqn.fromElements(1, 2, 3).equals(f.getAncestor(3));
      assert Fqn.fromElements(1, 2, 3, 4).equals(f.getAncestor(4));
      assert Fqn.fromElements(1, 2, 3, 4, 5).equals(f.getAncestor(5));

      try {
         f.getAncestor(-1);
         // should fail
         assert false;
      }
      catch (IllegalArgumentException good) {
         // expected
      }

      try {
         f.getAncestor(f.size() + 1);
         // should fail
         assert false;
      }
      catch (IndexOutOfBoundsException good) {
         // expected


      Map<String, String> data = cache.getData(Fqn.fromRelativeFqn(Fqn.fromString("STATUS"), Fqn.fromString("TRADE")));
      assertNotNull(data);
   }

   public void testConvenienceMethods() {
      Fqn fqn = Fqn.fromString("/test/fqn");
      String key = "key", value = "value";
      Map<String, String> data = new HashMap<String, String>();
      data.put(key, value);

      assertNull(cache.get(fqn, key));

   /**
    * Another convenience method that tests node removal
    */
   public void testNodeConvenienceNodeRemoval() {
      // this fqn is relative, but since it is from the root it may as well be absolute
      Fqn fqn = Fqn.fromString("/test/fqn");
      cache.getRoot().addChild(fqn);
      assertTrue(cache.getRoot().hasChild(fqn));

      assertEquals(true, cache.removeNode(fqn));
      assertFalse(cache.getRoot().hasChild(fqn));
      // remove should REALLY remove though and not just mark as deleted/invalid.
      Node n = cache.getNode(fqn);
      assertNull(n);

      assertEquals(false, cache.removeNode(fqn));

      // remove should REALLY remove though and not just mark as deleted/invalid.
      n = cache.getNode(fqn);
      assertNull(n);

      // Check that it's removed if it has a child
      Fqn child = Fqn.fromString("/test/fqn/child");
      log.error("TEST: Adding child " + child);
      cache.getRoot().addChild(child);
      assertStructure(cache, "/test/fqn/child");

      assertEquals(true, cache.removeNode(fqn));

   }

   private void assertStructure(TreeCache tc, String fqnStr) {
      // make sure structure nodes are properly built and maintained
      Cache c = tc.getCache();
      Fqn fqn = Fqn.fromString(fqnStr);
      // loop thru the Fqn, starting at its root, and make sure all of its children exist in proper NodeKeys
      for (int i = 0; i < fqn.size(); i++) {
         Fqn parent = fqn.getSubFqn(0, i);
         Object childName = fqn.get(i);
         // make sure a data key exists in the cache
         assertTrue("Node [" + parent + "] does not have a Data atomic map!", c.containsKey(new NodeKey(parent,
               NodeKey.Type.DATA)));
         assertTrue("Node [" + parent + "] does not have a Structure atomic map!", c.containsKey(new NodeKey(parent,

      }
   }


   public void testStopClearsData() throws Exception {
      Fqn a = Fqn.fromString("/a");
      Fqn b = Fqn.fromString("/a/b");
      String key = "key", value = "value";
      cache.getRoot().addChild(a).put(key, value);
      cache.getRoot().addChild(b).put(key, value);
      cache.getRoot().put(key, value);

   protected void init() {
      long startTime = System.currentTimeMillis();
      log.warn("Starting init() phase");
      fqns.clear();
      for (int i = 0; i < MAX_OVERALL_NODES; i++) {
         Fqn fqn;
         do {
            fqn = FqnGenerator.createRandomFqn(MAX_DEPTH);
         }
         while (fqns.contains(fqn));

      // loop through WARMUP_LOOPS gets and puts for JVM optimisation
      for (int i = 0; i < WARMUP_LOOPS; i++) {
         runner.execute(new Runnable() {
            public void run() {
               try {
                  Fqn fqn = Generator.getRandomElement(fqns);
                  DummyTransactionManager.getInstance().begin();
                  cache.get(fqn, "key");
                  DummyTransactionManager.getInstance().commit();
                  DummyTransactionManager.getInstance().begin();
                  cache.put(fqn, "key", "Value");

      int id;
      Mode mode;
      AtomicLong duration;

      public void run() {
         Fqn fqn = Generator.getRandomElement(fqns);
         long d = 0, st;
         try {
            switch (mode) {
               case PUT:
                  Object value = Generator.getRandomString();

      }
     
      // is the name a context?
      try
      {
         Fqn temp = Fqn.fromRelativeFqn(FQN_ROOT, Fqn.fromString(name.toString()));
         // TODO why not jst call remove -- why hasChild first?
         if (this.m_cache.getRoot().hasChild(temp))
         {
            this.m_cache.removeNode(temp);
            return;
         }
      }
      catch (CacheException ce)
      {
         // don't chain CacheException since Infinispan may not be on remote client's classpath
         NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
         ne.setStackTrace(ce.getStackTrace());
         throw ne;
      }
     
      int size = name.size();
     
      // get the context and key
      Fqn ctx;
      String key = name.get(size - 1);
      if (size > 1) // find subcontext to which the key is bound
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn = Fqn.fromString(prefix);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

      }
  
      int size = name.size();
  
      // get the context and key
      Fqn ctx;
      String key = name.get(size - 1);
      if (size > 1) // find subcontext to which the key is bound
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn = Fqn.fromString(prefix);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

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.