[jbosscache-commits] JBoss Cache SVN: r5574 - in core/trunk/src: test/java/org/jboss/cache/passivation and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Apr 16 06:52:28 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-16 06:52:28 -0400 (Wed, 16 Apr 2008)
New Revision: 5574

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
   core/trunk/src/test/resources/META-INF/conf-test/local-passivation-service.xml
Log:
Fixed broken passivation/activation code

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java	2008-04-16 10:26:17 UTC (rev 5573)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java	2008-04-16 10:52:28 UTC (rev 5574)
@@ -4,7 +4,15 @@
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.Modification;
 import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.cachedata.*;
+import org.jboss.cache.commands.cachedata.GetChildrenNamesCommand;
+import org.jboss.cache.commands.cachedata.GetKeyValueCommand;
+import org.jboss.cache.commands.cachedata.GetKeysCommand;
+import org.jboss.cache.commands.cachedata.GetNodeCommand;
+import org.jboss.cache.commands.cachedata.PutDataMapCommand;
+import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
+import org.jboss.cache.commands.cachedata.RemoveDataCommand;
+import org.jboss.cache.commands.cachedata.RemoveKeyCommand;
+import org.jboss.cache.commands.cachedata.RemoveNodeCommand;
 import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
 import org.jboss.cache.commands.tx.PrepareCommand;
 import org.jboss.cache.commands.visitors.AbstractCommandsVisitor;
@@ -16,7 +24,12 @@
 
 import javax.transaction.SystemException;
 import javax.transaction.TransactionManager;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -49,7 +62,7 @@
    @Override
    public Object handleRemoveDataCommand(InvocationContext ctx, RemoveDataCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleRemoveDataCommand(ctx, command);
       if (trace)
          log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
       loader.removeData(command.getFqn());
@@ -59,7 +72,7 @@
    @Override
    public Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleRemoveNodeCommand(ctx, command);
       if (trace)
          log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
       loader.remove(command.getFqn());
@@ -69,7 +82,7 @@
    @Override
    public Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleGetChildrenNamesCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -77,7 +90,7 @@
    @Override
    public Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleGetKeysCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -85,7 +98,7 @@
    @Override
    public Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleGetNodeCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -93,7 +106,7 @@
    @Override
    public Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleGetKeyValueCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -101,7 +114,7 @@
    @Override
    public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handlePutKeyValueCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -109,7 +122,7 @@
    @Override
    public Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handlePutDataMapCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -117,7 +130,7 @@
    @Override
    public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
    {
-      Object returnValue = invokeNextInterceptor(ctx, command);
+      Object returnValue = super.handleRemoveKeyCommand(ctx, command);
       removeNodeFromCacheLoader(ctx, command.getFqn());
       return returnValue;
    }
@@ -142,7 +155,8 @@
                log.debug("children all initialized");
                remove(ctx, fqn);
             }
-         } else if (loaderNoChildren(fqn))
+         }
+         else if (loaderNoChildren(fqn))
          {
             if (log.isDebugEnabled()) log.debug("no children " + n);
             remove(ctx, fqn);
@@ -186,7 +200,7 @@
          activations++;
       }
    }
