Package org.jboss.cache.interceptors

Examples of org.jboss.cache.interceptors.CacheStoreInterceptor


   }

   protected CacheStoreInterceptor findCacheStoreInterceptor(CacheSPI cache)
   {
      Iterator ints = cache.getInterceptorChain().iterator();
      CacheStoreInterceptor csi = null;
      while (ints.hasNext())
      {
         CommandInterceptor i = (CommandInterceptor) ints.next();
         if (i instanceof CacheStoreInterceptor)
         {
View Full Code Here


      // 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.
      CacheLoaderInterceptor loader = TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class);
      assertNotNull("CacheLoaderInterceptor not found.", loader);
      CacheStoreInterceptor store = TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class);
      assertNotNull("CacheStoreInterceptor not found.", store);

      // verify cache loader statistics for entries loaded into cache
      int miss = 5;
      int load = 0;
      int stores = 5;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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 - misses should still be same since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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 for after retrieving entries - misses should now be +1 after attempt to load Poland
      miss++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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));

      // now try retrieving its 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 should now be +1
      load++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add a new node - this should cause a store
      stores++;
      miss++;
      cache.put(POLAND, new HashMap<String, Object>());
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add two attributes - this should cause two stores
      stores += 2;
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // evict Poland and then try to retrieve an invalid attribute - this will cause a load as the node is restored
      load++;
      cache.evict(POLAND, false);
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // reset statistics
      loader.resetStatistics();
      store.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error after reset: ", 0, store.getCacheLoaderStores());
   }
View Full Code Here

      // 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.
      CacheLoaderInterceptor loader = TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class);
      assertNotNull("CacheLoaderInterceptor not found.", loader);
      CacheStoreInterceptor store = TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class);
      assertNotNull("CacheStoreInterceptor not found.", store);

      // verify cache loader statistics for entries loaded into cache
      int miss = 5;
      int load = 0;
      int stores = 5;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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 - misses should still be same since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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 for after retrieving entries - misses should now be +1 after attempt to load Poland
      miss++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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));

      // now try retrieving its 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 should now be +1
      load++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add a new node - this should cause a store
      stores++;
      miss++;
      cache.put(POLAND, new HashMap<String, Object>());
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add two attributes - this should cause two stores
      stores += 2;
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // evict Poland and then try to retrieve an invalid attribute - this will cause a load as the node is restored
      load++;
      cache.evict(POLAND, false);
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // reset statistics
      loader.resetStatistics();
      store.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error after reset: ", 0, store.getCacheLoaderStores());
   }
