Package org.infinispan.tree

Examples of org.infinispan.tree.Fqn


      startAtomic();
      try {
         NodeKey dataKey = new NodeKey(fqn, NodeKey.Type.DATA);
         NodeKey structureKey = new NodeKey(fqn, NodeKey.Type.STRUCTURE);
         if (cache.containsKey(dataKey) && cache.containsKey(structureKey)) return false;
         Fqn parent = fqn.getParent();
         if (!fqn.isRoot()) {
            if (!exists(cache, parent)) createNodeInCache(cache, parent);
            AtomicMap<Object, Fqn> parentStructure = getStructure(cache, parent);
            parentStructure.put(fqn.getLastElement(), fqn);
         }


         output.write(type);
      }
     
      @Override
      public NodeKey readObject(ObjectInput input) throws IOException, ClassNotFoundException {
         Fqn fqn = (Fqn) input.readObject();
         int typeb = input.readUnsignedByte();
         NodeKey.Type type = null;
         switch (typeb) {
            case DATA_BYTE:
               type = DATA;

   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();

   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);
   }

   }

   public void testBasicOperation() throws SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException {
      assertClusterSize("Should only be 2  caches in the cluster!!!", 2);

      Fqn f = Fqn.fromString("/test/data");
      String k = "key", v = "value";

      assertNull("Should be null", cache1.getRoot().getChild(f));
      assertNull("Should be null", cache2.getRoot().getChild(f));

      treeCache1 = tcf.createTreeCache(cache1);
      treeCache2 = tcf.createTreeCache(cache2);
   }

   public void testTreeCacheLocalPut() throws Exception {
      final Fqn fqn = Fqn.fromElements("TEST");
      treeCache1.put(fqn, KEY, "1", Flag.CACHE_MODE_LOCAL);
      treeCache2.put(fqn, KEY, "2", Flag.CACHE_MODE_LOCAL);
      assert "2".equals(treeCache2.get(fqn, KEY)) : "treeCache2 was updated locally";
      assert "1".equals(treeCache1.get(fqn, KEY)) : "treeCache1 should not be invalidated in case of LOCAL put in treeCache2";

   public void testWithFlags() {
      AdvancedCache<String, String> localCache1 = cache1.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL);
      AdvancedCache<String, String> localCache2 = cache2.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL);
      TreeCache<String, String> treeCache1 = new TreeCacheFactory().createTreeCache(localCache1);
      TreeCache<String, String> treeCache2 = new TreeCacheFactory().createTreeCache(localCache2);
      final Fqn fqn = Fqn.fromElements("TEST_WITH_FLAGS");
      treeCache1.put(fqn, KEY, "1");
      treeCache2.put(fqn, KEY, "2");
      assert "2".equals(treeCache2.get(fqn, KEY)) : "treeCache2 was updated locally";
      assert "1".equals(treeCache1.get(fqn, KEY)) : "treeCache1 should not be invalidated in case of LOCAL put in treeCache2";
   }

   }

   public void testBasicOperation() {
      assertClusterSize("Should only be 2  caches in the cluster!!!", 2);

      Fqn f = Fqn.fromString("/test/data");
      String k = "key", v = "value";

      assertNull("Should be null", cache1.getRoot().getChild(f));
      assertNull("Should be null", cache2.getRoot().getChild(f));

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.