public void testInvokeAndExceptionWhileUnmarshalling() throws Exception {
Cache cache1 = cache(0, "replSync");
Cache cache2 = cache(1, "replSync");
JGroupsTransport transport1 = (JGroupsTransport) TestingUtil.extractComponent(cache1, Transport.class);
CommandAwareRpcDispatcher dispatcher1 = transport1.getCommandAwareRpcDispatcher();
RpcDispatcher.Marshaller originalMarshaller1 = dispatcher1.getMarshaller();
JGroupsTransport transport2 = (JGroupsTransport) TestingUtil.extractComponent(cache2, Transport.class);
CommandAwareRpcDispatcher dispatcher2 = transport2.getCommandAwareRpcDispatcher();
RpcDispatcher.Marshaller originalMarshaller = dispatcher2.getMarshaller();
try {
RpcDispatcher.Marshaller mockMarshaller1 = mock(RpcDispatcher.Marshaller.class);
RpcDispatcher.Marshaller mockMarshaller = mock(RpcDispatcher.Marshaller.class);
PutKeyValueCommand putCommand = new PutKeyValueCommand();
putCommand.setKey(key);
putCommand.setValue(value);
SingleRpcCommand rpcCommand = new SingleRpcCommand("replSync");
Object[] params = new Object[]{putCommand};
rpcCommand.setParameters(SingleRpcCommand.COMMAND_ID, params);
when(mockMarshaller1.objectToBuffer(anyObject())).thenReturn(originalMarshaller1.objectToBuffer(rpcCommand));
when(mockMarshaller.objectFromBuffer((byte[]) anyObject(), anyInt(), anyInt())).thenThrow(new EOFException());
dispatcher1.setRequestMarshaller(mockMarshaller1);
dispatcher2.setRequestMarshaller(mockMarshaller);
cache1.put(key, value);
assert false : "Should have thrown an exception";
} catch (RemoteException ce) {
assert !(ce.getCause() instanceof ClassCastException) : "No way a ClassCastException must be sent back to user!";
assert ce.getCause() instanceof CacheException;
assert ce.getCause().getCause() instanceof EOFException;
} finally {
dispatcher1.setMarshaller(originalMarshaller1);
dispatcher2.setMarshaller(originalMarshaller);
}
}