View Full Code Here

   }

   protected CacheStoreInterceptor findCacheStoreInterceptor(CacheSPI cache)
   {
      Iterator ints = cache.getInterceptorChain().iterator();
      CacheStoreInterceptor csi = null;
      while (ints.hasNext())
      {
         CommandInterceptor i = (CommandInterceptor) ints.next();
         if (i instanceof CacheStoreInterceptor)
         {
View Full Code Here

    }

    protected CacheStoreInterceptor findCacheStoreInterceptor(TreeCache cache)
    {
        Iterator ints = cache.getInterceptors().iterator();
        CacheStoreInterceptor csi = null;
        while (ints.hasNext())
        {
            Interceptor i = (Interceptor) ints.next();
            if (i instanceof CacheStoreInterceptor)
            {
View Full Code Here

      // 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.
      CacheLoaderInterceptor loader = getCacheLoaderInterceptor(cache);
      assertNotNull("CacheLoaderInterceptor not found.", loader);
      CacheStoreInterceptor store = getCacheStoreInterceptor(cache);
      assertNotNull("CacheStoreInterceptor not found.", store);
    
      // verify cache loader statistics for entries loaded into cache
      int miss = 0;
      int load = 0;
      int stores = 11;
      assertEquals("CacheLoaderLoads count error: ", new Long(0), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // 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 - misses should still be same since nodes were already loaded
      load++;
      assertEquals("CacheLoaderLoads count error: ", new Long(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // 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 for after retrieving entries - misses should now be +1 after attempt to load Poland
      miss++;
      assertEquals("CacheLoaderLoads count error: ", new Long(1), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // 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));
     
      // now try retrieving its 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 should now be +1
      load++;
      assertEquals("CacheLoaderLoads count error: ", new Long(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // 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(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // 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(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // add a new node - this should cause a store
      stores++;
      cache.put("Europe/Poland", new HashMap());
      assertEquals("CacheLoaderLoads count error: ", new Long(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // add two attributes - this should cause two stores
      stores+=2;
      cache.put("Europe/Poland", CAPITAL, "Warsaw");
      cache.put("Europe/Poland", CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", new Long(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // evict Poland and then try to retrieve an invalid attribute - this will cause a load as the node is restored
      load++;
      key = Fqn.fromString("Europe/Poland");
      cache.evict(key);
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + key, cache.get(key, AREA));
      assertEquals("CacheLoaderLoads count error: ", new Long(load), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error: ", new Long(miss), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error: ", new Long(stores), new Long(store.getCacheLoaderStores()));
     
      // reset statistics
      loader.resetStatistics();
      store.resetStatistics();
    
      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", new Long(0), new Long(loader.getCacheLoaderLoads()));
      assertEquals("CacheLoaderMisses count error after reset: ", new Long(0), new Long(loader.getCacheLoaderMisses()));
      assertEquals("CacheLoaderStores count error after reset: ", new Long(0), new Long(store.getCacheLoaderStores()));
   }
View Full Code Here

   }

   protected CacheStoreInterceptor findCacheStoreInterceptor(CacheSPI cache)
   {
      Iterator ints = cache.getInterceptorChain().iterator();
      CacheStoreInterceptor csi = null;
      while (ints.hasNext())
      {
         Interceptor i = (Interceptor) ints.next();
         if (i instanceof CacheStoreInterceptor)
         {
View Full Code Here

      // 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.
      CacheLoaderInterceptor loader = TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class);
      assertNotNull("CacheLoaderInterceptor not found.", loader);
      CacheStoreInterceptor store = TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class);
      assertNotNull("CacheStoreInterceptor not found.", store);

      // verify cache loader statistics for entries loaded into cache
      int miss = 0;
      int load = 0;
      int stores = 5;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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));
      load++; // since we did a get on a non-existent key which triggered a load

      // verify statistics after retrieving entries - misses should still be same since nodes were already loaded
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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 for after retrieving entries - misses should now be +1 after attempt to load Poland
      miss++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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));

      // now try retrieving its 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 should now be +1
      load++;
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // 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: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add a new node - this should cause a store
      stores++;
      cache.put(POLAND, new HashMap<String, Object>());
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // add two attributes - this should cause two stores
      // plus one load as we're doing put(k, v)
      stores += 2;
      load++;
      cache.put(POLAND, CAPITAL, "Warsaw");
      cache.put(POLAND, CURRENCY, "Zloty");
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // evict Poland and then try to retrieve an invalid attribute - this will cause a load as the node is restored
      load++;
      cache.evict(POLAND, false);
      assertNull("Retrieval error: did not expect to retrieve " + AREA + " for " + POLAND, cache.get(POLAND, AREA));
      assertEquals("CacheLoaderLoads count error: ", load, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error: ", miss, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error: ", stores, store.getCacheLoaderStores());

      // reset statistics
      loader.resetStatistics();
      store.resetStatistics();

      // check the statistics again
      assertEquals("CacheLoaderLoads count error after reset: ", 0, loader.getCacheLoaderLoads());
      assertEquals("CacheLoaderMisses count error after reset: ", 0, loader.getCacheLoaderMisses());
      assertEquals("CacheLoaderStores count error after reset: ", 0, store.getCacheLoaderStores());
   }
View Full Code Here

TOP

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

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.