AddSshKeyStep { public void execute() throws EnvironmentManagerException, PeerException { if ( !StringUtils.isBlank( sshKey ) ) { Set<Peer> peers = environment.getPeers(); for ( final Peer peer : peers ) { keyUtil.addPeerTask( new PeerUtil.PeerTask<>( peer, new Callable<Object>() { @Override public Object call() throws Exception { peer.addToAuthorizedKeys( environment.getEnvironmentId(), sshKey ); return null; } } ) ); } PeerUtil.PeerTaskResults<Object> keyResults = keyUtil.executeParallel(); for ( PeerUtil.PeerTaskResult keyResult : keyResults.getResults() ) { if ( keyResult.hasSucceeded() ) { trackerOperation .addLog( String.format( "SSH key added on peer %s", keyResult.getPeer().getName() ) ); } else { trackerOperation.addLog( String.format( "SSH key addition failed on peer %s. Reason: %s", keyResult.getPeer().getName(), keyResult.getFailureReason() ) ); } } if ( keyResults.hasFailures() ) { throw new EnvironmentManagerException( "Failed to add SSH key on all peers" ); } } } AddSshKeyStep( final String sshKey, final LocalEnvironment environment,
                          final TrackerOperation trackerOperation ); void execute();  }
@Test( expected = EnvironmentManagerException.class ) public void testExecute() throws Exception { step.execute(); verify( PEER_UTIL ).addPeerTask( any( PeerUtil.PeerTask.class ) ); doReturn( true ).when( peerTaskResult ).hasSucceeded(); step.execute(); doReturn( true ).when( keyResults ).hasFailures(); step.execute(); }