CassandraDaemonPhase extends DefaultPhase { public static final CassandraDaemonPhase create( final CassandraState cassandraState, final PersistentOfferRequirementProvider provider, final SchedulerClient client, final DefaultConfigurationManager configurationManager) { try { return new CassandraDaemonPhase( createSteps(cassandraState, provider, configurationManager), new ArrayList<>()); } catch (Throwable e) { return new CassandraDaemonPhase(new ArrayList<>(), Arrays.asList(String.format( "Error creating CassandraDaemonStep : message = %s", e.getMessage()))); } } CassandraDaemonPhase(
            final List<Step> steps,
            final List<String> errors); static final CassandraDaemonPhase create(
            final CassandraState cassandraState,
            final PersistentOfferRequirementProvider provider,
            final SchedulerClient client,
            final DefaultConfigurationManager configurationManager);  }
@Test public void testCreateEmptyPhase() throws ConfigStoreException { CassandraSchedulerConfiguration configuration = Mockito.mock(CassandraSchedulerConfiguration.class); final DefaultConfigurationManager mockConfigManager = Mockito.mock(DefaultConfigurationManager.class); when(mockConfigManager.getTargetConfig()).thenReturn(configuration); Mockito.when(configuration.getServers()).thenReturn(0); final CassandraDaemonPhase phase = CassandraDaemonPhase.create( cassandraState, persistentOfferRequirementProvider, client, mockConfigManager); Assert.assertTrue(CollectionUtils.isEmpty(phase.getErrors())); Assert.assertTrue(phase.getChildren().isEmpty()); Assert.assertEquals("Deploy", phase.getName()); }
@Test public void testCreateSingleStepPhase() throws Exception { final CassandraDaemonTask daemonTask = Mockito.mock(CassandraDaemonTask.class); final CassandraContainer cassandraContainer = Mockito.mock(CassandraContainer.class); when(cassandraContainer.getDaemonTask()).thenReturn(daemonTask); final String EXPECTED_NAME = "node-0"; when(daemonTask.getName()).thenReturn(EXPECTED_NAME); final StateStore stateStore = Mockito.mock(StateStore.class); when(cassandraState.getStateStore()).thenReturn(stateStore); when(stateStore.fetchStatus(EXPECTED_NAME)) .thenReturn(Optional.empty()); when(cassandraState.getOrCreateContainer(EXPECTED_NAME)).thenReturn(cassandraContainer); CassandraSchedulerConfiguration configuration = Mockito.mock(CassandraSchedulerConfiguration.class); when(configurationManager.getTargetConfig()).thenReturn(configuration); Mockito.when(configuration.getServers()).thenReturn(1); final CassandraDaemonPhase phase = CassandraDaemonPhase.create( cassandraState, persistentOfferRequirementProvider, client, configurationManager); Assert.assertTrue(CollectionUtils.isEmpty(phase.getErrors())); Assert.assertTrue(phase.getChildren().size() == 1); Assert.assertEquals("Deploy", phase.getName()); }