You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2021/08/07 13:33:00 UTC

[sling-org-apache-sling-distribution-journal] branch SLING-10709 updated: SLING-10709 : Migrate SubscriberIdleCheck from Systemready to HC

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch SLING-10709
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git


The following commit(s) were added to refs/heads/SLING-10709 by this push:
     new 1c2a5a4  SLING-10709 : Migrate SubscriberIdleCheck from Systemready to HC
1c2a5a4 is described below

commit 1c2a5a4a156a4bb29e1c0d34795d2c8f3beedb82
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sat Aug 7 15:31:45 2021 +0200

    SLING-10709 : Migrate SubscriberIdleCheck from Systemready to HC
---
 pom.xml                                            |  4 +--
 .../impl/subscriber/SubscriberIdleCheck.java       | 29 +++++++---------
 .../impl/subscriber/SubscriberIdleCheckTest.java   | 39 +++++++++++-----------
 3 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7d5a6d3..ad9ea8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,8 +84,8 @@
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.systemready</artifactId>
-            <version>0.4.2</version>
+            <artifactId>org.apache.felix.healthcheck.api</artifactId>
+            <version>2.0.4</version>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheck.java b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheck.java
index 487d7b0..962da28 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheck.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheck.java
@@ -19,34 +19,30 @@
 package org.apache.sling.distribution.journal.impl.subscriber;
 
 import java.io.Closeable;
+import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.felix.systemready.CheckStatus;
-import org.apache.felix.systemready.StateType;
-import org.apache.felix.systemready.SystemReadyCheck;
-import org.apache.felix.systemready.CheckStatus.State;
+import org.apache.felix.hc.api.HealthCheck;
+import org.apache.felix.hc.api.Result;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-public class SubscriberIdleCheck implements SystemReadyCheck, Closeable {
+public class SubscriberIdleCheck implements HealthCheck, Closeable {
     static final String CHECK_NAME = "DistributionSubscriber idle";
-    private final ServiceRegistration<SystemReadyCheck> reg;
+    private final ServiceRegistration<HealthCheck> reg;
     private final IdleCheck idleCheck;
-    
+
     public SubscriberIdleCheck(BundleContext context, IdleCheck idleCheck) {
         this.idleCheck = idleCheck;
-        this.reg = context.registerService(SystemReadyCheck.class, this, new Hashtable<>());
+        final Dictionary<String, Object> props = new Hashtable<>();
+        props.put(HealthCheck.NAME, CHECK_NAME);
+        this.reg = context.registerService(HealthCheck.class, this, props);
     }
 
     @Override
-    public String getName() {
-        return CHECK_NAME;
-    }
-
-    @Override
-    public CheckStatus getStatus() {
-        State state = idleCheck.isIdle() ? State.GREEN : State.RED; 
-        return new CheckStatus(getName(), StateType.READY, state, CHECK_NAME);
+    public Result execute() {
+        Result.Status status = idleCheck.isIdle() ? Result.Status.OK : Result.Status.CRITICAL;
+        return new Result(status, CHECK_NAME);
     }
 
     @Override
@@ -55,5 +51,4 @@ public class SubscriberIdleCheck implements SystemReadyCheck, Closeable {
             reg.unregister();
         }
     }
-
 }
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheckTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheckTest.java
index 4b8a95a..03f4c98 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheckTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberIdleCheckTest.java
@@ -21,12 +21,12 @@ package org.apache.sling.distribution.journal.impl.subscriber;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.when;
 
-import org.apache.felix.systemready.CheckStatus;
-import org.apache.felix.systemready.CheckStatus.State;
-import org.apache.felix.systemready.SystemReadyCheck;
+import org.apache.felix.hc.api.HealthCheck;
+import org.apache.felix.hc.api.Result;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.junit.Before;
 import org.junit.Test;
@@ -41,10 +41,10 @@ public class SubscriberIdleCheckTest {
 
     private BundleContext context;
     private SubscriberIdleCheck idleCheck;
-    
+
     @Mock
-    private IdleCheck idle; 
-    
+    private IdleCheck idle;
+
     @Before
     public void before() {
         context = MockOsgi.newBundleContext();
@@ -53,34 +53,33 @@ public class SubscriberIdleCheckTest {
 
     @Test
     public void testServiceRegistration() throws InterruptedException {
-        ServiceReference<SystemReadyCheck> ref = context.getServiceReference(SystemReadyCheck.class);
+        ServiceReference<HealthCheck> ref = context.getServiceReference(HealthCheck.class);
         assertThat(ref, notNullValue());
         idleCheck.close();
-        ServiceReference<SystemReadyCheck> refClose = context.getServiceReference(SystemReadyCheck.class);
+        ServiceReference<HealthCheck> refClose = context.getServiceReference(HealthCheck.class);
         assertThat(refClose, nullValue());
     }
-    
+
     @Test
     public void testName() throws InterruptedException {
-        assertThat(idleCheck.getName(), equalTo(SubscriberIdleCheck.CHECK_NAME));
+        ServiceReference<HealthCheck> ref = context.getServiceReference(HealthCheck.class);
+        assertThat(ref.getProperty(HealthCheck.NAME), equalTo(SubscriberIdleCheck.CHECK_NAME));
     }
-    
+
     @Test
-    public void testCheckRed() throws InterruptedException {
+    public void testCheckCritical() throws InterruptedException {
         when(idle.isIdle()).thenReturn(false);
-        verifyStatus(State.RED);
+        verifyStatus(Result.Status.CRITICAL);
     }
 
     @Test
-    public void testCheckGreen() throws InterruptedException {
+    public void testCheckOk() throws InterruptedException {
         when(idle.isIdle()).thenReturn(true);
-        verifyStatus(State.GREEN);
+        verifyStatus(Result.Status.OK);
     }
 
-    private void verifyStatus(State expected) {
-        CheckStatus status = idleCheck.getStatus();
-        assertThat(status.getCheckName(), equalTo(SubscriberIdleCheck.CHECK_NAME));
-        assertThat(status.getDetails(), equalTo(SubscriberIdleCheck.CHECK_NAME));
-        assertThat(status.getState(), equalTo(expected));
+    private void verifyStatus(Result.Status expected) {
+        Result result = idleCheck.execute();
+        assertEquals(expected, result.getStatus());
     }
 }