NetworkCommunicationDispatcher extends ServerCommunicationDispatcher { @VisibleForTesting static MethodCall[] verifyNoExceptions(final MethodCall[] result, final Message[] messages, final MethodCall methodCall) { int size = result.length; List<String> remoteExceptions = null; for ( int i = 0; i < size; i++ ) { Message message = messages[i]; Address destination = message.getDest(); if ( result[i] != null ) { String exceptionAsString = result[i].getExceptionAsString(); if ( exceptionAsString != null ) { if ( remoteExceptions == null ) remoteExceptions = Lists.newArrayList(); remoteExceptions.add( String.format( "failed to execute %s on %s due to: \n %s", methodCall, destination, exceptionAsString ) ); } } } if ( remoteExceptions != null ) { StringBuilder builder = new StringBuilder(); builder.append( "unable to call remote method(s) due to single(multiple) failures: " ).append( "\n" ); for ( String e : remoteExceptions ) { builder.append( "\t" ); builder.append( e ); builder.append( "\n" ); } String failure = builder.toString(); LOGGER.error( failure ); throw new RemoteAccessException( failure ); } return result; } NetworkCommunicationDispatcher(final AbstractSpaceConfiguration configuration); void setKryo(final Kryo kryo); MethodCall[] sendAndReceive(final MethodCall methodCall,
                                       final ObjectBuffer objectBuffer,
                                       final Address... destinations); @Override void receive(final Message msg);  }
@Test public void testSunnyDayScenario() { MethodCall request = new BeginTransactionMethodCall(); NetworkCommunicationDispatcher.verifyNoExceptions( dummyResponses(), messages, request ); }
@Test(expected = RemoteAccessException.class) public void testWithFailures() { MethodCall request = new BeginTransactionMethodCall(); MethodCall[] dummyResponses = dummyResponses(); IllegalArgumentException argumentException1 = new IllegalArgumentException( String.valueOf( System.currentTimeMillis() ) ); argumentException1.fillInStackTrace(); dummyResponses[1].setException( argumentException1 ); IllegalArgumentException argumentException2 = new IllegalArgumentException( String.valueOf( System.currentTimeMillis() ) ); argumentException2.fillInStackTrace(); dummyResponses[2].setException( argumentException2 ); NetworkCommunicationDispatcher.verifyNoExceptions( dummyResponses, messages, request ); }