DestroyContainersStep { public Environment execute() throws EnvironmentNotFoundException, ContainerHostNotFoundException { if ( !CollectionUtil.isCollectionEmpty( removedContainers ) ) { for ( String containerId : removedContainers ) { final ContainerHost containerHost = environment.getContainerHostById( containerId ); destroyUtil.addTask( new ContainerDestroyTask( containerHost ) ); } TaskUtil.TaskResults<Object> destroyResults = destroyUtil.executeParallel(); for ( TaskUtil.TaskResult<Object> destroyResult : destroyResults.getResults() ) { ContainerHost containerHost = ( ( ContainerDestroyTask ) destroyResult.getTask() ).getContainerHost(); if ( destroyResult.hasSucceeded() ) { environmentManager.getRelationManager().removeRelation( containerHost ); trackerOperation.addLog( String.format( "Container %s destroyed", containerHost.getHostname() ) ); } else { trackerOperation.addLog( String.format( "Failed to destroy container %s. Reason: %s", containerHost.getHostname(), destroyResult.getFailureReason() ) ); } } return environmentManager.loadEnvironment( environment.getId() ); } return environment; } DestroyContainersStep( final LocalEnvironment environment, final EnvironmentManagerImpl environmentManager,
                                  final Set<String> removedContainers, TrackerOperation trackerOperation ); Environment execute();  }
@Test public void testExecute() throws Exception { doReturn( true ).when( taskResult ).hasSucceeded(); step.execute(); verify( environmentManager ).loadEnvironment( TestHelper.ENV_ID ); doReturn( false ).when( taskResult ).hasSucceeded(); step.execute(); verify( environmentManager, times( 2 ) ).loadEnvironment( TestHelper.ENV_ID ); }