Package org.jboss.cache.interceptors

Examples of org.jboss.cache.interceptors.ActivationInterceptor


      assertNotNull("Cache is null.", cache);

      // Note: because these tests are normally executed without a server, the interceptor
      // MBeans are usually not available for use in the tests.  Consequently it's necessary
      // to obtain references to the interceptors and work with them directly.
      ActivationInterceptor act = TestingUtil.findInterceptor(cache, ActivationInterceptor.class);
      assertNotNull("ActivationInterceptor not found.", act);
      PassivationInterceptor pass = TestingUtil.findInterceptor(cache, PassivationInterceptor.class);
      assertNotNull("PassivationInterceptor not found.", pass);

      System.out.println("count of misses " + act.getCacheLoaderMisses());
      int miss = 5;
      int activations = 0;
      // was 5 in 1.3 (one per attribute)
      // now just Europe/Albania and Europe/Hungary were loaded

      // verify statistics for entries loaded into cache
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving a valid attribute and an invalid attribute
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + AUSTRIA, cache.get(AUSTRIA, AREA));

      // verify statistics after retrieving entries - no change since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving an attribute for an invalid node
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + POLAND, cache.get(POLAND, CAPITAL));

      // verify statistics after retrieving invalid node - misses should now be incremented
      miss++;
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now evict Austria and confirm that it's no longer in cache
      cache.evict(AUSTRIA, false);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));

      // passivations should noe be 1
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving the attributes again - first retrieval should trigger a cache load
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after retrieving evicted entry - loads and activations should now increment by 1
      activations++;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now remove Austria and confirm that it's not in cache or loader
      cache.removeNode(AUSTRIA);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));
      assertFalse("Retrieval error: did not expect to find node " + AUSTRIA + " in loader", cl.exists(AUSTRIA));

      // verify statistics after removing entry - should be unchanged
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving attributes again - each attempt should fail and cause a miss since node is now removed
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after trying to retrieve removed node's attributes - should be two more misses
      miss += 2;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      cache.put(POLAND, new HashMap<String, Object>());
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      miss++;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // evict Poland - this will cause a passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // retrieve a valid attribute - this will cause an activation and a load
      activations++;
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + POLAND, cache.get(POLAND, CURRENCY));
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // evict again - causing another passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // retrieve an invalid attribute - this will cause an activation and a load
      activations++;
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", 3, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // reset statistics
      act.resetStatistics();
      pass.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", 0, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());
   }
View Full Code Here


      assertNotNull("Cache is null.", cache);

      // Note: because these tests are normally executed without a server, the interceptor
      // MBeans are usually not available for use in the tests.  Consequently it's necessary
      // to obtain references to the interceptors and work with them directly.
      ActivationInterceptor act = TestingUtil.findInterceptor(cache, ActivationInterceptor.class);
      assertNotNull("ActivationInterceptor not found.", act);
      PassivationInterceptor pass = TestingUtil.findInterceptor(cache, PassivationInterceptor.class);
      assertNotNull("PassivationInterceptor not found.", pass);

      int miss = 5;
      int activations = 0;
      // was 5 in 1.3 (one per attribute)
      // now just Europe/Albania and Europe/Hungary were loaded

      // verify statistics for entries loaded into cache
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving a valid attribute and an invalid attribute
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + AUSTRIA, cache.get(AUSTRIA, AREA));

      // verify statistics after retrieving entries - no change since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving an attribute for an invalid node
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + POLAND, cache.get(POLAND, CAPITAL));

      // verify statistics after retrieving invalid node - misses should now be incremented
      miss++;
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now evict Austria and confirm that it's no longer in cache
      cache.evict(AUSTRIA, false);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));

      // passivations should noe be 1
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving the attributes again - first retrieval should trigger a cache load
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after retrieving evicted entry - loads and activations should now increment by 1
      activations+= 3;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now remove Austria and confirm that it's not in cache or loader
      cache.removeNode(AUSTRIA);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));
      assertFalse("Retrieval error: did not expect to find node " + AUSTRIA + " in loader", cl.exists(AUSTRIA));

      // verify statistics after removing entry - should be unchanged
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving attributes again - each attempt should fail and cause a miss since node is now removed
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after trying to retrieve removed node's attributes - should be two more misses
      miss += 2;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      cache.put(POLAND, new HashMap<String, Object>());
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      miss ++;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // evict Poland - this will cause a passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // retrieve a valid attribute - this will cause an activation and a load
      activations+=3;
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + POLAND, cache.get(POLAND, CURRENCY));
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // evict again - causing another passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // retrieve an invalid attribute - this will cause an activation and a load
      activations+=3;
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", 3, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // reset statistics
      act.resetStatistics();
      pass.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", 0, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());
   }
