[jbosscache-commits] JBoss Cache SVN: r4889 - in core/trunk/src: main/java/org/jboss/cache/invocation and 5 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Dec 19 22:11:40 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-19 22:11:39 -0500 (Wed, 19 Dec 2007)
New Revision: 4889

Added:
   core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
   core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
   core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
   core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
   core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
   core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
Log:
Cache loader and passivation bugs fixed

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -2772,50 +2772,6 @@
    }
 
    /**
-    * A 'clustered get' call, called from a remote ClusteredCacheLoader.
-    *
-    * @return a List containing 2 elements: (true or false) and a value (Object).  If buddy replication
-    *         is used one further element is added - an Fqn of the backup subtree in which this node may be found.
-    */
-   public List _clusteredGet(MethodCall methodCall, Boolean searchBackupSubtrees)
-   {
-      MethodCall call = methodCall;
-      if (log.isTraceEnabled()) log.trace("Clustered Get called with params: " + call + ", " + searchBackupSubtrees);
-      Method m = call.getMethod();
-      Object[] args = call.getArgs();
-
-      Object callResults = null;
-
-      try
-      {
-         Fqn fqn = (Fqn) args[0];
-
-         if (log.isTraceEnabled()) log.trace("Clustered get: invoking call " + m + " with Fqn " + fqn);
-         callResults = m.invoke(this, args);
-         boolean found = validResult(callResults, call, fqn);
-         if (log.isTraceEnabled()) log.trace("Got result " + callResults + ", found=" + found);
-         if (found && callResults == null) callResults = createEmptyResults(call);
-      }
-      catch (Exception e)
-      {
-         log.warn("Problems processing clusteredGet call", e);
-      }
-
-      List<Object> results = new ArrayList<Object>(2);
-      if (callResults != null)
-      {
-         results.add(true);
-         results.add(callResults);
-      }
-      else
-      {
-         results.add(false);
-         results.add(null);
-      }
-      return results;
-   }
-
-   /**
     * Used with buddy replication's data gravitation interceptor.  If marshalling is necessary, ensure that the cache is
     * configured to use {@link org.jboss.cache.config.Configuration#useRegionBasedMarshalling} and the {@link org.jboss.cache.Region}
     * pertaining to the Fqn passed in is activated, and has an appropriate ClassLoader.
@@ -2960,41 +2916,7 @@
    }
 
    // ------------- end: buddy replication specific 'lifecycle' method calls
-
-
    /**
-    * Returns true if the call results returned a valid result.
-    */
-   private boolean validResult(Object callResults, MethodCall mc, Fqn fqn)
-   {
-      switch (mc.getMethodId())
-      {
-         case MethodDeclarations.getDataMapMethodLocal_id:
-         case MethodDeclarations.getChildrenNamesMethodLocal_id:
-            return callResults != null || exists(fqn);
-         case MethodDeclarations.existsMethod_id:
-            return (Boolean) callResults;
-         default:
-            return false;
-      }
-   }
-
-   /**
-    * Creates an empty Collection class based on the return type of the method called.
-    */
-   private Object createEmptyResults(MethodCall mc)
-   {
-      switch (mc.getMethodId())
-      {
-         case MethodDeclarations.getDataMapMethodLocal_id:
-         case MethodDeclarations.getChildrenNamesMethodLocal_id:
-            return Collections.emptyMap();
-         default:
-            return null;
-      }
-   }
-
-   /**
     * Releases all locks for a FQN.
     */
    public void _releaseAllLocks(Fqn fqn)

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -1,10 +1,14 @@
 package org.jboss.cache.invocation;
 
 import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
 
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -69,4 +73,82 @@
       MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
       invoke(m, true);
    }
