From 627a9cbb847d025e50135ba970b49218e8a8cd42 Mon Sep 17 00:00:00 2001 From: ivinokur Date: Mon, 22 Jan 2024 15:57:26 +0200 Subject: [PATCH] fixup! Remove DB related modules --- .../che/api/system/server/SystemManager.java | 12 ++++++++++++ .../che/api/system/server/SystemManagerTest.java | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/wsmaster/che-core-api-system/src/main/java/org/eclipse/che/api/system/server/SystemManager.java b/wsmaster/che-core-api-system/src/main/java/org/eclipse/che/api/system/server/SystemManager.java index 65d6e21353..fb2061c257 100644 --- a/wsmaster/che-core-api-system/src/main/java/org/eclipse/che/api/system/server/SystemManager.java +++ b/wsmaster/che-core-api-system/src/main/java/org/eclipse/che/api/system/server/SystemManager.java @@ -16,7 +16,9 @@ import static org.eclipse.che.api.system.shared.SystemStatus.PREPARING_TO_SHUTDO import static org.eclipse.che.api.system.shared.SystemStatus.READY_TO_SHUTDOWN; import static org.eclipse.che.api.system.shared.SystemStatus.RUNNING; +import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; +import jakarta.annotation.PreDestroy; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -143,4 +145,14 @@ public class SystemManager { shutdownLatch.countDown(); } } + + @PreDestroy + @VisibleForTesting + void shutdown() throws InterruptedException { + if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { + shutdownLatch.await(); + } else { + doSuspendServices(); + } + } } diff --git a/wsmaster/che-core-api-system/src/test/java/org/eclipse/che/api/system/server/SystemManagerTest.java b/wsmaster/che-core-api-system/src/test/java/org/eclipse/che/api/system/server/SystemManagerTest.java index 18cf11d40c..84f1150cb6 100644 --- a/wsmaster/che-core-api-system/src/test/java/org/eclipse/che/api/system/server/SystemManagerTest.java +++ b/wsmaster/che-core-api-system/src/test/java/org/eclipse/che/api/system/server/SystemManagerTest.java @@ -80,6 +80,21 @@ public class SystemManagerTest { systemManager.stopServices(); } + @Test + public void shutdownDoesNotFailIfServicesAreAlreadyStopped() throws Exception { + systemManager.stopServices(); + systemManager.shutdown(); + + verifyShutdownCompleted(); + } + + @Test + public void shutdownStopsServicesIfNotStopped() throws Exception { + systemManager.shutdown(); + + verifySuspendCompleted(); + } + private void verifyShutdownCompleted() throws InterruptedException { verify(terminator, timeout(2000)).terminateAll(); verifyEvents();