View Full Code Here

      loadCache(cache);     
      // Note: because these tests are normally executed without a server, the interceptor
      // MBeans are usually not available for use in the tests.  Consequently it's necessary
      // to obtain references to the interceptors and work with them directly.
      ActivationInterceptor act = getActivationInterceptor(cache);
      assertNotNull("ActivationInterceptor not found.", act);
      PassivationInterceptor pass = getPassivationInterceptor(cache);
      assertNotNull("PassivationInterceptor not found.", pass);

      System.out.println("count of misses " + act.getCacheLoaderMisses());
      int miss = 2;
      // was 5 in 1.3 (one per attribute)
      // now just Europe/Albania and Europe/Hungary were loaded
    
      // verify statistics for entries loaded into cache
      assertEquals("CacheLoaderLoads count error: ", new Long(0), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(0), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(0), new Long(pass.getPassivations()));
     
      // now try retrieving a valid attribute and an invalid attribute
      Fqn key = Fqn.fromString("Europe/Austria");
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + key, cache.get(key, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + key, cache.get(key, AREA));
     
      // verify statistics after retrieving entries - no change since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", new Long(0), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(0), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(0), new Long(pass.getPassivations()));
     
      // now try retrieving an attribute for an invalid node
      key = Fqn.fromString("Europe/Poland");
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + key, cache.get(key, CAPITAL));
     
      // verify statistics after retrieving invalid node - misses should now be incremented
      miss++;
      assertEquals("CacheLoaderLoads count error: ", new Long(0), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(0), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(0), new Long(pass.getPassivations()));
     
      // now evict Austria and confirm that it's no longer in cache
      key = Fqn.fromString("Europe/Austria");
      cache.evict(key);
      assertFalse("Retrieval error: did not expect to find node " + key + " in cache", cache.exists(key));
     
      // passivations should noe be 1
      assertEquals("Passivations count error: ", new Long(1), new Long(pass.getPassivations()));
     
      // now try retrieving the attributes again - first retrieval should trigger a cache load
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + key, cache.get(key, CAPITAL));
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
     
      // verify statistics after retrieving evicted entry - loads and activations should now be 1
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(1), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(1), new Long(pass.getPassivations()));
     
      // now remove Austria and confirm that it's not in cache or loader
      cache.remove(key);
      assertFalse("Retrieval error: did not expect to find node " + key + " in cache", cache.exists(key));
      assertFalse("Retrieval error: did not expect to find node " + key + " in loader", cl.exists(key));
     
      // verify statistics after removing entry - should be unchanged
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(1), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(1), new Long(pass.getPassivations()));
     
      // now try retrieving attributes again - each attempt should fail and cause a miss since node is now removed
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + key, cache.get(key, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
     
      // verify statistics after trying to retrieve removed node's attributes - should be two more misses
      miss += 2;
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(1), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(1), new Long(pass.getPassivations()));
     
      // add a new node and two attributes - this should cause a miss only
      miss++;
      cache.put("Europe/Poland", new HashMap());
      cache.put("Europe/Poland", CAPITAL, "Warsaw");
      cache.put("Europe/Poland", CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(1), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(1), new Long(pass.getPassivations()));
     
      // evict Poland - this will cause a passivation
      key = Fqn.fromString("Europe/Poland");
      cache.evict(key);
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(1), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(2), new Long(pass.getPassivations()));
     
      // retrieve a valid attribute - this will cause an activation and a load
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
      assertEquals("CacheLoaderLoads count error: ", new Long(2), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(2), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(2), new Long(pass.getPassivations()));
     
      // evict again - causing another passivation
      cache.evict(key);
      assertEquals("CacheLoaderLoads count error: ", new Long(2), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(2), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(3), new Long(pass.getPassivations()));
     
      // retrieve an invalid attribute - this will cause an activation and a load
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + key, cache.get(key, AREA));
      assertEquals("CacheLoaderLoads count error: ", new Long(3), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(3), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(3), new Long(pass.getPassivations()));
     
      // reset statistics
      act.resetStatistics();
      pass.resetStatistics();
    
      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", new Long(0), new Long(act.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error after reset: ", new Long(0), new Long(act.getCacheLoaderMisses()));
      assertEquals("Activations count error: ", new Long(0), new Long(act.getActivations()));
      assertEquals("Passivations count error: ", new Long(0), new Long(pass.getPassivations()));
   }