+
+   /**
+    * A 'clustered get' call, called from a remote ClusteredCacheLoader.
+    *
+    * @return a List containing 2 elements: (true or false) and a value (Object).  If buddy replication
+    *         is used one further element is added - an Fqn of the backup subtree in which this node may be found.
+    */
+   public List clusteredGet(MethodCall methodCall, Boolean searchBackupSubtrees)
+   {
+      if (log.isTraceEnabled())
+         log.trace("Clustered Get called with params: " + methodCall + ", " + searchBackupSubtrees);
+      Method m = methodCall.getMethod();
+      Object[] args = methodCall.getArgs();
+
+      Object callResults = null;
+
+      try
+      {
+         Fqn fqn = (Fqn) args[0];
+
+         if (log.isTraceEnabled()) log.trace("Clustered get: invoking call " + m + " with Fqn " + fqn);
+         callResults = m.invoke(cache, args);
+         boolean found = validResult(callResults, methodCall, fqn);
+         if (log.isTraceEnabled()) log.trace("Got result " + callResults + ", found=" + found);
+         if (found && callResults == null) callResults = createEmptyResults(methodCall);
+      }
+      catch (Exception e)
+      {
+         log.warn("Problems processing clusteredGet call", e);
+      }
+
+      List<Object> results = new ArrayList<Object>(2);
+      if (callResults != null)
+      {
+         results.add(true);
+         results.add(callResults);
+      }
+      else
+      {
+         results.add(false);
+         results.add(null);
+      }
+      return results;
+   }
+
+   /**
+    * Returns true if the call results returned a valid result.
+    */
+   private boolean validResult(Object callResults, MethodCall mc, Fqn fqn)
+   {
+      switch (mc.getMethodId())
+      {
+         case MethodDeclarations.getDataMapMethodLocal_id:
+         case MethodDeclarations.getChildrenNamesMethodLocal_id:
+            return callResults != null || exists(fqn);
+         case MethodDeclarations.existsMethod_id:
+            return (Boolean) callResults;
+         default:
+            return false;
+      }
+   }
+
+   /**
+    * Creates an empty Collection class based on the return type of the method called.
+    */
+   private Object createEmptyResults(MethodCall mc)
+   {
+      switch (mc.getMethodId())
+      {
+         case MethodDeclarations.getDataMapMethodLocal_id:
+         case MethodDeclarations.getChildrenNamesMethodLocal_id:
+            return Collections.emptyMap();
+         default:
+            return null;
+      }
+   }
+
+
 }

Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -352,10 +352,11 @@
    }
 
    /**
-    * Overrides generated cache loader with the one provided,for backward compat.
+    * Overrides generated cache loader with the one provided,for backward compat.  Deprecated, may not prote to all interceptors that need it.
     *
     * @param loader
     */
+   @Deprecated
    public void setCacheLoader(CacheLoader loader)
    {
       this.loader = loader;

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -267,7 +267,7 @@
 
          optimisticPrepareMethod = CacheImpl.class.getDeclaredMethod("optimisticPrepare", GlobalTransaction.class, List.class, Map.class, Address.class, boolean.class);
 
-         clusteredGetMethod = CacheImpl.class.getDeclaredMethod("_clusteredGet", MethodCall.class, Boolean.class);
+         clusteredGetMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("clusteredGet", MethodCall.class, Boolean.class);
 
          // ------------ buddy replication
 

Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -62,7 +62,7 @@
    }
 
    @Inject
-   private void injectDependencies(Cache cache)
+   private void injectDependencies(CacheSPI cache)
    {
       this.cache = cache;
    }

Modified: core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -20,7 +20,7 @@
  * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  */
 
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public abstract class AbstractCacheLoaderTestBase
 {
    protected final Log log = LogFactory.getLog(getClass());
@@ -38,17 +38,17 @@
    protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
    {
       String xml = "<config>\n" +
-              "<passivation>" + passivation + "</passivation>\n" +
-              "<preload>" + preload + "</preload>\n" +
-              "<cacheloader>\n" +
-              "<class>" + cacheloaderClass + "</class>\n" +
-              "<properties>" + properties + "</properties>\n" +
-              "<async>" + async + "</async>\n" +
-              "<shared>" + shared + "</shared>\n" +
-              "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
-              "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
-              "</cacheloader>\n" +
-              "</config>";
+            "<passivation>" + passivation + "</passivation>\n" +
+            "<preload>" + preload + "</preload>\n" +
+            "<cacheloader>\n" +
+            "<class>" + cacheloaderClass + "</class>\n" +
+            "<properties>" + properties + "</properties>\n" +
+            "<async>" + async + "</async>\n" +
+            "<shared>" + shared + "</shared>\n" +
+            "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
+            "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
+            "</cacheloader>\n" +
+            "</config>";
       Element element = XmlHelper.stringToElement(xml);
       return XmlConfigurationParser.parseCacheLoaderConfig(element);
    }

Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -20,16 +20,16 @@
 public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase
 {
    private CacheSPI cache;
-   private DummyCacheLoader dummyLoader;
+   private DummyCountingCacheLoader dummyLoader;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
       if (cache != null) tearDown();
       cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
-      cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, false));
+      cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, false));
       cache.start();
