From 27b2b56ab4dabb564ebb251c8b9e6c27b3e76606 Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Fri, 18 Mar 2016 14:44:26 +0100 Subject: SONAR-6732 CE and WebServer must share the same startedAt date --- .../src/main/java/org/sonar/application/App.java | 2 ++ .../test/java/org/sonar/application/AppTest.java | 41 +++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) (limited to 'sonar-application') 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 createCommands(Props props) { File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); + props.set(ProcessProperties.STARTED_AT, String.valueOf(new Date().getTime())); List 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,28 +58,42 @@ public class AppTest { Props props = initDefaultProps(); app.start(props); - Class> listClass = (Class>)(Class)List.class; - ArgumentCaptor> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor> 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> listClass = (Class>)(Class)List.class; - ArgumentCaptor> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor> 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> argument = newJavaCommandArgumentCaptor(); + verify(monitor).start(argument.capture()); + + List 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); @@ -89,8 +102,7 @@ public class AppTest { props.set("sonar.jdbc.driverPath", "oracle/ojdbc6.jar"); app.start(props); - Class> listClass = (Class>)(Class)List.class; - ArgumentCaptor> argument = ArgumentCaptor.forClass(listClass); + ArgumentCaptor> 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> newJavaCommandArgumentCaptor() { + Class> listClass = (Class>) (Class) List.class; + return ArgumentCaptor.forClass(listClass); + } } -- cgit v1.2.3