View Full Code Here

      assertNotNull("Cache is null.", cache);

      // Note: because these tests are normally executed without a server, the interceptor
      // MBeans are usually not available for use in the tests.  Consequently it's necessary
      // to obtain references to the interceptors and work with them directly.
      ActivationInterceptor act = TestingUtil.findInterceptor(cache, ActivationInterceptor.class);
      assertNotNull("ActivationInterceptor not found.", act);
      PassivationInterceptor pass = TestingUtil.findInterceptor(cache, PassivationInterceptor.class);
      assertNotNull("PassivationInterceptor not found.", pass);

      System.out.println("count of misses " + act.getCacheLoaderMisses());
      int miss = 0;
      int activations = 0;
      // was 5 in 1.3 (one per attribute)
      // now just Europe/Albania and Europe/Hungary were loaded

      // verify statistics for entries loaded into cache
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving a valid attribute and an invalid attribute
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      // will cause a load
      miss++;
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + AUSTRIA, cache.get(AUSTRIA, AREA));

      // verify statistics after retrieving entries - no change since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now try retrieving an attribute for an invalid node
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + POLAND, cache.get(POLAND, CAPITAL));

      // verify statistics after retrieving invalid node - misses should now be incremented
      miss++;
      assertEquals("CacheLoaderLoads count error: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());

      // now evict Austria and confirm that it's no longer in cache
      cache.evict(AUSTRIA, false);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));

      // passivations should noe be 1
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving the attributes again - first retrieval should trigger a cache load
      assertNotNull("Retrieval error: expected to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after retrieving evicted entry - loads and activations should now increment by 1
      activations++;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now remove Austria and confirm that it's not in cache or loader
      cache.removeNode(AUSTRIA);
      assertNull("Retrieval error: did not expect to find node " + AUSTRIA + " in cache", cache.peek(AUSTRIA, false));
      assertFalse("Retrieval error: did not expect to find node " + AUSTRIA + " in loader", cl.exists(AUSTRIA));

      // verify statistics after removing entry - should be unchanged
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // now try retrieving attributes again - each attempt should fail and cause a miss since node is now removed
      assertNull("Retrieval error: did not expect to retrieve " + CAPITAL + " for " + AUSTRIA, cache.get(AUSTRIA, CAPITAL));
      assertNull("Retrieval error: did not expect to retrieve " + CURRENCY + " for " + AUSTRIA, cache.get(AUSTRIA, CURRENCY));

      // verify statistics after trying to retrieve removed node's attributes - should be two more misses
      miss += 2;
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // add a new node and two attributes - this should cause a miss only
      miss++;
      cache.put(POLAND, new HashMap<String, Object>());
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 1, pass.getPassivations());

      // evict Poland - this will cause a passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 1, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // retrieve a valid attribute - this will cause an activation and a load
      activations++;
      assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + POLAND, cache.get(POLAND, CURRENCY));
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 2, pass.getPassivations());

      // evict again - causing another passivation
      cache.evict(POLAND, false);
      assertEquals("CacheLoaderLoads count error: ", 2, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // retrieve an invalid attribute - this will cause an activation and a load
      activations++;
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", 3, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", activations, act.getActivations());
      assertEquals("Passivations count error: ", 3, pass.getPassivations());

      // reset statistics
      act.resetStatistics();
      pass.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, act.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, act.getCacheLoaderMisses());
      assertEquals("Activations count error: ", 0, act.getActivations());
      assertEquals("Passivations count error: ", 0, pass.getPassivations());
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.interceptors.ActivationInterceptor

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.