Package org.jboss.cache

Examples of org.jboss.cache.RegionImpl


      assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
   }

   public void testEvictionSortOrder() throws EvictionException
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);

      config.setMaxAge(1000000);
      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;
      while ((ne = queue.getFirstMaxAgeNodeEntry()) != null)
      {
         assertTrue(ne.getCreationTimeStamp() >= lastCreateTimestamp);
         lastCreateTimestamp = ne.getCreationTimeStamp();
View Full Code Here


      assertEquals(7, queue.getNumberOfNodes());
   }

   public void testMaxNodesAndMaxElements() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(10);
      config.setMaxElementsPerNode(100);

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

         }
      }

      algo.process(region.getEvictionEventQueue());

      ElementSizeQueue queue = (ElementSizeQueue) algo.evictionQueue;
      assertEquals(10, algo.getEvictionQueue().getNumberOfNodes());
      assertEquals(45, algo.getEvictionQueue().getNumberOfElements());
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

      algo = (ElementSizeAlgorithm) createAndAssignToRegion("/a/b", regionManager, config);
   }

   public void testMaxElements() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      ElementSizeAlgorithmConfig config = (ElementSizeAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(10);
      config.setMaxElementsPerNode(6);

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

      algo.process(region.getEvictionEventQueue());

      ElementSizeQueue queue = (ElementSizeQueue) algo.evictionQueue;
      assertEquals(9, algo.getEvictionQueue().getNumberOfNodes());
      assertEquals(12, algo.getEvictionQueue().getNumberOfElements());
      // now verify the order.
      int count = 6;
      for (NodeEntry ne : queue)
      {
         System.out.println(ne);

         if (count > 0)
         {
            assertEquals(count, ne.getNumberOfElements());
         }
         else
         {
            assertEquals(0, ne.getNumberOfElements());
         }
         count -= 2;
      }

      for (int i = 0; i < 7; i++)
      {
         region.registerEvictionEvent(Fqn.fromString("/a/b/9"), EvictionEvent.Type.ADD_ELEMENT_EVENT);
         region.registerEvictionEvent(Fqn.fromString("/a/b/7"), EvictionEvent.Type.ADD_ELEMENT_EVENT);
      }

      algo.process(region.getEvictionEventQueue());

      assertEquals(7, queue.getNumberOfNodes());
   }
View Full Code Here

  
   public void testMaxNode1()
   {
      Fqn fqn1 = Fqn.fromString("/a/b/c");
      Fqn fqn2 = Fqn.fromString("/a/b/d");
      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();
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)
      {
         System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " + ne.getNumberOfNodeVisits());
         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());
      System.out.println();
      System.out.println();

      int count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " + ne.getNumberOfNodeVisits());
         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());
      System.out.println();
      System.out.println();

      count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " + ne.getNumberOfNodeVisits());
         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());

      System.out.println();
      System.out.println();
      count = 0;
      for (NodeEntry ne : queue)
      {
         count++;
         System.out.println("Fqn: " + ne.getFqn() + " NodeVisits: " + ne.getNumberOfNodeVisits());
         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());

      System.out.println();
      System.out.println();
      count = 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.