-      dummyLoader = (DummyCacheLoader) cache.getCacheLoaderManager().getCacheLoader();
+      dummyLoader = (DummyCountingCacheLoader) cache.getCacheLoaderManager().getCacheLoader();
    }
 
    @AfterMethod(alwaysRun = true)
@@ -62,7 +62,7 @@
       printReport("removeKey", dummyLoader);
    }
 
-   private void printReport(String test, DummyCacheLoader d)
+   private void printReport(String test, DummyCountingCacheLoader d)
    {
       System.out.println("------------------------------");
       System.out.println(" Test name: " + test);

Modified: core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -49,8 +49,8 @@
    public void setUp() throws Exception
    {
       if (cache1 != null || cache2 != null) tearDown();
-      cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
-      cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+      cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+      cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
 
       cache1.getConfiguration().setClusterName("CCL-Test");
       cache1.getConfiguration().setStateRetrievalTimeout(2000);

Modified: core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -6,7 +6,7 @@
  */
 package org.jboss.cache.loader;
 
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.config.CacheLoaderConfig;
 import org.jboss.cache.transaction.DummyTransactionManager;
@@ -14,6 +14,7 @@
 import static org.testng.AssertJUnit.assertNull;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -25,12 +26,13 @@
 import java.sql.SQLException;
 import java.util.Properties;
 
+ at Test(groups = "functional")
 public class DataSourceIntegrationTest extends AbstractCacheLoaderTestBase
 {
    private String old_factory = null;
    private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
    private final String JNDI_NAME = "java:/MockDS";
-   private CacheImpl cache;
+   private CacheSPI cache;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
@@ -65,7 +67,7 @@
       {
          // expected
       }
-      cache = (CacheImpl) new DefaultCacheFactory().createCache(false);
+      cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
       cache.getConfiguration().setCacheMode("local");
       cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
       cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(JNDI_NAME));

Copied: core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java (from rev 4826, core/trunk/src/test/java/org/jboss/cache/loader/DummyCacheLoader.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -0,0 +1,237 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.loader;
+
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Dummy cache loader that captures the number of times each method is called.  Stores statistics statically, mimicking
+ * a shared cache loader.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ */
+public class DummyCountingCacheLoader extends AbstractCacheLoader
+{
+   private static int getChildrenNamesCount = 0, getCount = 0, putCount = 0, existsCount = 0, removeCount = 0;
+
+   public int getGetChildrenNamesCount()
+   {
+      return getChildrenNamesCount;
+   }
+
+   public int getGetCount()
+   {
+      return getCount;
+   }
+
+   public int getPutCount()
+   {
+      return putCount;
+   }
+
+   public int getExistsCount()
+   {
+      return existsCount;
+   }
+
+   public int getRemoveCount()
+   {
+      return removeCount;
+   }
+
+
+   /**
+    * Sets the configuration. Will be called before {@link #create()} and {@link #start()}
+    */
+   public void setConfig(IndividualCacheLoaderConfig config)
+   {
+   }
+
+   public IndividualCacheLoaderConfig getConfig()
+   {
+      return null;
+   }
+
+   /**
+    * This method allows the CacheLoader to set the CacheImpl, therefore allowing the CacheLoader to invoke
+    * methods of the CacheImpl. It can also use the CacheImpl to fetch configuration information. Alternatively,
+    * the CacheLoader could maintain its own configuration<br/>
+    * This method will be called directly after the CacheLoader instance has been created
+    *
+    * @param c The cache on which this loader works
+    */
+   public void setCache(CacheImpl c)
+   {
+   }
+
+   /**
+    * Returns a list of children names, all names are <em>relative</em>. Returns null if the parent node is not found.
+    * The returned set must not be modified, e.g. use Collections.unmodifiableSet(s) to return the result
+    *
+    * @param fqn The FQN of the parent
+    * @return Set<String>. A list of children. Returns null if no children nodes are present, or the parent is
+    *         not present
+    */
+   public Set<String> getChildrenNames(Fqn fqn) throws Exception
+   {
+      getChildrenNamesCount++;
+      return null;
+   }
+
+   /**
+    * Returns the value for a given key. Returns null if the node doesn't exist, or the value is not bound
+    *
+    * @param name
+    * @return
+    * @throws Exception
+    */
+   public Object get(Fqn name, Object key) throws Exception
+   {
+      getCount++;
+      return null;
+   }
+
+   /**
+    * Returns all keys and values from the persistent store, given a fully qualified name
+    *
+    * @param name
+    * @return Map<Object,Object> of keys and values for the given node. Returns null if the node was not found, or
+    *         if the node has no attributes
+    * @throws Exception
+    */
+   public Map<Object, Object> get(Fqn name) throws Exception
+   {
+      getCount++;
+      return null;
+   }
+
+   /**
+    * Checks whether the CacheLoader has a node with Fqn
+    *
+    * @param name
+    * @return True if node exists, false otherwise
+    */
+   public boolean exists(Fqn name) throws Exception
+   {
+      existsCount++;
+      return false;
+   }
+
+   /**
+    * Inserts key and value into the attributes hashmap of the given node. If the node does not exist, all
+    * parent nodes from the root down are created automatically. Returns the old value
+    */
+   public Object put(Fqn name, Object key, Object value) throws Exception
+   {
+      putCount++;
+      return null;
+   }
+
+   /**
+    * Inserts all elements of attributes into the attributes hashmap of the given node, overwriting existing
+    * attributes, but not clearing the existing hashmap before insertion (making it a union of existing and
+    * new attributes)
+    * If the node does not exist, all parent nodes from the root down are created automatically
+    *
+    * @param name       The fully qualified name of the node
+    * @param attributes A Map of attributes. Can be null
+    */
+   public void put(Fqn name, Map attributes) throws Exception
+   {
+      putCount++;
+   }
+
+   /**
+    * Inserts all modifications to the backend store. Overwrite whatever is already in
+    * the datastore.
+    *
+    * @param modifications A List<Modification> of modifications
+    * @throws Exception
+    */
+   public void put(List<Modification> modifications) throws Exception
+   {
+      putCount++;
+   }
+
+   /**
+    * Removes the given key and value from the attributes of the given node. No-op if node doesn't exist
+    */
+   public Object remove(Fqn name, Object key) throws Exception
+   {
+      removeCount++;
+      return null;
+   }
+
+   /**
+    * Removes the given node. If the node is the root of a subtree, this will recursively remove all subnodes,
+    * depth-first
+    */
+   public void remove(Fqn name) throws Exception
+   {
+      removeCount++;
+   }
+
+   /**
+    * Removes all attributes from a given node, but doesn't delete the node itself
+    *
+    * @param name
+    * @throws Exception
+    */
+   public void removeData(Fqn name) throws Exception
+   {
+      removeCount++;
+   }
+
+   @Override
+   public void loadEntireState(ObjectOutputStream os) throws Exception
+   {
+      //intentional no-op
+   }
+
+   @Override
+   public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
+   {
+      // intentional no-op
+   }
+
+   @Override
+   public void storeEntireState(ObjectInputStream is) throws Exception
+   {
+      // intentional no-op
+   }
+
+   @Override
+   public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
+   {
+      // intentional no-op
+   }
+
+
+   @Override
+   public void destroy()
+   {
+      getChildrenNamesCount = 0;
+      getCount = 0;
+      putCount = 0;
+      existsCount = 0;
+      removeCount = 0;
+   }
+
+   public void scrubStats()
+   {
+      destroy();
+   }
+}
\ No newline at end of file


Property changes on: core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -1,7 +1,7 @@
 package org.jboss.cache.loader;
 
 import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.testng.annotations.AfterMethod;
@@ -13,7 +13,7 @@
 /**
  * To test the closing of JDBC connections
  */
- at Test(groups = {"functional"})
+ at Test(groups = "functional")
 public class JDBCCacheLoaderConnectionTest extends AbstractCacheLoaderTestBase
 {
    private Cache cache;
@@ -61,7 +61,7 @@
 
    private void assertConnectionsClosed() throws Exception
    {
-      JDBCCacheLoader loader = (JDBCCacheLoader) ((CacheImpl) cache).getCacheLoader();
+      JDBCCacheLoader loader = (JDBCCacheLoader) ((CacheSPI) cache).getCacheLoaderManager().getCacheLoader();
       NonManagedConnectionFactory cf = (NonManagedConnectionFactory) loader.cf;
       Connection conn = cf.connection.get();
       if (conn != null)

Modified: core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -13,6 +13,7 @@
 import static org.testng.AssertJUnit.assertEquals;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
 
 import java.util.Iterator;
 
@@ -21,37 +22,32 @@
  *
  * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
  */
+ at Test(groups = "functional")
 public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase
 {
    private CacheSPI<Object, Object> cache1, cache2;
-   private DummyCacheLoader dummyCacheLoader;
+   private DummyCountingCacheLoader dummyCacheLoader;
 
    @BeforeMethod(alwaysRun = true)
-   @SuppressWarnings("deprecation")
    public void setUp() throws Exception
    {
       if (cache1 != null || cache2 != null) tearDown();
 
       // set up 2 instances of CacheImpl with shared CacheLoaders.
-      cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
-      cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+      cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+      cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
 
       cache1.getConfiguration().setCacheMode("REPL_SYNC");
       cache2.getConfiguration().setCacheMode("REPL_SYNC");
 
-      cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
-      cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
+      cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, true));
+      cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, true));
 
       cache1.start();
       cache2.start();
 
-      // force setting up the same cache loader class
-//      dummyCacheLoader = new DummyCacheLoader();
-//
-//      cache1.setCacheLoader(dummyCacheLoader);
-//      cache2.setCacheLoader(dummyCacheLoader);
-//      findCacheStoreInterceptor(cache1).setCache(cache1);
-//      findCacheStoreInterceptor(cache2).setCache(cache2);
+      dummyCacheLoader = new DummyCountingCacheLoader(); // statistics are stored statically so this is safe.
+      dummyCacheLoader.scrubStats();
    }
 
    protected CacheStoreInterceptor findCacheStoreInterceptor(CacheSPI cache)

Modified: core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -7,8 +7,10 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.InterceptorChainFactory;
+import org.jboss.cache.interceptors.CacheLoaderInterceptor;
+import org.jboss.cache.interceptors.CacheStoreInterceptor;
 import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.reflect.ReflectionUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -20,8 +22,6 @@
 import java.util.Set;
 
 /**
- * //TODO: MANIK: Javadoc this class
- *
  * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  * @since 2.0.0
  */
@@ -47,8 +47,8 @@
       mockCacheLoader = EasyMock.createMock(CacheLoader.class);
 
       cache.getCacheLoaderManager().setCacheLoader(mockCacheLoader);
-      // re-set the cache so that the mock CL is registered with the inerceptors.
-      TestingUtil.extractComponentRegistry(cache).getComponent(InterceptorChainFactory.class).correctInterceptorChaining(cache.getInterceptorChain());
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class), "loader", mockCacheLoader);
+      ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class), "loader", mockCacheLoader);
 
       // lifecycle stuff
       mockCacheLoader.stop();

Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java	2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java	2007-12-20 03:11:39 UTC (rev 4889)
@@ -298,7 +298,6 @@
       keys = cache.getNode(Fqn.fromString("/a/b/c")).getKeys();
       assertNotNull(keys);
       assertEquals(1, keys.size());
-      keys.add("myKey");
    }
 
 
@@ -404,7 +403,7 @@
          {
             cache.put("/a/b/c", null);
          }
-         Set children = cache.getRoot().getChildrenNames();// get "null* node children names
+         Set children = cache.getChildrenNames((Fqn<String>) null);// get "null* node children names
          assertTrue(children.isEmpty());
       }
       catch (Exception e)
@@ -704,7 +703,7 @@
       cache.removeNode("/x");
       assertNull(cache.get(key, "keyA"));
       addDelay();
-      Set<Object> keys = cache.getNode(key).getKeys();
+      Set<Object> keys = cache.getKeys(key);
       assertNull(keys);
       cache.removeNode("/x");
    }




More information about the jbosscache-commits mailing list