RemoveSshKeyStep { 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.removeFromAuthorizedKeys( 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 removed on peer %s", keyResult.getPeer().getName() ) ); } else { trackerOperation.addLog( String.format( "SSH key removal failed on peer %s. Reason: %s", keyResult.getPeer().getName(), keyResult.getFailureReason() ) ); } } if ( keyResults.hasFailures() ) { throw new EnvironmentManagerException( "Failed to remove SSH key on all peers" ); } environment.removeSshKey( sshKey ); } } RemoveSshKeyStep( final String sshKey, final LocalEnvironment environment,
                             final TrackerOperation trackerOperation ); void execute();  }
@Test( expected = EnvironmentManagerException.class ) public void testExecute() throws Exception { step.execute(); verify( environment ).removeSshKey( TestHelper.SSH_KEY ); doReturn( false ).when( peerTaskResult ).hasSucceeded(); doReturn( true ).when( peerTaskResults ).hasFailures(); step.execute(); }