RpcManager mockManager = mock(RpcManager.class, AdditionalAnswers.delegatesTo(realManager));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
throw new RemoteException("FAIL", new TimeoutException());
}
// Only throw exception on the first call just in case if test calls it more than once to fail properly
}).doAnswer(AdditionalAnswers.delegatesTo(realManager)).when(mockManager).invokeRemotely(anyCollection(), any(ReplicableCommand.class), any(RpcOptions.class));
TestingUtil.replaceComponent(nonOwnerCache, RpcManager.class, mockManager, true);