public static void assertExecContains(ExecCmd actual, String expectedCmdRegex) { assertExecContains(actual, expectedCmdRegex, null); }
public static void assertExecSatisfies(ExecCmd actual, Predicate<? super ExecCmd> expected) { assertExecSatisfies(actual, expected, null); }
public static void assertExecHasOnlyOnce(List<ExecCmd> actuals, String expectedCmd) { assertExecHasExactly(actuals, expectedCmd, 1); }
@Test public void testAllCmds() throws Exception { app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "preInstallCommand") .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "installCommand") .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "postInstallCommand") .configure(VanillaSoftwareProcess.PRE_CUSTOMIZE_COMMAND, "preCustomizeCommand") .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "customizeCommand") .configure(VanillaSoftwareProcess.POST_CUSTOMIZE_COMMAND, "postCustomizeCommand") .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "preLaunchCommand") .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "launchCommand") .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "postLaunchCommand") .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "checkRunningCommand") .configure(VanillaSoftwareProcess.STOP_COMMAND, "stopCommand")); app.start(ImmutableList.of(loc)); assertExecsContain(RecordingSshTool.getExecCmds(), ImmutableList.of( "preInstallCommand", "installCommand", "postInstallCommand", "preCustomizeCommand", "customizeCommand", "postCustomizeCommand", "preLaunchCommand", "launchCommand", "postLaunchCommand", "checkRunningCommand")); app.stop(); assertExecContains(RecordingSshTool.getLastExecCmd(), "stopCommand"); }
assertExecsSatisfy(RecordingSshTool.getExecCmds(), ImmutableList.of( Predicates.and(ExecCmdPredicates.containsCmd("preInstallCommand"), ExecCmdPredicates.containsEnv(expectedEnv)), Predicates.and(ExecCmdPredicates.containsCmd("installCommand"), ExecCmdPredicates.containsEnv(expectedEnv)), assertExecSatisfies( RecordingSshTool.getLastExecCmd(), Predicates.and(ExecCmdPredicates.containsCmd("stopCommand"), ExecCmdPredicates.containsEnv(expectedEnv)));
@Test public void testSkipInstallation() throws Exception { app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.SKIP_INSTALLATION, true) .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "preInstallCommand") .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "installCommand") .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "postInstallCommand") .configure(VanillaSoftwareProcess.PRE_CUSTOMIZE_COMMAND, "preCustomizeCommand") .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "customizeCommand") .configure(VanillaSoftwareProcess.POST_CUSTOMIZE_COMMAND, "postCustomizeCommand") .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "preLaunchCommand") .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "launchCommand") .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "postLaunchCommand") .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "checkRunningCommand") .configure(VanillaSoftwareProcess.STOP_COMMAND, "stopCommand")); app.start(ImmutableList.of(loc)); assertExecsContain(RecordingSshTool.getExecCmds(), ImmutableList.of( "preCustomizeCommand", "customizeCommand", "postCustomizeCommand", "preLaunchCommand", "launchCommand", "postLaunchCommand", "checkRunningCommand")); assertExecsNotContains(RecordingSshTool.getExecCmds(), ImmutableList.of( "preInstallCommand", "installCommand", "postInstallCommand")); }
@Test public void testCmdNotInheritedFromParentOfSoftwareProcess() throws Exception { app.config().set(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "preInstallCommand"); app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "launchCommand")); app.start(ImmutableList.of(loc)); // since app does not define it, the child *should* run it assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "preInstallCommand"); assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "launchCommand"); } }
.get(); assertExecsContain(RecordingSshTool.getExecCmds(), ImmutableList.of( "checkRunningCommand", "stopCommand", "preLaunchCommand", "launchCommand", "postLaunchCommand",
public static void assertExecsNotContains(List<? extends ExecCmd> actuals, List<String> expectedNotCmdRegexs) { for (ExecCmd actual : actuals) { assertExecNotContains(actual, expectedNotCmdRegexs); } }
createStartWaitAndLogApplication(yaml); ExecCmd cmd = ExecCmdAsserts.findExecContaining(RecordingSshTool.getExecCmds(), "myLaunchCmd"); assertEquals(cmd.env.get("KEY_IN_SUPER"), "myDefaultVal", "cmd="+cmd); assertEquals(cmd.env.get("KEY_IN_SUB"), "myBoringVal", "cmd="+cmd);
@Test public void testSkipEntityStartIfRunningWhenAlreadyRunning() throws Exception { app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.SKIP_ENTITY_START_IF_RUNNING, true) .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "preInstallCommand") .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "installCommand") .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "postInstallCommand") .configure(VanillaSoftwareProcess.PRE_CUSTOMIZE_COMMAND, "preCustomizeCommand") .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "customizeCommand") .configure(VanillaSoftwareProcess.POST_CUSTOMIZE_COMMAND, "postCustomizeCommand") .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "preLaunchCommand") .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "launchCommand") .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "postLaunchCommand") .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "checkRunningCommand") .configure(VanillaSoftwareProcess.STOP_COMMAND, "stopCommand")); app.start(ImmutableList.of(loc)); assertExecsContain(RecordingSshTool.getExecCmds(), ImmutableList.of( "checkRunningCommand")); assertExecsNotContains(RecordingSshTool.getExecCmds(), ImmutableList.of( "launchCommand")); }
@Test public void testCmdNotInheritedByChildrenOfSoftwareProcess() throws Exception { app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "preInstallCommand") .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "parentLaunchCommand") .configure(VanillaSoftwareProcess.CHILDREN_STARTABLE_MODE, ChildStartableMode.FOREGROUND) .child(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "childLaunchCommand"))); app.start(ImmutableList.of(loc)); assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "childLaunchCommand"); assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "preInstallCommand"); }
app.start(ImmutableList.of(loc)); assertExecsContain(RecordingSshTool.getExecCmds(), ImmutableList.of( "checkRunningCommand", "preInstallCommand", "installCommand", "postInstallCommand",
public static void assertExecsContain(List<ExecCmd> actuals, List<String> expectedCmds) { String errMsg = "actuals="+actuals+"; expected="+expectedCmds; assertTrue(actuals.size() >= expectedCmds.size(), "actualSize="+actuals.size()+"; expectedSize="+expectedCmds.size()+"; "+errMsg); for (int i = 0; i < expectedCmds.size(); i++) { assertExecContains(actuals.get(i), expectedCmds.get(i), errMsg); } }
public static void assertExecsSatisfy(List<ExecCmd> actuals, List<? extends Predicate<? super ExecCmd>> expectedCmds) { String errMsg = "actuals="+actuals+"; expected="+expectedCmds; assertTrue(actuals.size() >= expectedCmds.size(), "actualSize="+actuals.size()+"; expectedSize="+expectedCmds.size()+"; "+errMsg); for (int i = 0; i < expectedCmds.size(); i++) { assertExecSatisfies(actuals.get(i), expectedCmds.get(i), errMsg); } }
public static void assertExecHasNever(List<ExecCmd> actuals, String expectedCmd) { assertExecHasExactly(actuals, expectedCmd, 0); }