[infinispan-commits] Infinispan SVN: r777 - in trunk/core/src: test/java/org/infinispan/remoting and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Sep 4 09:16:21 EDT 2009
Author: galder.zamarreno at jboss.com
Date: 2009-09-04 09:16:20 -0400 (Fri, 04 Sep 2009)
New Revision: 777
Added:
trunk/core/src/test/java/org/infinispan/remoting/SingleClusterMemberTransportInvokeTest.java
trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java
Removed:
trunk/core/src/test/java/org/infinispan/remoting/TransportInvokeTest.java
Modified:
trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/CommandAwareRpcDispatcher.java
trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java
Log:
[ISPN-176] (Unmarshalling errors leading to ClassCastException in sender) Fixed by wrapping Throwable into an CacheException that is passed as an ExceptionResponse to the sender.
Modified: trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/CommandAwareRpcDispatcher.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/CommandAwareRpcDispatcher.java 2009-09-04 10:05:04 UTC (rev 776)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/CommandAwareRpcDispatcher.java 2009-09-04 13:16:20 UTC (rev 777)
@@ -1,8 +1,9 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * Copyright 2008, 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
@@ -25,6 +26,7 @@
import org.infinispan.commands.ReplicableCommand;
import org.infinispan.commands.remote.CacheRpcCommand;
import org.infinispan.remoting.InboundInvocationHandler;
+import org.infinispan.remoting.responses.ExceptionResponse;
import org.infinispan.remoting.responses.ExtendedResponse;
import org.infinispan.remoting.responses.RequestIgnoredResponse;
import org.infinispan.remoting.responses.Response;
@@ -140,7 +142,7 @@
}
catch (Throwable x) {
if (trace) log.trace("Problems invoking command.", x);
- return x;
+ return new ExceptionResponse(new CacheException("Problems invoking command.", x));
}
} else {
return null;
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-09-04 10:05:04 UTC (rev 776)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java 2009-09-04 13:16:20 UTC (rev 777)
@@ -1,3 +1,25 @@
+/*
+ * 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.remoting.transport.jgroups;
import org.infinispan.CacheException;
@@ -511,4 +533,10 @@
}
return retval;
}
+
+ // mainly for unit testing
+ public CommandAwareRpcDispatcher getCommandAwareRpcDispatcher() {
+ return dispatcher;
+ }
+
}
Copied: trunk/core/src/test/java/org/infinispan/remoting/SingleClusterMemberTransportInvokeTest.java (from rev 716, trunk/core/src/test/java/org/infinispan/remoting/TransportInvokeTest.java)
===================================================================
--- trunk/core/src/test/java/org/infinispan/remoting/SingleClusterMemberTransportInvokeTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/remoting/SingleClusterMemberTransportInvokeTest.java 2009-09-04 13:16:20 UTC (rev 777)
@@ -0,0 +1,73 @@
+/*
+ * 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.remoting;
+
+import static org.easymock.EasyMock.*;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.remoting.rpc.RpcManager;
+import org.infinispan.remoting.rpc.RpcManagerImpl;
+import org.infinispan.remoting.transport.Address;
+import org.infinispan.remoting.transport.Transport;
+import org.infinispan.test.MultipleCacheManagersTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+ at Test(groups = "functional", testName = "remoting.SingleClusterMemberTransportInvokeTest")
+public class SingleClusterMemberTransportInvokeTest extends MultipleCacheManagersTest {
+ final String key = "k", value = "v", value2 = "v2";
+ Cache cache1;
+
+ @Override
+ protected void createCacheManagers() throws Throwable {
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ createClusteredCaches(1, "replSync", c);
+ cache1 = cache(0, "replSync");
+ }
+
+ public void testInvokeRemotelyWhenSingleMember() throws Exception {
+ Transport mockTransport = createMock(Transport.class);
+ RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
+ Transport originalTransport = TestingUtil.extractComponent(cache1, Transport.class);
+ try {
+ Address mockAddress1 = createNiceMock(Address.class);
+ List<Address> memberList = new ArrayList<Address>(1);
+ memberList.add(mockAddress1);
+ expect(mockTransport.getMembers()).andReturn(memberList).anyTimes();
+ expect(mockTransport.getAddress()).andReturn(null).anyTimes();
+ rpcManager.setTransport(mockTransport);
+ // Transport invoke remote should not be called.
+ replay(mockAddress1, mockTransport);
+ // now try a simple replication. Since the RpcManager is a mock object it will not actually replicate anything.
+ cache1.put(key, value);
+ verify(mockTransport);
+ } finally {
+ if (rpcManager != null) rpcManager.setTransport(originalTransport);
+ }
+ }
+}
Deleted: trunk/core/src/test/java/org/infinispan/remoting/TransportInvokeTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/remoting/TransportInvokeTest.java 2009-09-04 10:05:04 UTC (rev 776)
+++ trunk/core/src/test/java/org/infinispan/remoting/TransportInvokeTest.java 2009-09-04 13:16:20 UTC (rev 777)
@@ -1,86 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, 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.remoting;
-
-import static org.easymock.EasyMock.*;
-import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.remoting.rpc.RpcManager;
-import org.infinispan.remoting.rpc.RpcManagerImpl;
-import org.infinispan.remoting.transport.Address;
-import org.infinispan.remoting.transport.Transport;
-import org.infinispan.test.MultipleCacheManagersTest;
-import org.infinispan.test.ReplListener;
-import org.infinispan.test.TestingUtil;
-import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
-import org.testng.annotations.Test;
-
-import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * TransportInvokeTest.
- *
- * @author Galder Zamarreño
- * @since 4.0
- */
- at Test(groups = "functional", testName = "remoting.TransportInvokeTest")
-public class TransportInvokeTest extends MultipleCacheManagersTest {
- final String key = "k", value = "v", value2 = "v2";
- Cache cache1;
- TransactionManager tm1;
- ReplListener replListener1;
-
- @Override
- protected void createCacheManagers() throws Throwable {
- Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
- c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- createClusteredCaches(1, "replSync", c);
- cache1 = cache(0, "replSync");
- tm1 = TestingUtil.getTransactionManager(cache1);
- replListener1 = replListener(cache1);
- }
-
- public void testInvokeRemotelyWhenSingleMember() throws Exception {
- Transport mockTransport = createMock(Transport.class);
- RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
- Transport originalTransport = TestingUtil.extractComponent(cache1, Transport.class);
- try {
-
- Address mockAddress1 = createNiceMock(Address.class);
- List<Address> memberList = new ArrayList<Address>(1);
- memberList.add(mockAddress1);
- expect(mockTransport.getMembers()).andReturn(memberList).anyTimes();
- expect(mockTransport.getAddress()).andReturn(null).anyTimes();
- rpcManager.setTransport(mockTransport);
- // Transport invoke remote should not be called.
- replay(mockAddress1, mockTransport);
- // now try a simple replication. Since the RpcManager is a mock object it will not actually replicate anything.
- cache1.put(key, value);
- verify(mockTransport);
-
- } finally {
- if (rpcManager != null) rpcManager.setTransport(originalTransport);
- }
- }
-}
Added: trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java 2009-09-04 13:16:20 UTC (rev 777)
@@ -0,0 +1,89 @@
+/*
+ * 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.remoting;
+
+import static org.easymock.EasyMock.*;
+
+import java.io.EOFException;
+
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.commands.remote.SingleRpcCommand;
+import org.infinispan.commands.write.PutKeyValueCommand;
+import org.infinispan.config.Configuration;
+import org.infinispan.remoting.transport.Transport;
+import org.infinispan.remoting.transport.jgroups.CommandAwareRpcDispatcher;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+import org.infinispan.test.MultipleCacheManagersTest;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
+import org.jgroups.blocks.RpcDispatcher.Marshaller2;
+import org.testng.annotations.Test;
+
+ at Test(groups = "functional", testName = "remoting.TransportSenderExceptionHandlingTest")
+public class TransportSenderExceptionHandlingTest extends MultipleCacheManagersTest {
+ final String key = "k-illyria", value = "v-illyria", value2 = "v2-illyria";
+ Cache cache1;
+ Cache cache2;
+
+ @Override
+ protected void createCacheManagers() throws Throwable {
+ Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ createClusteredCaches(2, "replSync", c);
+ cache1 = cache(0, "replSync");
+ cache2 = cache(1, "replSync");
+ }
+
+ public void testInvokeAndExceptionWhileUnmarshalling() throws Exception {
+ JGroupsTransport transport1 = (JGroupsTransport) TestingUtil.extractComponent(cache1, Transport.class);
+ CommandAwareRpcDispatcher dispatcher1 = transport1.getCommandAwareRpcDispatcher();
+ Marshaller2 originalMarshaller1 = (Marshaller2) dispatcher1.getMarshaller();
+ JGroupsTransport transport2 = (JGroupsTransport) TestingUtil.extractComponent(cache2, Transport.class);
+ CommandAwareRpcDispatcher dispatcher2 = transport2.getCommandAwareRpcDispatcher();
+ Marshaller2 originalMarshaller2 = (Marshaller2) dispatcher2.getMarshaller();
+ try {
+ Marshaller2 mockMarshaller1 = createMock(Marshaller2.class);
+ Marshaller2 mockMarshaller2 = createMock(Marshaller2.class);
+ PutKeyValueCommand putCommand = new PutKeyValueCommand();
+ putCommand.setKey(key);
+ putCommand.setValue(value);
+ SingleRpcCommand rpcCommand = new SingleRpcCommand();
+ Object[] params = new Object[]{"replSync", putCommand};
+ rpcCommand.setParameters(SingleRpcCommand.COMMAND_ID, params);
+ expect(mockMarshaller1.objectToBuffer(anyObject())).andReturn(originalMarshaller1.objectToBuffer(rpcCommand));
+ expect(mockMarshaller2.objectFromByteBuffer((byte[]) anyObject(), anyInt(), anyInt())).andThrow(new EOFException());
+ dispatcher1.setRequestMarshaller(mockMarshaller1);
+ dispatcher2.setRequestMarshaller(mockMarshaller2);
+ replay(mockMarshaller1, mockMarshaller2);
+ cache1.put(key, value);
+ assert false : "Should have thrown an exception";
+ } catch(CacheException ce) {
+ assert !(ce.getCause() instanceof ClassCastException) : "No way a ClassCastException must be sent back to user!";
+ assert ce.getCause() instanceof EOFException;
+ } finally {
+ dispatcher1.setMarshaller(originalMarshaller1);
+ dispatcher2.setMarshaller(originalMarshaller2);
+ }
+ }
+}
More information about the infinispan-commits
mailing list