Package org.jboss.cache

Examples of org.jboss.cache.RegionImpl


      c = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, true);
      additionalConfiguration(c);
      Cache<Object, Object> cache2 = new UnitTestCacheFactory<Object, Object>().createCache(c);
      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();
      int i = 0;
      int events = nodeEventQueueSize;
      while (events > 0)
      {
         System.out.println(++i + ") Queue contains : " + region.getEvictionEventQueue().poll(0, TimeUnit.MILLISECONDS));
         events = region.getEvictionEventQueue().size();
      }
      boolean mvcc = cache2.getConfiguration().getNodeLockingScheme() == NodeLockingScheme.MVCC;
      assertEquals("Saw the expected number of node events", mvcc ? 5 : 3, nodeEventQueueSize);
   }
View Full Code Here


   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(100);
      config.setMaxAge(300);
      region.registerEvictionEvent(fqn1, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, EvictionEvent.Type.ADD_NODE_EVENT);
      region.registerEvictionEvent(fqn2, EvictionEvent.Type.REMOVE_NODE_EVENT);

      algorithm.process(region.getEvictionEventQueue());

      EvictionQueue eq = algorithm.getEvictionQueue();
      int numNodesInQueue = eq.getNumberOfNodes();
      assert 1 == numNodesInQueue : "Queue size #1: expected 1 but was " + numNodesInQueue;

      // make sure existing events all time out
      TestingUtil.sleepThread(110);
      region.registerEvictionEvent(fqn3, EvictionEvent.Type.ADD_NODE_EVENT);

      algorithm.process(region.getEvictionEventQueue());

      numNodesInQueue = eq.getNumberOfNodes();
      assert 1 == numNodesInQueue : "Queue size #2: expected 1 but was " + numNodesInQueue;

      TestingUtil.sleepThread(310);
      region.registerEvictionEvent(fqn3, EvictionEvent.Type.VISIT_NODE_EVENT);

      algorithm.process(region.getEvictionEventQueue());

      numNodesInQueue = eq.getNumberOfNodes();
      assert 0 == numNodesInQueue : "Queue size #3: expected 0 but was " + numNodesInQueue;
   }
View Full Code Here

      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

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

   public void testMaxNodes1() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(5);

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

      algo.process(region.getEvictionEventQueue());
      FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
      assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());

      // now verify the order.
      int index = 3;
      for (NodeEntry ne : queue)
      {
         String fqn = ne.getFqn().toString();
         assertTrue(fqn.endsWith("/" + Integer.toString(index)));
         index++;
      }

      // now verify the same order still exists after visiting the nodes.
      for (int i = 3; i < 8; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
      }
      for (int i = 3; i < 5; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
      }

      algo.process(region.getEvictionEventQueue());

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

      index = 3;
      for (NodeEntry ne : queue)
View Full Code Here

      }
   }

   public void testMaxNodes2() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(500);

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

      algo.process(region.getEvictionEventQueue());
      FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
      assertEquals(500, algo.getEvictionQueue().getNumberOfNodes());

      int index = 0;
      for (NodeEntry ne : queue)
      {
         assertTrue(ne.getFqn().toString().endsWith("/" + Integer.toString(index)));
         index++;
      }

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

      algo.process(region.getEvictionEventQueue());

      index = 100;
      for (NodeEntry ne : queue)
      {
         assertTrue(ne.getFqn().toString().endsWith("/" + Integer.toString(index)));
View Full Code Here

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

   public void testMaxNodes1() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(5);

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

      algo.process(region.getEvictionEventQueue());
      FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
      assertEquals(5, algo.getEvictionQueue().getNumberOfNodes());

      // now verify the order.
      int index = 3;
      for (NodeEntry ne : queue)
      {
         String fqn = ne.getFqn().toString();
         assertTrue(fqn.endsWith("/" + Integer.toString(index)));
         index++;
      }

      // now verify the same order still exists after visiting the nodes.
      for (int i = 3; i < 8; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
      }
      for (int i = 3; i < 5; i++)
      {
         Fqn fqn = Fqn.fromString("/a/b/" + Integer.toString(i));
         region.registerEvictionEvent(fqn, EvictionEvent.Type.VISIT_NODE_EVENT);
      }

      algo.process(region.getEvictionEventQueue());

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

      index = 3;
      for (NodeEntry ne : queue)
View Full Code Here

      }
   }

   public void testMaxNodes2() throws Exception
   {
      RegionImpl region = (RegionImpl) regionManager.getRegion("/a/b", true);
      FIFOAlgorithmConfig config = (FIFOAlgorithmConfig) region.getEvictionRegionConfig().getEvictionAlgorithmConfig();
      config.setMaxNodes(500);

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

      algo.process(region.getEvictionEventQueue());
      FIFOQueue queue = (FIFOQueue) algo.evictionQueue;
      assertEquals(500, algo.getEvictionQueue().getNumberOfNodes());

      int index = 0;
      for (NodeEntry ne : queue)
      {
         assertTrue(ne.getFqn().toString().endsWith("/" + Integer.toString(index)));
         index++;
      }

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

      algo.process(region.getEvictionEventQueue());

      index = 100;
      for (NodeEntry ne : queue)
      {
         assertTrue(ne.getFqn().toString().endsWith("/" + Integer.toString(index)));
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)
      {
         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

      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 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

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.