Package org.jboss.cache

Examples of org.jboss.cache.RegionImpl


      additionalConfiguration(c);
      c.getEvictionConfig().setWakeupInterval(-1);
      Cache<Object, Object> cache2 = new UnitTestCacheFactory<Object, Object>().createCache(c, getClass());
      caches.put("evict2", cache2);

      RegionImpl region = (RegionImpl) cache2.getRegion(Fqn.ROOT, false);
      // We expect a VISIT event for / and ADD events for /a, /a/b and /a/b/c
      int nodeEventQueueSize = region.getEvictionEventQueue().size();
      assertTrue("Saw the expected number of node events", nodeEventQueueSize >= 4); //one event happens on read root
   }
View Full Code Here


   public void testMaxNodes() throws Exception
   {
      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);
      MRUAlgorithmConfig config = (MRUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(1);
      region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
      algorithm.process(region.getEvictionEventQueue());

      assertEquals(1, algorithm.getEvictionQueue().getNumberOfNodes());

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

      algorithm.process(region.getEvictionEventQueue());

      assertEquals(100, algorithm.getEvictionQueue().getNumberOfNodes());
   }
View Full Code Here

      Fqn fqn6 = Fqn.fromString("/a/b/h");
      Fqn fqn7 = Fqn.fromString("/a/b/i");
      Fqn fqn8 = Fqn.fromString("/a/b/j");
      Fqn fqn9 = Fqn.fromString("/a/b/k");
      Fqn fqn10 = Fqn.fromString("/a/b/l");
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      MRUAlgorithmConfig config = (MRUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(8);
      region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn5, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn6, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn7, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn8, EvictionEvent.Type.ADD_NODE_EVENT);

      algorithm.process(region.getEvictionEventQueue());

      assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());

      region.registerEvictionEvent(fqn9, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn10, EvictionEvent.Type.ADD_NODE_EVENT);

//      Thread.sleep(5000);
      assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());

      region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn4, EvictionEvent.Type.ADD_NODE_EVENT);

      algorithm.process(region.getEvictionEventQueue());

      assertEquals(8, algorithm.getEvictionQueue().getNumberOfNodes());

      assertNull(algorithm.getEvictionQueue().getNodeEntry(fqn2));
      assertNull("No FQN4 " + algorithm.getEvictionQueue(),
View Full Code Here

   public void testMaxNode2()
   {
      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(1);
      config.setMinNodes(20);
      region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);

      try
      {
         algo.process(region.getEvictionEventQueue());
      }
      catch (EvictionException e)
      {
         fail("testMaxNode: process failed " + e);
         e.printStackTrace();
      }
      assertEquals("Queue size should be ", 1, algo.getEvictionQueue().getNumberOfNodes());

      region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);


      try
      {
         algo.process(region.getEvictionEventQueue());
      }
      catch (EvictionException e)
      {
         fail("testMaxNode: process failed " + e);
         e.printStackTrace();
View Full Code Here

      Fqn fqn1 = Fqn.fromString("/a/b/c");
      Fqn fqn2 = Fqn.fromString("/a/b/c/d");
      Fqn fqn3 = Fqn.fromString("/a/b/c/d/e");
      Fqn fqn4 = Fqn.fromString("/a/b/c/d/e/f");

      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      LFUAlgorithmConfig config = (LFUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();

      config.setMaxNodes(-1);
      config.setMinNodes(2);

      region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn4, ADD_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());

      assertEquals("Queue size should be ", 2, algo.getEvictionQueue().getNumberOfNodes());
   }
View Full Code Here

   public void testMinNode2() throws Exception
   {
      Fqn fqn1 = Fqn.fromString("/a/b/c");
      Fqn fqn2 = Fqn.fromString("/a/b/d");

      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      LFUAlgorithmConfig config = (LFUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();

      config.setMaxNodes(-1);
      config.setMinNodes(-1);

      region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());

      assertEquals("Queue size should be ", 0, algo.getEvictionQueue().getNumberOfNodes());
   }
