Package org.jboss.cache

Examples of org.jboss.cache.Fqn


   /**
    * Generic combo case.
    */
   public void testCombo1() throws EvictionException
   {
      Fqn fqn1 = Fqn.fromString("/a/b/c");
      Fqn fqn2 = Fqn.fromString("/a/b/d");
      Fqn fqn3 = Fqn.fromString("/a/b/e");
      Fqn fqn4 = Fqn.fromString("/a/b/f");
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);

      // Should have a maximum of 2 nodes.
      config.setMaxNodes(2);
      config.setTimeToLive(1000);


   /**
    * Generic combo case with newly added node should be around.
    */
   public void testCombo2() throws EvictionException
   {
      Fqn fqn1 = Fqn.fromString("/a/b/c");
      Fqn fqn2 = Fqn.fromString("/a/b/d");
      Fqn fqn3 = Fqn.fromString("/a/b/e");
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);

      config.setMaxNodes(2);
      config.setTimeToLive(1000);
      config.setMaxAge(3000);

      config.setMaxNodes(0);
      config.setTimeToLive(1000000);

      for (int i = 0; i < 100; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
      }

      algorithm.process(region.getEvictionEventQueue());

      for (int i = 0; i < 100; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         if (i % 2 == 0)
         {
            region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
         }
      }

      algorithm.process(region.getEvictionEventQueue());

      LRUQueue queue = (LRUQueue) algorithm.getEvictionQueue();

      NodeEntry ne;
      int count = 0;
      while ((ne = queue.getFirstLRUNodeEntry()) != null)
      {
         if (count < 50)
         {
            assertEquals(1, ne.getNumberOfNodeVisits());
         }
         else
         {
            assertEquals(2, ne.getNumberOfNodeVisits());
         }
         queue.removeNodeEntry(ne);
         count++;
      }

      for (int i = 0; i < 100; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.ADD_NODE_EVENT);
      }

      algorithm.process(region.getEvictionEventQueue());
      long lastCreateTimestamp = 0;

      String rootStr = "/org/jboss/test/data/";

      for (int i = 0; i < 10; i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         try
         {
            cache.put(fqn, str, str);
         }
         catch (Exception e)
         {
            fail("Failed to insert data" + e);
            e.printStackTrace();
         }
      }

      evController.startEviction();

      try
      {
         for (int i = 0; i < 5; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNull("Fqn " + fqn + " should be null", cache.get(fqn, str));
         }
         for (int i = 5; i < 10; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNotNull(cache.get(fqn, str));
         }

         // since min is 5 the cache won't deplete past 5 nodes left in the cache.
         for (int i = 5; i < 10; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNotNull(cache.get(fqn, str));
         }

         // now we add some more nodes and we selectively visit some older nodes but not all. they should not get
         // evicted when the thread next runs.
         for (int i = 5; i < 7; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            cache.get(fqn, str);
         }

         // add 2 more to push the limit to 5 so we cause the old unvisited nodes to get evicted.
         for (int i = 10; i < 13; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            cache.put(fqn, str, str);

            // now bring up their hit count for LFU purposes (cache hit count based eviction).
            for (int k = 0; k < 10; k++)
            {
               cache.get(fqn, str);
            }
         }

         evController.startEviction();

         // now make sure we still only have 5 nodes and they are the ones we expect based on LFU
         for (int i = 5; i < 7; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNotNull(cache.get(fqn, str));
         }

         for (int i = 7; i < 10; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNull(cache.get(fqn, str));
         }

         for (int i = 10; i < 13; i++)
         {
            String str = rootStr + Integer.toString(i);
            Fqn fqn = Fqn.fromString(str);
            assertNotNull(cache.get(fqn, str));
         }

      }
      catch (Exception e)

   {
      String rootStr = "/org/jboss/data/";
      for (int i = 0; i < maxNodesR1; i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         try
         {
            cache.put(fqn, str, str);
         }
         catch (Exception e)
         {
            fail("Failed to insert data" + e);
            e.printStackTrace();
         }
      }

      evController.startEviction();

      for (int i = 0; i < (maxNodesR1 - minNodesR1); i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         assertNull(cache.get(fqn, str));
      }

      for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         assertNotNull(cache.get(fqn, str));
      }

      for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
      {
         if (i % 2 == 0)
         {
            String str = rootStr + i;
            Fqn fqn = Fqn.fromString(str);
            cache.removeNode(fqn);
         }
      }

      evController.startEviction();


      for (int i = (maxNodesR1 - minNodesR1); i < maxNodesR1; i++)
      {
         if (i % 2 == 0)
         {
            String str = rootStr + i;
            Fqn fqn = Fqn.fromString(str);
            assertNull(cache.getNode(fqn));
         }
      }
   }

   }

   public void testInUseEviction() throws Exception
   {
      String rootStr = "/org/jboss/test/data/inuse/";
      Fqn fqn;

      for (int i = 0; i < 10; i++)
      {
         String str = rootStr + i;
         fqn = Fqn.fromString(str);
         cache.put(fqn, str, str);
      }

      cache.getRegionManager().getRegion(Fqn.fromString(rootStr + 5), false).markNodeCurrentlyInUse(Fqn.fromString(rootStr + 5), 0);

      for (int i = 10; i < 15; i++)
      {
         String str = rootStr + i;
         fqn = Fqn.fromString(str);
         cache.put(fqn, str, str);
      }

      new EvictionController(cache).startEviction();

      for (int i = 0; i < 5; i++)
      {
         Fqn f = Fqn.fromString(rootStr + i);
         assert null == cache.getNode(f) : f + " should be null";
      }

      assertNotNull(cache.getNode(Fqn.fromString(rootStr + 5)));

      for (int i = 6; i < 11; i++)
      {
         Fqn f = Fqn.fromString(rootStr + i);
         assert null == cache.getNode(f) : f + " should be null";
      }
      for (int i = 11; i < 15; i++)
      {
         Fqn f = Fqn.fromString(rootStr + i);
         assert null != cache.getNode(f) : f + " should not be null";
      }
   }

   {
      String rootStr = "/org/jboss/test/data/";
      for (int i = 0; i < 10; i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         try
         {
            cache.put(fqn, str, str);
         }
         catch (Exception e)

   public void testNodeVisited() throws InterruptedException
   {
      String rootStr = "/org/jboss/test/data/";

      final Fqn fqn7 = Fqn.fromString(rootStr + "7");

      for (int i = 0; i < 10; i++)
      {
         String str = rootStr + i;
         Fqn fqn = Fqn.fromString(str);
         cache.put(fqn, str, str);

         // playing favourites here:
         cache.getNode(fqn7);// just to keep it fresh
      }

   {
      String rootStr = "/org/jboss/test/data/";
      for (int i = 0; i < 10; i++)
      {
         String str = rootStr + i + "/" + i;
         Fqn fqn = Fqn.fromString(str);
         cache.put(fqn, str, str);
      }

      String str1 = rootStr + "7";
      Fqn fqn1 = Fqn.fromString(str1);
      String str2 = rootStr + "7/7";
      Fqn fqn2 = Fqn.fromString(str2);
      cache.get(fqn1, str1);// just to keep it fresh
      cache.get(fqn2, str2);// just to keep it fresh
      new EvictionController(cache).startEviction();
      cache.get(fqn1, str1);// just to keep it fresh
      cache.get(fqn2, str2);// just to keep it fresh

   {
      String rootStr = "/test/";

      // Add a parent, then a child. LRU will evict the parent,
      // then the child, leaving behind an empty parent
      Fqn parent = Fqn.fromString(rootStr + "parent");
      cache.put(parent, "key", "value");
      cache.put(Fqn.fromRelativeElements(parent, "child"), "key", "value");

      // Give eviction time to run a few times, then confirm parent
      // is completely gone

TOP

Related Classes of org.jboss.cache.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.