private void tryToStartProcess(SQProcess process, Supplier<AbstractCommand> commandSupplier) { tryToStart(process, () -> { AbstractCommand command = commandSupplier.get(); return processLauncher.launch(command); }); }
@Test public void clean_up_old_es_data() throws Exception { File tempDir = temp.newFolder(); File homeDir = temp.newFolder(); File dataDir = temp.newFolder(); File logDir = temp.newFolder(); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> new TestProcessBuilder()); EsScriptCommand command = createEsScriptCommand(tempDir, homeDir, dataDir, logDir); File outdatedEsDir = new File(dataDir, "es"); assertThat(outdatedEsDir.mkdir()).isTrue(); assertThat(outdatedEsDir.exists()).isTrue(); underTest.launch(command); assertThat(outdatedEsDir.exists()).isFalse(); }
@Test public void do_not_fail_if_outdated_es_directory_does_not_exist() throws Exception { File tempDir = temp.newFolder(); File homeDir = temp.newFolder(); File dataDir = temp.newFolder(); File logDir = temp.newFolder(); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> new TestProcessBuilder()); EsScriptCommand command = createEsScriptCommand(tempDir, homeDir, dataDir, logDir); File outdatedEsDir = new File(dataDir, "es"); assertThat(outdatedEsDir.exists()).isFalse(); underTest.launch(command); assertThat(outdatedEsDir.exists()).isFalse(); }
@Test public void throw_ISE_if_command_fails() throws IOException { File tempDir = temp.newFolder(); ProcessLauncherImpl.ProcessBuilder processBuilder = mock(ProcessLauncherImpl.ProcessBuilder.class, RETURNS_MOCKS); when(processBuilder.start()).thenThrow(new IOException("error")); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Fail to launch process [es]"); underTest.launch(new JavaCommand(ProcessId.ELASTICSEARCH, temp.newFolder())); }
@Test public void temporary_properties_file_can_be_avoided() throws Exception { File tempDir = temp.newFolder(); TestProcessBuilder processBuilder = new TestProcessBuilder(); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder); JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.WEB_SERVER, temp.newFolder()); command.setReadsArgumentsFromFile(false); command.setArgument("foo", "bar"); command.setArgument("baz", "woo"); command.setJvmOptions(new JvmOptions<>()); underTest.launch(command); String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1); File file = new File(propsFilePath); assertThat(file).doesNotExist(); }
@Test public void properties_are_passed_to_command_via_a_temporary_properties_file() throws Exception { File tempDir = temp.newFolder(); TestProcessBuilder processBuilder = new TestProcessBuilder(); ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder); JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.WEB_SERVER, temp.newFolder()); command.setReadsArgumentsFromFile(true); command.setArgument("foo", "bar"); command.setArgument("baz", "woo"); command.setJvmOptions(new JvmOptions<>()); underTest.launch(command); String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1); File file = new File(propsFilePath); assertThat(file).exists().isFile(); try (FileReader reader = new FileReader(file)) { Properties props = new Properties(); props.load(reader); assertThat(props).containsOnly( entry("foo", "bar"), entry("baz", "woo"), entry("process.terminationTimeout", "60000"), entry("process.key", ProcessId.WEB_SERVER.getKey()), entry("process.index", String.valueOf(ProcessId.WEB_SERVER.getIpcIndex())), entry("process.sharedDir", tempDir.getAbsolutePath())); } }
command.setEsInstallation(createEsInstallation()); ProcessMonitor monitor = underTest.launch(command);
private void tryToStartProcess(SQProcess process, Supplier<AbstractCommand> commandSupplier) { tryToStart(process, () -> { AbstractCommand command = commandSupplier.get(); return processLauncher.launch(command); }); }