[jbosscache-commits] JBoss Cache SVN: r5189 - in core/trunk/src: main/java/org/jboss/cache/loader and 8 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Jan 22 08:30:37 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-01-22 08:30:36 -0500 (Tue, 22 Jan 2008)
New Revision: 5189

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
   core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
   core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValue.java
   core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java
   core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
   core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
   core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplMarshalledValuesTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java
   core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java
   core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
Log:
JBCACHE-1231 - Implicit MarshalledValues

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MarshalledValueInterceptor.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -3,9 +3,11 @@
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.marshall.MarshalledValue;
 import org.jboss.cache.marshall.MarshalledValueHelper;
+import org.jboss.cache.marshall.MarshalledValueMap;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodDeclarations;
 
+import java.io.NotSerializableException;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -74,8 +76,14 @@
          if (retVal instanceof MarshalledValue)
          {
             if (trace) log.trace("Return value is a MarshalledValue.  Unwrapping.");
-            return ((MarshalledValue) retVal).get();
+            retVal = ((MarshalledValue) retVal).get();
          }
+         else if (retVal instanceof Map && call.getMethodId() == MethodDeclarations.getDataMapMethodLocal_id)
+         {
+            if (trace) log.trace("Return value is a Map and we're retrieving data.  Wrapping as a MarshalledValueMap.");
+            Map retValMap = (Map) retVal;
+            if (!retValMap.isEmpty()) retVal = new MarshalledValueMap(retValMap);
+         }
       }
 
       return retVal;
@@ -99,7 +107,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   protected Map wrapMap(Map m, Set<MarshalledValue> marshalledValues, InvocationContext ctx)
+   protected Map wrapMap(Map m, Set<MarshalledValue> marshalledValues, InvocationContext ctx) throws NotSerializableException
    {
       Map copy = new HashMap();
       for (Object key : m.keySet())
@@ -111,7 +119,7 @@
       return copy;
    }
 
-   protected MarshalledValue createAndAddMarshalledValue(Object toWrap, Set<MarshalledValue> marshalledValues, InvocationContext ctx)
+   protected MarshalledValue createAndAddMarshalledValue(Object toWrap, Set<MarshalledValue> marshalledValues, InvocationContext ctx) throws NotSerializableException
    {
       MarshalledValue mv = new MarshalledValue(toWrap);
       marshalledValues.add(mv);

Modified: core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/loader/TcpDelegatingCacheLoader.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -22,7 +22,6 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.Socket;
-import java.net.SocketException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -115,11 +114,12 @@
          }
          catch (InvocationTargetException e)
          {
-            if (e.getCause() instanceof SocketException)
+            if (e.getCause() instanceof IOException)
             {
                try
                {
                   // sleep 250 ms
+                  if (log.isDebugEnabled()) log.debug("Caught IOException.  Retrying.", e);
                   Thread.sleep(config.getReconnectWaitTime());
                   restart();
                }
@@ -132,6 +132,10 @@
                   // do nothing
                }
             }
+            else
+            {
+               throw new CacheException("Problems invoking method call!", e);
+            }
          }
       } while (System.currentTimeMillis() < endTime);
       throw new CacheException("Unable to communicate with TCPCacheServer(" + config.getHost() + ":" + config.getPort() + ") after " + config.getTimeout() + " millis, with reconnects every " + config.getReconnectWaitTime() + " millis.");

Modified: core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -334,7 +334,7 @@
                         output.writeObject(null);
                         break;
                      }
-                     Map map = n.getDataDirect();
+                     Map map = n.getData();
                      if (map == null) map = new HashMap();
                      output.writeObject(map);
                      break;

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValue.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValue.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -25,14 +25,14 @@
    // by default equals() will test on the istance rather than the byte array if conversion is required.
    private transient boolean equalityPreferenceForInstance = true;
 