View Full Code Here

      Fqn fqn8 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k");
      Fqn fqn9 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k/l");
      Fqn fqn10 = Fqn.fromString("/a/b/c/d/e/f/g/h/i/j/k/l/m");


      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      LFUAlgorithmConfig config = (LFUAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(-1);
      config.setMinNodes(100);

      region.registerEvictionEvent(fqn1, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn3, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn4, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn5, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn6, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn7, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn8, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn9, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn10, ADD_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());
      LFUQueue queue = (LFUQueue) algo.evictionQueue;
      assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());

      for (NodeEntry ne : queue)
      {
         assertEquals(1, ne.getNumberOfNodeVisits());
      }

      // fqn1 visited 4 additional times.
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);

      // fqn2 visited 3 additional times.
      region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn2, VISIT_NODE_EVENT);

      // fqn3 visited 1 additional time.
      region.registerEvictionEvent(fqn3, VISIT_NODE_EVENT);

      // fqn4 visited 2 additional times.
      region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);

      // fqn9 visited 1 additional time.
      region.registerEvictionEvent(fqn9, VISIT_NODE_EVENT);

      // fqn10 visited 2 additional times.
      region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn10, VISIT_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());
      int count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         if (count == 5 || count == 6)
         {
            assertEquals(2, ne.getNumberOfNodeVisits());
         }
         else if (count == 7 || count == 8)
         {
            assertEquals(3, ne.getNumberOfNodeVisits());
         }
         else if (count == 9)
         {
            assertEquals(4, ne.getNumberOfNodeVisits());
         }
         else if (count == 10)
         {
            assertEquals(5, ne.getNumberOfNodeVisits());
         }
         else
         {
            assertEquals(1, ne.getNumberOfNodeVisits());
         }
      }


      assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());

      Fqn fqn11 = Fqn.fromString("/a");
      Fqn fqn12 = Fqn.fromString("/a/b");

      region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn12, ADD_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());

      count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         if (count == 7 || count == 8)
         {
            assertEquals(2, ne.getNumberOfNodeVisits());
         }
         else if (count == 9 || count == 10)
         {
            assertEquals(3, ne.getNumberOfNodeVisits());
         }
         else if (count == 11)
         {
            assertEquals(4, ne.getNumberOfNodeVisits());
         }
         else if (count == 12)
         {
            assertEquals(5, ne.getNumberOfNodeVisits());
         }
         else
         {
            assertEquals(1, ne.getNumberOfNodeVisits());
         }
      }

      assertEquals(12, algo.getEvictionQueue().getNumberOfNodes());

      region.registerEvictionEvent(fqn1, REMOVE_NODE_EVENT);
      region.registerEvictionEvent(fqn11, REMOVE_NODE_EVENT);
      region.registerEvictionEvent(fqn12, REMOVE_NODE_EVENT);
      region.registerEvictionEvent(fqn10, REMOVE_NODE_EVENT);

      algo.process(region.getEvictionEventQueue());

      count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         if (count == 5 || count == 6)
         {
            assertEquals(2, ne.getNumberOfNodeVisits());
         }
         else if (count == 7)
         {
            assertEquals(3, ne.getNumberOfNodeVisits());
         }
         else if (count == 8)
         {
            assertEquals(4, ne.getNumberOfNodeVisits());
         }
         else
         {
            assertEquals(1, ne.getNumberOfNodeVisits());
         }
      }

      assertEquals(8, algo.getEvictionQueue().getNumberOfNodes());

      //test add/visit/remove combination
      region.registerEvictionEvent(fqn11, ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn11, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn4, VISIT_NODE_EVENT);

      // purposefully revisit a node that has been removed. assert that it is readded.
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);
      region.registerEvictionEvent(fqn1, VISIT_NODE_EVENT);

      region.registerEvictionEvent(fqn3, REMOVE_NODE_EVENT);


      algo.process(region.getEvictionEventQueue());

      count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
View Full Code Here

      assertEquals(9, algo.getEvictionQueue().getNumberOfNodes());
   }

   public void testEvictionQueueSortOrder2() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      EvictionRegionConfig config = region.getEvictionRegionConfig();

      ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMaxNodes(-1);
      ((LFUAlgorithmConfig) config.getEvictionAlgorithmConfig()).setMinNodes(10000);
      for (int i = 0; i < 10000; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, ADD_NODE_EVENT);
      }

      algo.process(region.getEvictionEventQueue());
      LFUQueue queue = (LFUQueue) algo.evictionQueue;

      long lastModifiedTimestamp = 0;
      for (NodeEntry ne : queue)
      {
         assertTrue(lastModifiedTimestamp <= ne.getModifiedTimeStamp());
         lastModifiedTimestamp = ne.getModifiedTimeStamp();
      }

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

      algo.process(region.getEvictionEventQueue());

      int count = 0;
      lastModifiedTimestamp = 0;
      for (NodeEntry ne : queue)
      {
View Full Code Here

TOP

Related Classes of org.jboss.cache.RegionImpl

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.