[infinispan-commits] Infinispan SVN: r2445 - in branches/4.2.x/core/src: test/java/org/infinispan/eviction and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Sep 28 11:07:55 EDT 2010


Author: vblagojevic at jboss.com
Date: 2010-09-28 11:07:55 -0400 (Tue, 28 Sep 2010)
New Revision: 2445

Modified:
   branches/4.2.x/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java
   branches/4.2.x/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java
Log:
[ISPN-674] - Eviction notification throws NPE

Modified: branches/4.2.x/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java	2010-09-27 19:34:54 UTC (rev 2444)
+++ branches/4.2.x/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java	2010-09-28 15:07:55 UTC (rev 2445)
@@ -139,12 +139,13 @@
    
    @Override
    public void preEvict(Object key) {
+      InvocationContext context = getInvocationContext();
       try {
-         acquireLock(getInvocationContext(), key);
+         acquireLock(context, key);
       } catch (Exception e) {
          log.warn("Could not acquire lock for eviction of {0}", key, e);
       }
-      cacheNotifier.notifyCacheEntryEvicted(key, true, null);
+      cacheNotifier.notifyCacheEntryEvicted(key, true, context);
    }
 
    @Override
@@ -154,7 +155,7 @@
       } catch (CacheLoaderException e) {
          log.warn("Unable to passivate entry under {0}", key, e);
       }
-      cacheNotifier.notifyCacheEntryEvicted(key, false, null);
+      cacheNotifier.notifyCacheEntryEvicted(key, false, getInvocationContext());
       releaseLock(key);
    }
    

Modified: branches/4.2.x/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java
===================================================================
--- branches/4.2.x/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java	2010-09-27 19:34:54 UTC (rev 2444)
+++ branches/4.2.x/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java	2010-09-28 15:07:55 UTC (rev 2445)
@@ -2,9 +2,14 @@
 
 import java.util.Random;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import org.infinispan.config.Configuration;
 import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted;
+import org.infinispan.notifications.cachelistener.event.CacheEntryEvictedEvent;
+import org.infinispan.notifications.cachelistener.event.Event;
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
 import org.testng.annotations.Test;
@@ -28,9 +33,27 @@
       cfg.setUseLockStriping(false); // to minimize chances of deadlock in the unit test
       EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(cfg);
       cache = cm.getCache();
+      cache.addListener(new EvictionListener());
       return cm;
    }
 
+   public void testSimpleEvictionMaxEntries() throws Exception {
+      for (int i = 0; i < 512; i++) {
+         cache.put("key-" + (i + 1), "value-" + (i + 1), 1, TimeUnit.MINUTES);
+      }
+      Thread.sleep(1000); // sleep long enough to allow the thread to wake-up
+      assert CACHE_SIZE >= cache.size() : "cache size too big: " + cache.size();
+   }
+
+   public void testSimpleExpirationMaxIdle() throws Exception {
+
+      for (int i = 0; i < 512; i++) {
+         cache.put("key-" + (i + 1), "value-" + (i + 1), 1, TimeUnit.MILLISECONDS);
+      }
+      Thread.sleep(1000); // sleep long enough to allow the thread to wake-up and purge all expired entries
+      assert 0 == cache.size() : "cache size should be zero: " + cache.size();
+   }
+
    public void testMultiThreaded() throws InterruptedException {
       int NUM_THREADS = 20;
       Writer[] w = new Writer[NUM_THREADS];
@@ -82,8 +105,26 @@
             } catch (InterruptedException e) {
                // ignore
             }
-            cache.put("key" + r.nextInt(), "value");
+            
+            //mix mortal and immortal entries 
+            if (Math.random() < 0.5) {
+               cache.put("key" + r.nextInt(), "value");
+            } else {
+               cache.put("key" + r.nextInt(), "value", 10, TimeUnit.SECONDS);
+            }
          }
       }
    }
+   
+   @Listener
+   public class EvictionListener {
+      
+      @CacheEntryEvicted
+      public void nodeEvicted(CacheEntryEvictedEvent e){
+         assert e.isPre() || !e.isPre();
+         assert e.getKey() != null;
+         assert e.getCache() != null;
+         assert e.getType() == Event.Type.CACHE_ENTRY_EVICTED;         
+      }
+   }
 }



More information about the infinispan-commits mailing list