-   public MarshalledValue(Object instance)
+   public MarshalledValue(Object instance) throws NotSerializableException
    {
       if (instance == null) throw new NullPointerException("Null values cannot be wrapped as MarshalledValues!");
 
       if (instance instanceof Serializable)
          this.instance = instance;
       else
-         throw new CacheException(new NotSerializableException("Marshalled values can only wrap Objects that are serializable!  Instance of " + instance.getClass() + " won't Serialize."));
+         throw new NotSerializableException("Marshalled values can only wrap Objects that are serializable!  Instance of " + instance.getClass() + " won't Serialize.");
    }
 
    public MarshalledValue()
@@ -63,8 +63,7 @@
          }
          catch (Exception e)
          {
-            throw new
-                  CacheException("Unable to marshall value " + instance);
+            throw new CacheException("Unable to marshall value " + instance, e);
          }
       }
    }

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -3,13 +3,13 @@
 import net.jcip.annotations.Immutable;
 import org.jboss.cache.CacheException;
 
+import java.io.Externalizable;
 import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -25,23 +25,26 @@
  * @since 2.1.0
  */
 @Immutable
-public class MarshalledValueMap implements Map
+public class MarshalledValueMap implements Map, Externalizable
 {
    Map delegate;
-   Map<Object, MarshalledValue> marshalledValues;
+   Map<Object, Object> unmarshalled;
 
+   public MarshalledValueMap()
+   {
+      // for externalization
+   }
+
    public MarshalledValueMap(Map delegate)
    {
       this.delegate = delegate;
    }
 
-   protected MarshalledValue getMarshalledValue(Object o)
+   @SuppressWarnings("unchecked")
+   protected synchronized Map getUnmarshalledMap()
    {
-      if (marshalledValues == null) marshalledValues = new HashMap<Object, MarshalledValue>();
-      if (marshalledValues.containsKey(o)) return marshalledValues.get(o);
-      MarshalledValue mv = new MarshalledValue(o);
-      marshalledValues.put(o, mv);
-      return mv;
+      if (unmarshalled == null) unmarshalled = unmarshalledMap(delegate.entrySet());
+      return unmarshalled;
    }
 
    public int size()
@@ -56,50 +59,17 @@
 
    public boolean containsKey(Object key)
    {
-      if (MarshalledValueHelper.excludeFromMarshalledValueWrapping(key))
-      {
-         return delegate.containsKey(key);
-      }
-      else
-      {
-         return delegate.containsKey(getMarshalledValue(key));
-      }
+      return getUnmarshalledMap().containsKey(key);
    }
 
    public boolean containsValue(Object value)
    {
-      if (MarshalledValueHelper.excludeFromMarshalledValueWrapping(value))
-      {
-         return delegate.containsValue(value);
-      }
-      else
-      {
-         return delegate.containsValue(getMarshalledValue(value));
-      }
+      return getUnmarshalledMap().containsValue(value);
    }
 
    public Object get(Object key)
    {
-      Object retVal;
-      if (MarshalledValueHelper.excludeFromMarshalledValueWrapping(key))
-      {
-         retVal = delegate.get(key);
-      }
-      else
-      {
-         retVal = delegate.get(getMarshalledValue(key));
-      }
-
-      if (retVal instanceof MarshalledValue) try
-      {
-         retVal = ((MarshalledValue) retVal).get();
-      }
-      catch (Exception e)
-      {
-         throw new CacheException("Unable to unmarshall MarshalledValue", e);
-      }
-
-      return retVal;
+      return getUnmarshalledMap().get(key);
    }
 
    public Object put(Object key, Object value)
@@ -124,59 +94,67 @@
 
    public Set keySet()
    {
-      try
-      {
-         return unmarshallSet(delegate.keySet());
-      }
-      catch (Exception e)
-      {
-         throw new CacheException("Unable to unmarshall MarshalledValues in collection", e);
-      }
+      return getUnmarshalledMap().keySet();
    }
 
    public Collection values()
    {
-      try
+      return getUnmarshalledMap().values();
+   }
+
+   public Set entrySet()
+   {
+      return getUnmarshalledMap().entrySet();
+   }
+
+   @SuppressWarnings("unchecked")
+   protected Map unmarshalledMap(Set entries)
+   {
+      if (entries == null || entries.isEmpty()) return Collections.emptyMap();
+      Map map = new HashMap(entries.size());
+      for (Object e : entries)
       {
-         return unmarshallList(delegate.values());
+         Map.Entry entry = (Map.Entry) e;
+         map.put(getUnmarshalledValue(entry.getKey()), getUnmarshalledValue(entry.getValue()));
       }
-      catch (Exception e)
-      {
-         throw new CacheException("Unable to unmarshall MarshalledValues in collection", e);
-      }
+      return map;
    }
 
-   public Set entrySet()
+   private Object getUnmarshalledValue(Object o)
    {
       try
       {
-         return unmarshallSet(delegate.entrySet());
+         return o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o;
       }
       catch (Exception e)
       {
-         throw new CacheException("Unable to unmarshall MarshalledValues in collection", e);
+         throw new CacheException("Unable to unmarshall value", e);
       }
    }
 
-   @SuppressWarnings("unchecked")
-   protected Set unmarshallSet(Set set) throws IOException, ClassNotFoundException
+   @Override
+   public boolean equals(Object other)
    {
-      Set newSet = new HashSet();
-      for (Object o : set)
+      if (other instanceof Map)
       {
-         newSet.add(o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o);
+         return getUnmarshalledMap().equals(other);
       }
-      return Collections.unmodifiableSet(newSet);
+      return false;
    }
 
-   @SuppressWarnings("unchecked")
-   protected List unmarshallList(Collection c) throws IOException, ClassNotFoundException
+   @Override
+   public int hashCode()
    {
-      List newList = new LinkedList();
-      for (Object o : c)
-      {
-         newList.add(o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o);
-      }
-      return Collections.unmodifiableList(newList);
+      return getUnmarshalledMap().hashCode();
    }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeObject(delegate);
+   }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      delegate = (Map) in.readObject();
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -635,6 +635,8 @@
 
    private static Map copy(Map data)
    {
+      if (data == null) return null;
+      if (data.isEmpty()) return Collections.emptyMap();
       if (safe(data)) return new MarshalledValueMap(data);
       return new MarshalledValueMap(new MapCopy(data));
    }

