diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-18 14:44:26 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-03-21 16:44:06 +0100 |
commit | 27b2b56ab4dabb564ebb251c8b9e6c27b3e76606 (patch) | |
tree | 9b8ff2e90eeafb5d28436e3e216460c96927df84 /sonar-application | |
parent | 2bcf361c8c2458d00b4711da65b099a59a266912 (diff) | |
download | sonarqube-27b2b56ab4dabb564ebb251c8b9e6c27b3e76606.tar.gz sonarqube-27b2b56ab4dabb564ebb251c8b9e6c27b3e76606.zip |
SONAR-6732 CE and WebServer must share the same startedAt date
Diffstat (limited to 'sonar-application')
-rw-r--r-- | sonar-application/src/main/java/org/sonar/application/App.java | 2 | ||||
-rw-r--r-- | sonar-application/src/test/java/org/sonar/application/AppTest.java | 41 |
2 files changed, 31 insertions, 12 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java index 7067d122d11..35e9f491694 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -21,6 +21,7 @@ package org.sonar.application; import java.io.File; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Properties; import org.apache.commons.io.FilenameUtils; @@ -59,6 +60,7 @@ public class App implements Stoppable { private static List<JavaCommand> createCommands(Props props) { File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + props.set(ProcessProperties.STARTED_AT, String.valueOf(new Date().getTime())); List<JavaCommand> commands = new ArrayList<>(3); commands.add(createESCommand(props, homeDir)); diff --git a/sonar-application/src/test/java/org/sonar/application/AppTest.java b/sonar-application/src/test/java/org/sonar/application/AppTest.java index 04f0da47559..70f694c97dc 100644 --- a/sonar-application/src/test/java/org/sonar/application/AppTest.java +++ b/sonar-application/src/test/java/org/sonar/application/AppTest.java @@ -19,6 +19,10 @@ */ package org.sonar.application; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Properties; import org.apache.commons.io.FilenameUtils; import org.junit.Rule; import org.junit.Test; @@ -29,11 +33,6 @@ import org.sonar.process.Props; import org.sonar.process.monitor.JavaCommand; import org.sonar.process.monitor.Monitor; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -59,29 +58,43 @@ public class AppTest { Props props = initDefaultProps(); app.start(props); - Class<List<JavaCommand>> listClass = (Class<List<JavaCommand>>)(Class)List.class; - ArgumentCaptor<List<JavaCommand>> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); verify(monitor).start(argument.capture()); assertThat(argument.getValue()).extracting("key").containsExactly("search", "web", "ce"); } @Test - public void do_not_start_tomcat_if_elasticsearch_slave() throws Exception { + public void do_not_start_WebServer_nor_CE_if_elasticsearch_slave() throws Exception { Monitor monitor = mock(Monitor.class); App app = new App(monitor); Props props = initDefaultProps(); props.set("sonar.cluster.masterHost", "1.2.3.4"); app.start(props); - Class<List<JavaCommand>> listClass = (Class<List<JavaCommand>>)(Class)List.class; - ArgumentCaptor<List<JavaCommand>> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); verify(monitor).start(argument.capture()); assertThat(argument.getValue()).extracting("key").containsOnly("search"); } @Test + public void all_JavaCommand_have_a_sonar_core_startedAt_property_argument() throws IOException { + Monitor monitor = mock(Monitor.class); + App app = new App(monitor); + Props props = initDefaultProps(); + app.start(props); + + ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); + verify(monitor).start(argument.capture()); + + List<JavaCommand> javaCommands = argument.getValue(); + for (JavaCommand javaCommand : javaCommands) { + assertThat(javaCommand.getArguments()).containsKey(ProcessProperties.STARTED_AT); + } + } + + @Test public void add_custom_jdbc_driver_to_tomcat_classpath() throws Exception { Monitor monitor = mock(Monitor.class); App app = new App(monitor); @@ -89,8 +102,7 @@ public class AppTest { props.set("sonar.jdbc.driverPath", "oracle/ojdbc6.jar"); app.start(props); - Class<List<JavaCommand>> listClass = (Class<List<JavaCommand>>)(Class)List.class; - ArgumentCaptor<List<JavaCommand>> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); verify(monitor).start(argument.capture()); assertThat(argument.getValue().get(1).getClasspath()).contains("oracle/ojdbc6.jar"); @@ -104,4 +116,9 @@ public class AppTest { props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); return props; } + + private ArgumentCaptor<List<JavaCommand>> newJavaCommandArgumentCaptor() { + Class<List<JavaCommand>> listClass = (Class<List<JavaCommand>>) (Class) List.class; + return ArgumentCaptor.forClass(listClass); + } } |