diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-10 14:27:41 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-21 16:44:04 +0100 |
commit | 7b6038abea08791c5c69c0716cca2fe40688d20c (patch) | |
tree | 6ccb4ee6ad3435c073e364c03d21d7a251b6e801 /server/sonar-process | |
parent | b096cada959198f345b71cc9b0e65393c082d97e (diff) | |
download | sonarqube-7b6038abea08791c5c69c0716cca2fe40688d20c.tar.gz sonarqube-7b6038abea08791c5c69c0716cca2fe40688d20c.zip |
SONAR-7435 CE process waiting for WebServer to be operational
CE detects WebServer is operational though shared file IPC (see ProcessCommand)
Diffstat (limited to 'server/sonar-process')
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java | 36 | ||||
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java | 36 |
2 files changed, 53 insertions, 19 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java index 84cbb22f093..10930daf679 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java @@ -19,6 +19,7 @@ */ package org.sonar.process; +import java.io.File; import org.slf4j.LoggerFactory; public class ProcessEntryPoint implements Stoppable { @@ -29,6 +30,9 @@ public class ProcessEntryPoint implements Stoppable { public static final String PROPERTY_SHARED_PATH = "process.sharedDir"; private final Props props; + private final String processKey; + private final int processNumber; + private final File sharedDir; private final Lifecycle lifecycle = new Lifecycle(); private final ProcessCommands commands; private final SystemExit exit; @@ -46,7 +50,14 @@ public class ProcessEntryPoint implements Stoppable { }); ProcessEntryPoint(Props props, SystemExit exit, ProcessCommands commands) { + this(props, getProcessNumber(props), getSharedDir(props), exit, commands); + } + + private ProcessEntryPoint(Props props, int processNumber, File sharedDir, SystemExit exit, ProcessCommands commands) { this.props = props; + this.processKey = props.nonNullValue(PROPERTY_PROCESS_KEY); + this.processNumber = processNumber; + this.sharedDir = sharedDir; this.exit = exit; this.commands = commands; this.stopWatcher = new StopWatcher(commands, this); @@ -61,7 +72,15 @@ public class ProcessEntryPoint implements Stoppable { } public String getKey() { - return props.nonNullValue(PROPERTY_PROCESS_KEY); + return processKey; + } + + public int getProcessNumber() { + return processNumber; + } + + public File getSharedDir() { + return sharedDir; } /** @@ -138,8 +157,17 @@ public class ProcessEntryPoint implements Stoppable { public static ProcessEntryPoint createForArguments(String[] args) { Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args); - ProcessCommands commands = DefaultProcessCommands.main( - props.nonNullValueAsFile(PROPERTY_SHARED_PATH), Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX))); - return new ProcessEntryPoint(props, new SystemExit(), commands); + File sharedDir = getSharedDir(props); + int processNumber = getProcessNumber(props); + ProcessCommands commands = DefaultProcessCommands.main(sharedDir, processNumber); + return new ProcessEntryPoint(props, processNumber, sharedDir, new SystemExit(), commands); + } + + private static int getProcessNumber(Props props) { + return Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX)); + } + + private static File getSharedDir(Props props) { + return props.nonNullValueAsFile(PROPERTY_SHARED_PATH); } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java index 8e107af3ee1..6acf205b52e 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java @@ -19,6 +19,7 @@ */ package org.sonar.process; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; @@ -35,6 +36,10 @@ import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; +import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX; +import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_KEY; +import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH; +import static org.sonar.process.ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT; public class ProcessEntryPointTest { @@ -61,7 +66,7 @@ public class ProcessEntryPointTest { @Test public void test_initial_state() throws Exception { - Props props = new Props(new Properties()); + Props props = createProps(); ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class)); assertThat(entryPoint.getProps()).isSameAs(props); @@ -70,10 +75,8 @@ public class ProcessEntryPointTest { } @Test - public void fail_to_launch_multiple_times() { - Props props = new Props(new Properties()); - props.set(ProcessEntryPoint.PROPERTY_PROCESS_KEY, "test"); - props.set(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, "30000"); + public void fail_to_launch_multiple_times() throws IOException { + Props props = createProps(); ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class)); entryPoint.launch(new NoopProcess()); @@ -87,9 +90,7 @@ public class ProcessEntryPointTest { @Test public void launch_then_request_graceful_stop() throws Exception { - Props props = new Props(new Properties()); - props.set(ProcessEntryPoint.PROPERTY_PROCESS_KEY, "test"); - props.set(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, "30000"); + Props props = createProps(); final ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class)); final StandardProcess process = new StandardProcess(); @@ -115,9 +116,7 @@ public class ProcessEntryPointTest { @Test public void terminate_if_unexpected_shutdown() throws Exception { - Props props = new Props(new Properties()); - props.set(ProcessEntryPoint.PROPERTY_PROCESS_KEY, "foo"); - props.set(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, "30000"); + Props props = createProps(); final ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class)); final StandardProcess process = new StandardProcess(); @@ -146,10 +145,8 @@ public class ProcessEntryPointTest { } @Test - public void terminate_if_startup_error() { - Props props = new Props(new Properties()); - props.set(ProcessEntryPoint.PROPERTY_PROCESS_KEY, "foo"); - props.set(ProcessEntryPoint.PROPERTY_TERMINATION_TIMEOUT, "30000"); + public void terminate_if_startup_error() throws IOException { + Props props = createProps(); final ProcessEntryPoint entryPoint = new ProcessEntryPoint(props, exit, mock(ProcessCommands.class)); final Monitored process = new StartupErrorProcess(); @@ -157,6 +154,15 @@ public class ProcessEntryPointTest { assertThat(entryPoint.getState()).isEqualTo(State.STOPPED); } + private Props createProps() throws IOException { + Props props = new Props(new Properties()); + props.set(PROPERTY_SHARED_PATH, temp.newFolder().getAbsolutePath()); + props.set(PROPERTY_PROCESS_INDEX, "1"); + props.set(PROPERTY_PROCESS_KEY, "test"); + props.set(PROPERTY_TERMINATION_TIMEOUT, "30000"); + return props; + } + private static class NoopProcess implements Monitored { @Override |