Modified: core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -54,14 +54,14 @@
    public void testInjectionAtHead()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       Interceptor x = new TestInterceptor();
       cache.addInterceptor(x, 0);
 
       interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 7 interceptors", 8, interceptors.size());
+      assertEquals("Expecting 9 interceptors", 9, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       assertEquals(x, interceptors.get(0));
@@ -70,30 +70,30 @@
    public void testInjectionAtTail()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       Interceptor x = new TestInterceptor();
-      cache.addInterceptor(x, 6);
+      cache.addInterceptor(x, 8);
 
       interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 7 interceptors", 8, interceptors.size());
+      assertEquals("Expecting 9 interceptors", 9, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
-      assertEquals(x, interceptors.get(6));
+      assertEquals(x, interceptors.get(8));
    }
 
    public void testInjectionInMiddle()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       Interceptor x = new TestInterceptor();
       cache.addInterceptor(x, 3);
 
       interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 7 interceptors", 8, interceptors.size());
+      assertEquals("Expecting 9 interceptors", 9, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       assertEquals(x, interceptors.get(3));
@@ -102,13 +102,13 @@
    public void testInjectionBeyondTail()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       Interceptor x = new TestInterceptor();
       try
       {
-         cache.addInterceptor(x, 8);
+         cache.addInterceptor(x, 9);
          fail("Should throw an exception");
       }
       catch (IndexOutOfBoundsException e)
@@ -121,13 +121,13 @@
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
       Interceptor afterHead = interceptors.get(1);
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       cache.removeInterceptor(0);
 
       interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 5 interceptors", 6, interceptors.size());
+      assertEquals("Expecting 7 interceptors", 7, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       assertEquals(afterHead, interceptors.get(0));
@@ -137,7 +137,7 @@
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
       Interceptor beforeTail = interceptors.get(4);
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       cache.removeInterceptor(5);
@@ -146,7 +146,7 @@
 
       System.out.println(interceptors);
 
-      assertEquals("Expecting 5 interceptors", 6, interceptors.size());
+      assertEquals("Expecting 7 interceptors", 7, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       assertEquals(beforeTail, interceptors.get(4));
@@ -155,25 +155,25 @@
    public void testRemoveAtMiddle()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       cache.removeInterceptor(3);
 
       interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 5 interceptors", 6, interceptors.size());
+      assertEquals("Expecting 7 interceptors", 7, interceptors.size());
       assertInterceptorLinkage(interceptors);
    }
 
    public void testRemoveBeyondTail()
    {
       List<Interceptor> interceptors = cache.getInterceptorChain();
-      assertEquals("Expecting 6 interceptors", 7, interceptors.size());
+      assertEquals("Expecting 8 interceptors", 8, interceptors.size());
       assertInterceptorLinkage(interceptors);
 
       try
       {
-         cache.removeInterceptor(8);
+         cache.removeInterceptor(9);
          fail("Should throw an exception");
       }
       catch (IndexOutOfBoundsException e)

Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheLoaderTest.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -93,9 +93,6 @@
       cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
             TcpDelegatingCacheLoader.class.getName(),
             "host=127.0.0.1\nport=12121\ntimeout=" + TCP_CACHE_LOADER_TIMEOUT_MS, false, true, false));
-
-      // give the tcp cache server time to start up
-      //TestingUtil.sleepThread(2000);
    }
 
    // restart tests

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplMarshalledValuesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplMarshalledValuesTest.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplMarshalledValuesTest.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -1,13 +1,22 @@
 package org.jboss.cache.marshall;
 
+import org.testng.annotations.Test;
+
 /**
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
+ at Test(groups = {"functional", "jgroups"})
 public class AsyncReplMarshalledValuesTest extends AsyncReplTest
 {
    public AsyncReplMarshalledValuesTest()
    {
       useMarshalledValues = true;
    }
+
+   @Override
+   public void testCustomFqn()
+   {
+      // don't test this case
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -38,7 +38,7 @@
  * @author Ben Wang
  * @version $Revision$
  */
- at Test(groups = {"functional", "jgroups", "transaction"})
+ at Test(groups = {"functional", "jgroups"})
 public class AsyncReplTest extends RegionBasedMarshallingTestBase
 {
    CacheSPI<Object, Object> cache1, cache2;
@@ -85,18 +85,8 @@
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
-      cache1.removeNode(Fqn.ROOT);
-      if (cache1 != null)
-      {
-         log("stopping cache1");
-         cache1.stop();
-      }
-
-      if (cache2 != null)
-      {
-         log("stopping cache2");
-         cache2.stop();
-      }
+      TestingUtil.killCaches(cache1, cache2);
+      resetContextClassLoader();
    }
 
    /**
@@ -107,73 +97,77 @@
    public void testCLSet2() throws Exception
    {
       ClassLoader cla = getClassLoader();
+      ClassLoader clb = getClassLoader();
 
-      Region existing = cache1.getRegion(aop, false);
-      if (existing == null)
+      if (!useMarshalledValues)
       {
-         existing = cache1.getRegion(aop, true);
-      }
-      existing.registerContextClassLoader(cla);
-
-
-      ClassLoader clb = getClassLoader();
-      existing = cache2.getRegion(aop, false);
-      if (existing == null)
-      {
+         Region existing = cache1.getRegion(aop, true);
+         existing.registerContextClassLoader(cla);
          existing = cache2.getRegion(aop, true);
+         existing.registerContextClassLoader(clb);
       }
-      existing.registerContextClassLoader(clb);
 
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
       cache1.put(aop, "person", ben_);
       cache1.put(new Fqn<String>("alias"), "person", ben_);
+      if (useMarshalledValues) resetContextClassLoader();
 
       TestingUtil.sleepThread(1000);
       Object ben2 = null;
       // Can't cast it to Person. CCE will resutl.
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
       ben2 = cache2.get(aop, "person");
+      if (useMarshalledValues) resetContextClassLoader();
       assertNotNull(ben2);
       assertEquals(ben_.toString(), ben2.toString());
 
       Class<?> claz = clb.loadClass(ADDRESS_CLASSNAME);
       Object add = claz.newInstance();
-      Class<?>[] types = {String.class};
-      Method setValue = claz.getMethod("setCity", types);
-      Object[] margs = {"Sunnyvale"};
-      setValue.invoke(add, margs);
+      Method setValue = claz.getMethod("setCity", String.class);
+      setValue.invoke(add, "Sunnyvale");
       Class<?> clasz1 = clb.loadClass(PERSON_CLASSNAME);
-      types = new Class[]{claz};
-      setValue = clasz1.getMethod("setAddress", types);
-      margs = new Object[]{add};
-      setValue.invoke(ben2, margs);
+      setValue = clasz1.getMethod("setAddress", claz);
+      setValue.invoke(ben2, add);
 
       // Set it back to the cache
       // Can't cast it to Person. CCE will resutl.
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
       cache2.put(aop, "person", ben2);
+      if (useMarshalledValues) resetContextClassLoader();
       TestingUtil.sleepThread(1000);
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
       Object ben3 = cache1.get(aop, "person");
+      if (useMarshalledValues) resetContextClassLoader();
       assertEquals(ben2.toString(), ben3.toString());
    }
 
    public void testPuts() throws Exception
    {
-      ClassLoader cl = getClassLoader();
-      Region r1 = cache1.getRegion(aop, false) == null ? cache1.getRegion(aop, true) : cache1.getRegion(aop, false);
-      r1.registerContextClassLoader(cl);
+      ClassLoader cla = getClassLoader();
+      ClassLoader clb = getClassLoader();
+
+      if (!useMarshalledValues)
+      {
+         Region r1 = cache1.getRegion(aop, false) == null ? cache1.getRegion(aop, true) : cache1.getRegion(aop, false);
+         r1.registerContextClassLoader(cla);
+         Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
+         r2.registerContextClassLoader(clb);
+      }
+
       // Create an empty Person loaded by this classloader
-      Object scopedBen1 = getPersonFromClassloader(cl);
-
-      cl = getClassLoader();
-      Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
-      r2.registerContextClassLoader(cl);
+      Object scopedBen1 = getPersonFromClassloader(cla);
       // Create another empty Person loaded by this classloader
-      Object scopedBen2 = getPersonFromClassloader(cl);
+      Object scopedBen2 = getPersonFromClassloader(clb);
 
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
       cache1.put(Fqn.fromString("/aop/1"), "person", ben_);
       cache1.put(Fqn.fromString("/aop/2"), "person", scopedBen1);
+      if (useMarshalledValues) resetContextClassLoader();
       TestingUtil.sleepThread(1000);
 
       Object ben2 = null;
       // Can't cast it to Person. CCE will resutl.
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
       ben2 = cache2.get(Fqn.fromString("/aop/1"), "person");
       assertEquals(ben_.toString(), ben2.toString());
 
@@ -198,39 +192,48 @@
    public void testTxCLSet2() throws Exception
    {
       ClassLoader cla = getClassLoader();
-      Region r1 = cache1.getRegion(aop, false) == null ? cache1.getRegion(aop, true) : cache1.getRegion(aop, false);
-      r1.registerContextClassLoader(cla);
       ClassLoader clb = getClassLoader();
-      Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
-      r2.registerContextClassLoader(clb);
 
+      if (!useMarshalledValues)
+      {
+         Region r1 = cache1.getRegion(aop, false) == null ? cache1.getRegion(aop, true) : cache1.getRegion(aop, false);
+         r1.registerContextClassLoader(cla);
+         Region r2 = cache2.getRegion(aop, false) == null ? cache2.getRegion(aop, true) : cache2.getRegion(aop, false);
+         r2.registerContextClassLoader(clb);
+      }
+
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
       beginTransaction();
       cache1.put(aop, "person", ben_);
       commit();
+      if (useMarshalledValues) resetContextClassLoader();
+
       TestingUtil.sleepThread(1000);
 
       Object ben2 = null;
       // Can't cast it to Person. CCE will resutl.
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
       ben2 = cache2.get(aop, "person");
+      if (useMarshalledValues) resetContextClassLoader();
       assertEquals(ben_.toString(), ben2.toString());
 
       Class<?> claz = clb.loadClass(ADDRESS_CLASSNAME);
       Object add = claz.newInstance();
-      Class<?>[] types = {String.class};
-      Method setValue = claz.getMethod("setCity", types);
-      Object[] margs = {"Sunnyvale"};
-      setValue.invoke(add, margs);
+      Method setValue = claz.getMethod("setCity", String.class);
+      setValue.invoke(add, "Sunnyvale");
       Class<?> clasz1 = clb.loadClass(PERSON_CLASSNAME);
-      types = new Class[]{claz};
-      setValue = clasz1.getMethod("setAddress", types);
-      margs = new Object[]{add};
-      setValue.invoke(ben2, margs);
+      setValue = clasz1.getMethod("setAddress", claz);
+      setValue.invoke(ben2, add);
 
       // Set it back to the cache
       // Can't cast it to Person. CCE will resutl.
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
       cache2.put(aop, "person", ben2);
+      if (useMarshalledValues) resetContextClassLoader();
       TestingUtil.sleepThread(1000);
+      if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
       Object ben3 = cache1.get(aop, "person");
+      if (useMarshalledValues) resetContextClassLoader();
       assertEquals(ben2.toString(), ben3.toString());
    }
 

Modified: core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -123,16 +123,12 @@
          }
          else
          {
-            fail("should have received NotSerializableException, but received " + t.getClass());
+            throw runtime;
          }
       }
-      catch (Exception exc)
-      {
-         fail("failure - we should not get here: " + exc);
-      }
    }
 
-   public void testNonSerizlableReplWithTx() throws Exception
+   public void testNonSerializableReplWithTx() throws Exception
    {
       TransactionManager tm;
 

Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java	2008-01-22 10:59:59 UTC (rev 5188)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java	2008-01-22 13:30:36 UTC (rev 5189)
@@ -15,6 +15,7 @@
 import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.factories.XmlConfigurationParser;
 import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.marshall.MarshalledValue;
 import org.jboss.cache.misc.TestingUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.Test;
@@ -396,12 +397,17 @@
 
       r.activate();
 
-      assertEquals("Correct state from loader for /a/b", ben.toString(), loader.get(A_B).get("person").toString());
+      assertEquals("Correct state from loader for /a/b", ben.toString(), getUnmarshalled(loader.get(A_B).get("person")).toString());
 
-      assertEquals("Correct state from cache for /a/b", ben.toString(), cache2.get(A_B, "person").toString());
+      assertEquals("Correct state from cache for /a/b", ben.toString(), getUnmarshalled(cache2.get(A_B, "person")).toString());
 
    }
 
+   private Object getUnmarshalled(Object o) throws Exception
+   {
+      return o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o;
+   }
+
    public void testStalePersistentState() throws Exception
    {
       CacheSPI c1 = createCache("1", true, false, true, false);




More information about the jbosscache-commits mailing list