-                                    
+
    /**
     * Returns true if the loader indicates no children for this node.
     * Return false on error.
@@ -275,6 +289,7 @@
          handlePutCommand(ctx, fqn);
          return null;
       }
+
       // On the way out, remove the node from the cache loader.
       // Only remove the node if it exists in memory, its attributes have
       // been initialized, its children have been loaded

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java	2008-04-16 10:26:17 UTC (rev 5573)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java	2008-04-16 10:52:28 UTC (rev 5574)
@@ -6,9 +6,11 @@
 import org.jboss.cache.commands.cachedata.EvictNodeCommand;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
 import org.jboss.cache.interceptors.base.ChainedInterceptor;
 import org.jboss.cache.invocation.CacheData;
 import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
 import org.jboss.cache.notifications.Notifier;
 
 import java.util.Collections;
@@ -28,19 +30,27 @@
 
    private AtomicLong passivations = new AtomicLong(0);
 
-   protected CacheLoader loader = null;
+   private CacheLoader loader;
    private Notifier notifier;
    private Configuration configuration;
    private CacheData cacheData;
+   private CacheLoaderManager cacheLoaderManager;
 
    @Inject
-   public void setDependencies(Notifier notifier, Configuration configuration, CacheData cacheData)
+   public void setDependencies(Notifier notifier, Configuration configuration, CacheData cacheData, CacheLoaderManager cacheLoaderManager)
    {
       this.notifier = notifier;
       this.configuration = configuration;
       this.cacheData = cacheData;
+      this.cacheLoaderManager = cacheLoaderManager;
    }
 
+   @Start
+   public void startInterceptor()
+   {
+      loader = cacheLoaderManager.getCacheLoader();
+   }
+
    /**
     * Notifies the cache instance listeners that the evicted node is about to
     * be passivated and stores the evicted node and its attributes back to the

Modified: core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java	2008-04-16 10:26:17 UTC (rev 5573)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java	2008-04-16 10:52:28 UTC (rev 5574)
@@ -12,7 +12,6 @@
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 import org.jboss.cache.loader.DummyInMemoryCacheLoader;
 import org.jboss.cache.misc.TestingUtil;
 import org.jboss.cache.notifications.annotation.CacheListener;
@@ -59,7 +58,7 @@
 
    private void initCaches()
    {
-      CacheFactory<String, String> instance = new DefaultCacheFactory();
+      CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
       cache = (CacheSPI) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/conf-test/local-passivation-service.xml"), false);
       cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
       Object listener = new TestCacheListener();
@@ -78,30 +77,17 @@
    {
       activationCount = 0;
       passivationCount = 0;
-      Fqn fqn = Fqn.fromString(FQNSTR);
-      try
-      {
-         cache.put(fqn, FQNSTR, FQNSTR);
-      }
-      catch (Exception e)
-      {
-         fail("Failed to insert data" + e);
-         e.printStackTrace();
-      }
+
+      cache.put(FQNSTR, FQNSTR, FQNSTR);
+
       System.out.println(cache.toString());
-      TestingUtil.sleepThread(21000);
+      TestingUtil.sleepThread(2100);
       System.out.println(cache.toString());
-      try
-      {
-         assert !(cache.exists(FQNSTR) && cache.getNode(FQNSTR).getKeys().contains(FQNSTR));
-         Object val = cache.get(FQNSTR, FQNSTR);
-         assertNotNull("DataNode should not be empty ", val);
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace();
-         fail("Failed to get" + e);
-      }
+
+      assert !(cache.exists(FQNSTR) && cache.getNode(FQNSTR).getKeys().contains(FQNSTR)) : "Should have been evicted!!";
+      Object val = cache.get(FQNSTR, FQNSTR);
+      assertNotNull("DataNode should not be empty ", val);
+
       assertEquals("activation count:", 1, activationCount);
       assertEquals("passivation count:", 1, passivationCount);
    }

Modified: core/trunk/src/test/resources/META-INF/conf-test/local-passivation-service.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/conf-test/local-passivation-service.xml	2008-04-16 10:26:17 UTC (rev 5573)
+++ core/trunk/src/test/resources/META-INF/conf-test/local-passivation-service.xml	2008-04-16 10:52:28 UTC (rev 5574)
@@ -79,7 +79,7 @@
       <!-- Specific eviction policy configurations. This is LRU -->
       <attribute name="EvictionPolicyConfig">
          <config>
-            <attribute name="wakeUpIntervalSeconds">5</attribute>
+            <attribute name="wakeUpIntervalSeconds">1</attribute>
             <!-- This defaults to 200000 if not specified -->
             <attribute name="eventQueueSize">200000</attribute>
             <!-- Name of the DEFAULT eviction policy class. -->
@@ -89,11 +89,11 @@
             <!-- Cache wide default -->
             <region name="/_default_">
                <attribute name="maxNodes">5000</attribute>
-               <attribute name="timeToLiveSeconds">3</attribute>
+               <attribute name="timeToLiveSeconds">1</attribute>
             </region>
             <region name="/org/jboss/test/data">
                <attribute name="maxNodes">100</attribute>
-               <attribute name="timeToLiveSeconds">3</attribute>
+               <attribute name="timeToLiveSeconds">1</attribute>
             </region>
          </config>
       </attribute>




More information about the jbosscache-commits mailing list