CassandraDaemonStep extends DefaultStep { @Override public Optional<OfferRequirement> start() { LOGGER.info("Starting Step = {}", getName()); try { CassandraContainer container = cassandraState.getOrCreateContainer(getName()); if (!isPending()) { LOGGER.warn("Step {} is not pending. start() should not be called.", getName()); return Optional.empty(); } if (isComplete(container)) { LOGGER.info("Step {} - Task complete: id = {}", getName(), container.getId()); setStatus(Status.COMPLETE); return Optional.empty(); } else if (StringUtils.isBlank(container.getAgentId())) { LOGGER.info("Step {} - Launching new container : id = {}", getName(), container.getId()); return provider.getNewOfferRequirement(container); } else if (needsConfigUpdate(container.getDaemonTask())) { LOGGER.info("Step {} - Task requires config update: id = {}", getName(), container.getId()); return reconfigureTask(container.getDaemonTask()); } else if (container.isTerminated() || container.isLaunching()) { LOGGER.info("Step {} - Replacing container : id = {}", getName(), container.getId()); return replaceTask(container.getDaemonTask()); } else { return Optional.empty(); } } catch (IOException ex) { LOGGER.error(String.format("Step %s - Failed to get or create a container", getName()), ex); return Optional.empty(); } } CassandraDaemonStep(
            final String name,
            final PersistentOfferRequirementProvider provider,
            final CassandraState cassandraState); static boolean isComplete(Protos.TaskStatus status); static boolean isComplete(Optional<Protos.TaskStatus> status); static CassandraDaemonStep create(
            final String name,
            final PersistentOfferRequirementProvider provider,
            final CassandraState cassandraState); @Override Optional<OfferRequirement> start(); @Override void update(Protos.TaskStatus status); @Override String getMessage(); @Override String toString();  }
@Test public void testStart() throws Exception { final String EXPECTED_NAME = "node-0"; CassandraDaemonStep step = CassandraDaemonStep.create( EXPECTED_NAME, persistentOfferRequirementProvider, cassandraState); final OfferRequirement mockOfferReq = mock(OfferRequirement.class); when(persistentOfferRequirementProvider.getNewOfferRequirement(Mockito.any())).thenReturn( Optional.of(mockOfferReq)); final Optional<OfferRequirement> offerRequirement = step.start(); Assert.assertTrue(offerRequirement.isPresent()); }