[infinispan-commits] Infinispan SVN: r1033 - in trunk/core/src: test/java/org/infinispan/distribution and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Oct 27 11:45:58 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-10-27 11:45:57 -0400 (Tue, 27 Oct 2009)
New Revision: 1033

Modified:
   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/SingleOwnerTest.java
Log:
[ISPN-234] (Serialization exception thrown if objects in distibuted cache do not implement the serializiable interface) Handle Throwables other than Exceptions too, i.e. OutOfMemoryError.

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-27 15:40:05 UTC (rev 1032)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsResponseFilterAdapter.java	2009-10-27 15:45:57 UTC (rev 1033)
@@ -10,6 +10,7 @@
  * Acts as a bridge between JGroups RspFilter and {@link org.infinispan.remoting.rpc.ResponseFilter}.
  *
  * @author Manik Surtani
+ * @author Galder Zamarreño
  * @since 4.0
  */
 public class JGroupsResponseFilterAdapter implements RspFilter {
@@ -28,6 +29,8 @@
    public boolean isAcceptable(Object response, Address sender) {
       if (response instanceof Exception)
          response = new ExceptionResponse((Exception) response);
+      else if (response instanceof Throwable)
+         response = new ExceptionResponse(new RuntimeException((Throwable)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-27 15:40:05 UTC (rev 1032)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java	2009-10-27 15:45:57 UTC (rev 1033)
@@ -74,6 +74,7 @@
  * An encapsulation of a JGroups transport
  *
  * @author Manik Surtani
+ * @author Galder Zamarreño
  * @since 4.0
  */
 public class JGroupsTransport implements Transport, ExtendedMembershipListener, ExtendedMessageListener {
@@ -375,22 +376,26 @@
                }
             } else {
                noValidResponses = false;
-               if (rsp.getValue() != null) {
-                  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);
+               Object value = rsp.getValue();
+               if (value instanceof Response) {
+                  Response response = (Response) value;
+                  if (response 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;
+                     }
                   }
+                  retval.add(response);
+               } else if (value instanceof Exception) {
+                  Exception e = (Exception) value;
+                  if (trace) log.trace("Unexpected exception from " + rsp.getSender(), e);
+                  throw e;
+               } else if (value instanceof Throwable) {
+                  Throwable t = (Throwable) value;
+                  if (trace) log.trace("Unexpected throwable from " + rsp.getSender(), t);
+                  throw new CacheException("Remote (" + rsp.getSender() +") failed unexpectedly", t);
                }
             }
          }

Modified: trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	2009-10-27 15:40:05 UTC (rev 1032)
+++ trunk/core/src/test/java/org/infinispan/distribution/SingleOwnerTest.java	2009-10-27 15:45:57 UTC (rev 1033)
@@ -23,10 +23,15 @@
 package org.infinispan.distribution;
 
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.concurrent.TimeUnit;
 
 import org.infinispan.Cache;
+import org.infinispan.CacheException;
 import org.infinispan.config.Configuration;
 import org.infinispan.remoting.transport.Address;
 import org.infinispan.util.concurrent.IsolationLevel;
@@ -51,7 +56,7 @@
          // tests repeatedly queries changes
          configuration.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
       }
-      configuration.setSyncReplTimeout(360, TimeUnit.SECONDS);
+      configuration.setSyncReplTimeout(3, TimeUnit.SECONDS);
       configuration.setNumOwners(1);
       configuration.setLockAcquisitionTimeout(45, TimeUnit.SECONDS);
       caches = createClusteredCaches(2, cacheName, configuration);
@@ -72,7 +77,7 @@
       ownerCache.put("mykey", new Object());
    }
 
-   public void testRetrieveKeyFromNonOwner() {
+   public void testRetrieveNonSerializableKeyFromNonOwner() {
       Cache[] owners = getOwners("yourkey", 1);
       Cache[] nonOwners = getNonOwners("yourkey", 1);
       assert owners.length == 1;
@@ -87,4 +92,25 @@
       }
    }
 
+   public void testErrorWhenRetrievingKeyFromNonOwner() {
+      Cache[] owners = getOwners("diffkey", 1);
+      Cache[] nonOwners = getNonOwners("diffkey", 1);
+      assert owners.length == 1;
+      assert nonOwners.length == 1;
+      Cache ownerCache = owners[0];
+      Cache nonOwnerCache = nonOwners[0];
+      ownerCache.put("diffkey", new Externalizable() {
+         public void writeExternal(ObjectOutput out) throws IOException {
+            throw new UnknownError();
+         }
+         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+         }
+      });
+      try {
+         nonOwnerCache.get("diffkey");
+         assert false : "Should have failed with a CacheException that contains an UnknownError";
+      } catch (CacheException e) {
+         assert e.getCause() instanceof UnknownError;
+      }
+   }
 }



More information about the infinispan-commits mailing list