@Test public void createSpecificExperimentsInsufficientContainerCountExceptionMoreThanOneSurvivor () { doReturn(IntStream.range(0, 14) .mapToObj(i -> mock(Container.class)) .collect(Collectors.toUnmodifiableSet())).when(firstPlatform).getRosterByAggregationId("aggregate"); try { experimentManager.createSpecificExperiments(firstPlatform, new ExperimentSuite.ExperimentCriteria("aggregate", IntStream .range(0, 10) .mapToObj(String::valueOf) .collect(Collectors.toUnmodifiableList()), Collections.emptyList()), 5); fail("Should have thrown an exception"); } catch (ChaosException e) { assertThat(e.getMessage(), Matchers.startsWith(String.valueOf(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT.getErrorCode()))); } }
Stream<Experiment> createSpecificExperiments (Platform platform, ExperimentSuite.ExperimentCriteria experimentCriteria, int minimumNumberOfSurvivors) { String containerAggregationIdentifier = experimentCriteria.getContainerIdentifier(); List<String> experimentMethods = experimentCriteria.getExperimentMethods(); List<String> specificContainerTargets = experimentCriteria.getSpecificContainerTargets(); log.debug("Creating experiments of type {} against {} with identifier {}", experimentMethods, platform, containerAggregationIdentifier); List<Container> potentialContainers = new ArrayList<>(platform.getRosterByAggregationId(containerAggregationIdentifier)); if (potentialContainers.size() - minimumNumberOfSurvivors < experimentMethods.size()) { throw new ChaosException(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT); } Stream<Experiment> experimentStream1 = IntStream.range(0, specificContainerTargets.size()).mapToObj(i -> { String experimentMethod = experimentMethods.get(i); Experiment experiment = createSingleExperiment(platform, specificContainerTargets.get(i), experimentMethod); Optional.ofNullable(experiment).map(Experiment::getContainer).ifPresent(potentialContainers::remove); return experiment; }); List<String> leftoverExperimentMethods = experimentMethods.subList(specificContainerTargets.size(), experimentMethods .size()); Collections.shuffle(potentialContainers); Stream<Experiment> experimentStream2 = IntStream.range(0, leftoverExperimentMethods.size()).mapToObj(i -> { Container container = potentialContainers.get(i); String experimentMethod = leftoverExperimentMethods.get(i); return container.createExperiment(experimentMethod); }); return Stream.concat(experimentStream1, experimentStream2); }
ExperimentManager { Stream<Experiment> createSpecificExperiments (Platform platform, ExperimentSuite.ExperimentCriteria experimentCriteria, int minimumNumberOfSurvivors) { String containerAggregationIdentifier = experimentCriteria.getContainerIdentifier(); List<String> experimentMethods = experimentCriteria.getExperimentMethods(); List<String> specificContainerTargets = experimentCriteria.getSpecificContainerTargets(); log.debug("Creating experiments of type {} against {} with identifier {}", experimentMethods, platform, containerAggregationIdentifier); List<Container> potentialContainers = new ArrayList<>(platform.getRosterByAggregationId(containerAggregationIdentifier)); if (potentialContainers.size() - minimumNumberOfSurvivors < experimentMethods.size()) { throw new ChaosException(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT); } Stream<Experiment> experimentStream1 = IntStream.range(0, specificContainerTargets.size()).mapToObj(i -> { String experimentMethod = experimentMethods.get(i); Experiment experiment = createSingleExperiment(platform, specificContainerTargets.get(i), experimentMethod); Optional.ofNullable(experiment).map(Experiment::getContainer).ifPresent(potentialContainers::remove); return experiment; }); List<String> leftoverExperimentMethods = experimentMethods.subList(specificContainerTargets.size(), experimentMethods .size()); Collections.shuffle(potentialContainers); Stream<Experiment> experimentStream2 = IntStream.range(0, leftoverExperimentMethods.size()).mapToObj(i -> { Container container = potentialContainers.get(i); String experimentMethod = leftoverExperimentMethods.get(i); return container.createExperiment(experimentMethod); }); return Stream.concat(experimentStream1, experimentStream2); } }
ExperimentManager { Stream<Experiment> createSpecificExperiments (Platform platform, ExperimentSuite.ExperimentCriteria experimentCriteria, int minimumNumberOfSurvivors) { String containerAggregationIdentifier = experimentCriteria.getContainerIdentifier(); List<String> experimentMethods = experimentCriteria.getExperimentMethods(); List<String> specificContainerTargets = experimentCriteria.getSpecificContainerTargets(); log.debug("Creating experiments of type {} against {} with identifier {}", experimentMethods, platform, containerAggregationIdentifier); List<Container> potentialContainers = new ArrayList<>(platform.getRosterByAggregationId(containerAggregationIdentifier)); if (potentialContainers.size() - minimumNumberOfSurvivors < experimentMethods.size()) { throw new ChaosException(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT); } Stream<Experiment> experimentStream1 = IntStream.range(0, specificContainerTargets.size()).mapToObj(i -> { String experimentMethod = experimentMethods.get(i); Experiment experiment = createSingleExperiment(platform, specificContainerTargets.get(i), experimentMethod); Optional.ofNullable(experiment).map(Experiment::getContainer).ifPresent(potentialContainers::remove); return experiment; }); List<String> leftoverExperimentMethods = experimentMethods.subList(specificContainerTargets.size(), experimentMethods .size()); Collections.shuffle(potentialContainers); Stream<Experiment> experimentStream2 = IntStream.range(0, leftoverExperimentMethods.size()).mapToObj(i -> { Container container = potentialContainers.get(i); String experimentMethod = leftoverExperimentMethods.get(i); return container.createExperiment(experimentMethod); }); return Stream.concat(experimentStream1, experimentStream2); }  }
ExperimentManager { Stream<Experiment> createSpecificExperiments (Platform platform, ExperimentSuite.ExperimentCriteria experimentCriteria, int minimumNumberOfSurvivors) { String containerAggregationIdentifier = experimentCriteria.getContainerIdentifier(); List<String> experimentMethods = experimentCriteria.getExperimentMethods(); List<String> specificContainerTargets = experimentCriteria.getSpecificContainerTargets(); log.debug("Creating experiments of type {} against {} with identifier {}", experimentMethods, platform, containerAggregationIdentifier); List<Container> potentialContainers = new ArrayList<>(platform.getRosterByAggregationId(containerAggregationIdentifier)); if (potentialContainers.size() - minimumNumberOfSurvivors < experimentMethods.size()) { throw new ChaosException(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT); } Stream<Experiment> experimentStream1 = IntStream.range(0, specificContainerTargets.size()).mapToObj(i -> { String experimentMethod = experimentMethods.get(i); Experiment experiment = createSingleExperiment(platform, specificContainerTargets.get(i), experimentMethod); Optional.ofNullable(experiment).map(Experiment::getContainer).ifPresent(potentialContainers::remove); return experiment; }); List<String> leftoverExperimentMethods = experimentMethods.subList(specificContainerTargets.size(), experimentMethods .size()); Collections.shuffle(potentialContainers); Stream<Experiment> experimentStream2 = IntStream.range(0, leftoverExperimentMethods.size()).mapToObj(i -> { Container container = potentialContainers.get(i); String experimentMethod = leftoverExperimentMethods.get(i); return container.createExperiment(experimentMethod); }); return Stream.concat(experimentStream1, experimentStream2); }  void setExperimentBackoffPeriod(Duration experimentBackoffPeriod); boolean areExperimentsInProgress(); }
ExperimentManager { Stream<Experiment> createSpecificExperiments (Platform platform, ExperimentSuite.ExperimentCriteria experimentCriteria, int minimumNumberOfSurvivors) { String containerAggregationIdentifier = experimentCriteria.getContainerIdentifier(); List<String> experimentMethods = experimentCriteria.getExperimentMethods(); List<String> specificContainerTargets = experimentCriteria.getSpecificContainerTargets(); log.debug("Creating experiments of type {} against {} with identifier {}", experimentMethods, platform, containerAggregationIdentifier); List<Container> potentialContainers = new ArrayList<>(platform.getRosterByAggregationId(containerAggregationIdentifier)); if (potentialContainers.size() - minimumNumberOfSurvivors < experimentMethods.size()) { throw new ChaosException(NOT_ENOUGH_CONTAINERS_FOR_PLANNED_EXPERIMENT); } Stream<Experiment> experimentStream1 = IntStream.range(0, specificContainerTargets.size()).mapToObj(i -> { String experimentMethod = experimentMethods.get(i); Experiment experiment = createSingleExperiment(platform, specificContainerTargets.get(i), experimentMethod); Optional.ofNullable(experiment).map(Experiment::getContainer).ifPresent(potentialContainers::remove); return experiment; }); List<String> leftoverExperimentMethods = experimentMethods.subList(specificContainerTargets.size(), experimentMethods .size()); Collections.shuffle(potentialContainers); Stream<Experiment> experimentStream2 = IntStream.range(0, leftoverExperimentMethods.size()).mapToObj(i -> { Container container = potentialContainers.get(i); String experimentMethod = leftoverExperimentMethods.get(i); return container.createExperiment(experimentMethod); }); return Stream.concat(experimentStream1, experimentStream2); }  void setExperimentBackoffPeriod(Duration experimentBackoffPeriod); boolean areExperimentsInProgress();  }