]> source.dussan.org Git - sonarqube.git/commitdiff
stop should be allowed when SQ is not yet fully operational
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 5 Sep 2019 07:50:08 +0000 (09:50 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 6 Sep 2019 18:21:05 +0000 (20:21 +0200)
this allows to keep stop code behing lifecycle transition test
which prevents multiple stop sequence to be initiated in parallel from different thread
which may interrupt each other and create unstable behaviors (with cryptic non reproducible errors)

server/sonar-main/src/main/java/org/sonar/application/NodeLifecycle.java
server/sonar-main/src/main/java/org/sonar/application/SchedulerImpl.java
server/sonar-main/src/test/java/org/sonar/application/NodeLifecycleTest.java

index 20aa56b378282bcf7a20484d5d7055d32f64859b..288f329260fd848eccad4553827f5709ec0c9648 100644 (file)
@@ -73,7 +73,7 @@ class NodeLifecycle {
   private static Map<State, Set<State>> buildTransitions() {
     Map<State, Set<State>> res = new EnumMap<>(State.class);
     res.put(INIT, toSet(STARTING));
-    res.put(STARTING, toSet(OPERATIONAL, RESTARTING, HARD_STOPPING, STOPPED));
+    res.put(STARTING, toSet(OPERATIONAL, RESTARTING, STOPPING, HARD_STOPPING, STOPPED));
     res.put(OPERATIONAL, toSet(RESTARTING, STOPPING, HARD_STOPPING, STOPPED));
     res.put(STOPPING, toSet(HARD_STOPPING, STOPPED));
     res.put(RESTARTING, toSet(STARTING, HARD_STOPPING, STOPPED));
index 93a258a0a9abce2d6995a992d8d9bfa7075864ee..ed0712801687619b7f9d8f0e3d2185505d723d52 100644 (file)
@@ -201,8 +201,8 @@ public class SchedulerImpl implements Scheduler, ManagedProcessEventListener, Pr
   public void stop() {
     if (nodeLifecycle.tryToMoveTo(STOPPING)) {
       LOG.info("Stopping SonarQube");
+      stopImpl();
     }
-    stopImpl();
   }
 
   private void stopImpl() {
index 5ebfd9587fd80ab21efcbe7387a4d599c16dcc86..1190f0c601cc46156f8ddf297cdd8bf75922f8bc 100644 (file)
@@ -46,6 +46,17 @@ public class NodeLifecycleTest {
     assertThat(underTest.getState()).isEqualTo(STOPPED);
   }
 
+  @Test
+  public void verify_regular_start_and_early_graceful_stop_cycle() {
+    assertThat(underTest.getState()).isEqualTo(INIT);
+    assertThat(underTest.tryToMoveTo(STARTING)).isTrue();
+    assertThat(underTest.getState()).isEqualTo(STARTING);
+    assertThat(underTest.tryToMoveTo(STOPPING)).isTrue();
+    assertThat(underTest.getState()).isEqualTo(STOPPING);
+    assertThat(underTest.tryToMoveTo(STOPPED)).isTrue();
+    assertThat(underTest.getState()).isEqualTo(STOPPED);
+  }
+
   @Test
   public void verify_start_and_hard_stop_cycle() {
     assertThat(underTest.getState()).isEqualTo(INIT);