You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/06/03 06:21:59 UTC

[camel] branch master updated: Fix HealthCheckRegistry and HealthCheckService setters

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new d87f5d5  Fix HealthCheckRegistry and HealthCheckService setters
d87f5d5 is described below

commit d87f5d55d8bf738bc6a62455542456ecf78e1b9e
Author: Denis Istomin <is...@gmail.com>
AuthorDate: Fri May 31 22:26:31 2019 +0500

    Fix HealthCheckRegistry and HealthCheckService setters
---
 .../camel/impl/health/DefaultHealthCheckRegistry.java     |  6 +++---
 .../camel/impl/health/DefaultHealthCheckService.java      |  2 +-
 .../camel/impl/health/DefaultHealthCheckRegistryTest.java | 12 ++++++++++++
 .../camel/impl/health/DefaultHealthCheckServiceTest.java  | 15 ++++++++++++++-
 4 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
index 54326fb..fd65b14 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
@@ -101,10 +101,10 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry {
 
     @Override
     public void setRepositories(Collection<HealthCheckRepository> repositories) {
-        repositories.clear();
-        repositories.addAll(repositories);
+        this.repositories.clear();
+        this.repositories.addAll(repositories);
     }
-    
+
     @Override
     public Collection<HealthCheckRepository> getRepositories() {
         return Collections.unmodifiableCollection(repositories);
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java b/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
index bbf6b58..b365538 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
@@ -135,7 +135,7 @@ public final class DefaultHealthCheckService extends ServiceSupport implements H
 
     @Override
     public void setHealthCheckOptions(String id, Map<String, Object> options) {
-        options.put(id, options);
+        this.options.put(id, options);
     }
 
     @Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckRegistryTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckRegistryTest.java
index 1d0472b..8983ed7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckRegistryTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckRegistryTest.java
@@ -30,6 +30,18 @@ import org.junit.Test;
 public class DefaultHealthCheckRegistryTest {
 
     @Test
+    public void testDefaultHealthCheckRegistryRepositorySetter() {
+        HealthCheckRegistry registry1 = new DefaultHealthCheckRegistry();
+        HealthCheckRegistry registry2 = new DefaultHealthCheckRegistry();
+        registry1.addRepository(() -> Stream.of(
+                new MyHealthCheck("G1", "1")
+                )
+        );
+        registry2.setRepositories(registry1.getRepositories());
+        Assert.assertArrayEquals(registry1.getRepositories().toArray(), registry2.getRepositories().toArray());
+    }
+
+    @Test
     public void testDefaultHealthCheckRegistry() throws Exception {
         HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
         registry.register(new MyHealthCheck("G1", "1"));
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckServiceTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckServiceTest.java
index 7b21921..2a42d92 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckServiceTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/health/DefaultHealthCheckServiceTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.impl.health;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
@@ -24,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckConfiguration;
 import org.apache.camel.health.HealthCheckRegistry;
 import org.apache.camel.health.HealthCheckResultBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -37,7 +39,7 @@ public class DefaultHealthCheckServiceTest {
         CamelContext context = null;
 
         try {
-            MyHealthCheck check = new MyHealthCheck("", HealthCheck.State.UP);
+            MyHealthCheck check = new MyHealthCheck("test", HealthCheck.State.UP);
             List<HealthCheck.State> results = new ArrayList<>();
             CountDownLatch latch = new CountDownLatch(10);
 
@@ -45,6 +47,10 @@ public class DefaultHealthCheckServiceTest {
             registry.register(check);
 
             DefaultHealthCheckService service = new DefaultHealthCheckService();
+            Map<String, Object> options = new HashMap<>();
+            options.put("test", "test");
+
+            service.setHealthCheckOptions("test", options);
             service.setCheckInterval(500, TimeUnit.MILLISECONDS);
             service.addStateChangeListener((s, c) -> {
                 results.add(s);
@@ -69,6 +75,7 @@ public class DefaultHealthCheckServiceTest {
 
             Assert.assertEquals(1, service.getResults().size());
             Assert.assertEquals(check, service.getResults().iterator().next().getCheck());
+            Assert.assertEquals(options, check.getOptions());
 
         } finally {
             if (context != null) {
@@ -84,6 +91,7 @@ public class DefaultHealthCheckServiceTest {
 
     private class MyHealthCheck extends AbstractHealthCheck {
         private HealthCheck.State state;
+        private Map<String, Object> options;
 
         MyHealthCheck(String id, HealthCheck.State state) {
             super(id);
@@ -99,6 +107,11 @@ public class DefaultHealthCheckServiceTest {
         @Override
         public void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
             builder.state(state);
+            this.options = options;
+        }
+
+        public Map<String, Object> getOptions() {
+            return options;
         }
     }
 }