@Test public void shouldSortSingleRootWithMultipleLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_SINGLE_ROOT_AND_MULTIPLE_LINKS, "C", "A")); assertExecutionSteps(sorted, new String[] {"B"}, new String[] {"A", "C"}); }
private String join(Collection<String> strings) { return join(strings.toArray(new String[] {})); }
@Test(expected = IllegalArgumentException.class) public void shouldFailOnRecursiveLinks() throws Exception { AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_RECURSIVE_LINKS, "A", "B")); }
@Test public void shouldSortSingleRootWithMultipleDependsOn() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_SINGLE_ROOT_AND_MULTIPLE_DEPENDS, "C", "A")); assertExecutionSteps(sorted, new String[] {"B"}, new String[] {"A", "C"}); }
private CubeDockerConfiguration create(String setup, String... autoStart) { Map<String, String> config = new HashMap<>(); if (autoStart != null && autoStart.length > 0) { config.put("autoStartContainers", join(autoStart)); } config.put("dockerContainers", setup); config.put("definitionFormat", DefinitionFormat.CUBE.name()); return CubeDockerConfiguration.fromMap(config, null); }
@Test public void shouldSortSingleRootWithMultipleDependsOnMustHavePriorityOverLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_SINGLE_ROOT_AND_MULTIPLE_DEPENDS_AND_LINK, "C", "A")); assertExecutionSteps(sorted, new String[] {"B"}, new String[] {"A", "C"}); }
private void assertExecutionSteps(List<String[]> actuals, String[]... expecteds) { Assert.assertEquals("Number of steps to should match", expecteds.length, actuals.size()); for (int i = 0; i < actuals.size(); i++) { List<String> actual = Arrays.asList(actuals.get(i)); String[] expected = expecteds[i]; Assert.assertEquals("Number of cubes in step[" + i + "] should match", expected.length, actual.size()); for (String expectedId : expected) { Assert.assertTrue( "Cube[" + expectedId + "] should have been in step[" + i + "] Found[" + join(actual) + "]", actual.contains(expectedId)); } } }
@Test public void shouldSortMultipleNonLinkedRoots() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_MULTIPLE_ROOTS, "A", "B")); assertExecutionSteps(sorted, new String[] {"A", "B"}); }
@Test public void shouldSortMultipleRootWithSingleLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_MULTIPLE_ROOTS_AND_SINGLE_LINK, "C", "A")); assertExecutionSteps(sorted, new String[] {"B", "C"}, new String[] {"A"}); }
@Test public void shouldSortInReverseMultiRootWithMultipleLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStopOrder( create(SCENARIO_MULTI_ROOT_AND_MULTIPLE_LINKS, "A", "F")); assertExecutionSteps(sorted, new String[] {"A", "F"}, new String[] {"D", "C"}, new String[] {"B", "E"}); }
@Test public void shouldSortNoKnownLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_NO_KNOWN_LINK, "A")); assertExecutionSteps(sorted, new String[] {"A"}); }
@Test public void shouldSortSingleLink() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_SINGLE_LINK, "A")); assertExecutionSteps(sorted, new String[] {"B"}, new String[] {"A"}); }
@Test public void shouldSortSingleNonLinkedRoots() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_MULTIPLE_ROOTS, "A")); assertExecutionSteps(sorted, new String[] {"A"}); }
@Test public void shouldSortMultiRootWithMultipleLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStartOrder( create(SCENARIO_MULTI_ROOT_AND_MULTIPLE_LINKS, "A", "F")); assertExecutionSteps(sorted, new String[] {"B", "E"}, new String[] {"D", "C"}, new String[] {"A", "F"}); }