[infinispan-commits] Infinispan SVN: r1014 - in trunk/core/src: main/java/org/infinispan/remoting/transport/jgroups and 1 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Oct 26 12:59:53 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-10-26 12:59:52 -0400 (Mon, 26 Oct 2009)
New Revision: 1014

Added:
   trunk/core/src/main/java/org/infinispan/marshall/NotSerializableException.java
Modified:
   trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java
   trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsResponseFilterAdapter.java
   trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java
   trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java
Log:
[ISPN-234] (Serialization exception thrown if objects in distibuted cache do not implement the serializiable interface) Fixed ClassCastException and wrapped NotSerializableException instances into our own NotSerializableException exception that only shows information about the object that couldn't be serialized. Trace level log still shows full stacktrace in case needed for debugging.

Added: trunk/core/src/main/java/org/infinispan/marshall/NotSerializableException.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/NotSerializableException.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/marshall/NotSerializableException.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.marshall;
+
+import org.infinispan.CacheException;
+
+/**
+ * An exception that hides inner stacktrace lines for non serializable exceptions.
+ * 
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public class NotSerializableException extends CacheException {
+
+   public NotSerializableException(String message, Throwable cause) {
+      super(message, cause);
+   }
+
+   @Override
+   public void setStackTrace(StackTraceElement[] stackTrace) {
+      // nothing
+   }
+
+   public Throwable fillInStackTrace() {
+      // no operation
+      return this;
+   }
+
+}

Modified: trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java	2009-10-26 16:39:10 UTC (rev 1013)
+++ trunk/core/src/main/java/org/infinispan/marshall/VersionAwareMarshaller.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -34,6 +34,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.NotSerializableException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.io.OutputStream;
@@ -88,6 +89,12 @@
       ObjectOutput out = startObjectOutput(baos, false);
       try {
          defaultMarshaller.objectToObjectStream(obj, out);
+      } catch(NotSerializableException nse) {
+         if (log.isTraceEnabled()) log.trace("Object is not serializable", nse);
+         throw new org.infinispan.marshall.NotSerializableException(nse.getMessage(), nse.getCause());
+      } catch(IOException ioe) {
+         if (log.isTraceEnabled()) log.trace("Exception while marshalling object", ioe);
+         throw ioe;
       } finally {
          finishObjectOutput(out);
       }

Modified: trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsResponseFilterAdapter.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsResponseFilterAdapter.java	2009-10-26 16:39:10 UTC (rev 1013)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsResponseFilterAdapter.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -1,6 +1,7 @@
 package org.infinispan.remoting.transport.jgroups;
 
 import org.infinispan.remoting.rpc.ResponseFilter;
+import org.infinispan.remoting.responses.ExceptionResponse;
 import org.infinispan.remoting.responses.Response;
 import org.jgroups.Address;
 import org.jgroups.blocks.RspFilter;
@@ -25,6 +26,9 @@
    }
 
    public boolean isAcceptable(Object response, Address sender) {
+      if (response instanceof Exception)
+         response = new ExceptionResponse((Exception) response);
+
       return r.isAcceptable((Response) response, new JGroupsAddress(sender));
    }
 

Modified: trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java	2009-10-26 16:39:10 UTC (rev 1013)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -376,16 +376,21 @@
             } else {
                noValidResponses = false;
                if (rsp.getValue() != null) {
-                  Response value = (Response) rsp.getValue();
-                  if (value instanceof ExceptionResponse) {
-                     Exception e = ((ExceptionResponse) value).getException();
-                     if (!(e instanceof ReplicationException)) {
-                        // if we have any application-level exceptions make sure we throw them!!
-                        if (trace) log.trace("Received exception from " + rsp.getSender(), e);
-                        throw e;
-                     }
+                  Object value = rsp.getValue();
+                  Exception e = null;
+                  if (value instanceof Exception)
+                     e = (Exception) value;
+                  if (value instanceof ExceptionResponse)
+                     e = ((ExceptionResponse) value).getException();
+                  
+                  if (e != null && !(e instanceof ReplicationException)) {
+                     // if we have any application-level exceptions make sure we throw them!!
+                     if (trace) log.trace("Received exception from " + rsp.getSender(), e);
+                     throw e;
+                  } else {
+                     Response response = (Response) rsp.getValue();
+                     retval.add(response);
                   }
-                  retval.add(value);
                }
             }
          }

Modified: trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-26 16:39:10 UTC (rev 1013)
+++ trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -258,7 +258,11 @@
    }
 
    protected Cache<Object, String>[] getNonOwners(Object key) {
-      Cache<Object, String>[] nonOwners = new Cache[2];
+      return getNonOwners(key, 2);
+   }
+
+   protected Cache<Object, String>[] getNonOwners(Object key, int expectedNumberNonOwners) {
+      Cache<Object, String>[] nonOwners = new Cache[expectedNumberNonOwners];
       int i = 0;
       for (Cache<Object, String> c : caches) {
          if (!isOwner(c, key)) nonOwners[i++] = c;

Modified: trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	2009-10-26 16:39:10 UTC (rev 1013)
+++ trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	2009-10-26 16:59:52 UTC (rev 1014)
@@ -33,7 +33,7 @@
 import org.testng.annotations.Test;
 
 /**
- * Ispn234Test.
+ * Test single owner distributed cache configurations.
  * 
  * @author Galder Zamarreño
  * @since 4.0
@@ -51,7 +51,7 @@
          // tests repeatedly queries changes
          configuration.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
       }
-      configuration.setSyncReplTimeout(60, TimeUnit.SECONDS);
+      configuration.setSyncReplTimeout(360, TimeUnit.SECONDS);
       configuration.setNumOwners(1);
       configuration.setLockAcquisitionTimeout(45, TimeUnit.SECONDS);
       caches = createClusteredCaches(2, cacheName, configuration);
@@ -72,4 +72,19 @@
       ownerCache.put("mykey", new Object());
    }
 
+   public void testRetrieveKeyFromNonOwner() {
+      Cache[] owners = getOwners("yourkey", 1);
+      Cache[] nonOwners = getNonOwners("yourkey", 1);
+      assert owners.length == 1;
+      assert nonOwners.length == 1;
+      Cache ownerCache = owners[0];
+      Cache nonOwnerCache = nonOwners[0];
+      ownerCache.put("yourkey", new Object());
+      try {
+         nonOwnerCache.get("yourkey");
+         assert false : "Should have failed with a org.infinispan.marshall.NotSerializableException";
+      } catch (org.infinispan.marshall.NotSerializableException e) {
+      }
+   }
+
 }



More information about the infinispan-commits mailing list