You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cs...@apache.org on 2019/11/28 10:39:30 UTC

[sling-org-apache-sling-distribution-journal] 01/02: SLING-8863 - Show more details in log message

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

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

commit da9d03d4053fad045b561fcfeefcba872831b0c8
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Wed Nov 27 20:12:43 2019 +0100

    SLING-8863 - Show more details in log message
---
 .gitignore                                            |  1 +
 .../journal/impl/shared/JournalAvailableChecker.java  | 19 ++++++++++++++++---
 .../impl/shared/JournalAvailableCheckerTest.java      |  6 +++---
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5b783ed..aa74147 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ maven-eclipse.xml
 .DS_Store
 jcr.log
 atlassian-ide-plugin.xml
+/.vscode/
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableChecker.java b/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableChecker.java
index eb878b2..ea479a5 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableChecker.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableChecker.java
@@ -18,8 +18,8 @@
  */
 package org.apache.sling.distribution.journal.impl.shared;
 
+import static java.time.temporal.ChronoUnit.MILLIS;
 import static java.time.temporal.ChronoUnit.MINUTES;
-import static java.time.temporal.ChronoUnit.SECONDS;
 import static java.util.Objects.requireNonNull;
 
 import java.time.Duration;
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
 )
 public class JournalAvailableChecker implements EventHandler {
     
-    private static final Duration INITIAL_RETRY_DELAY = Duration.of(1, SECONDS);
+    private static final Duration INITIAL_RETRY_DELAY = Duration.of(500, MILLIS);
     private static final Duration MAX_RETRY_DELAY = Duration.of(5, MINUTES);
 
     // Minimal number of errors before journal is considered unavailable
@@ -113,11 +113,24 @@ public class JournalAvailableChecker implements EventHandler {
         if (LOG.isDebugEnabled()) {
             LOG.warn(msg, e);
         } else {
-            LOG.warn(msg);
+            LOG.warn(accumulatedMessage(e));
         }
         this.marker.unRegister();
     }
     
+    private String accumulatedMessage(Exception e) {
+        StringBuilder msg = new StringBuilder();
+        Throwable th = e;
+        do {
+            msg.append(th.getMessage());
+            th = th.getCause();
+            if (th != null) {
+                msg.append(". Caused by: ");
+            }
+        } while (th != null);
+        return msg.toString();
+    }
+
     public boolean isAvailable() {
         return this.marker.isRegistered();
     }
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableCheckerTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableCheckerTest.java
index fb407a2..40c7666 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableCheckerTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableCheckerTest.java
@@ -81,7 +81,7 @@ public class JournalAvailableCheckerTest {
     @Before
     public void before() throws Exception {
         when(metrics.createGauge(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(gauge);
-        doThrow(new MessagingException("topic is invalid"))
+        doThrow(new MessagingException("topic is invalid", new RuntimeException("Nested exception")))
                 .when(provider).assertTopic(INVALID_TOPIC);
         when(context.registerService(Mockito.eq(JournalAvailable.class), Mockito.any(JournalAvailable.class), Mockito.any()))
                 .thenReturn(sreg);
@@ -108,7 +108,7 @@ public class JournalAvailableCheckerTest {
     }
 
     @Test
-    public void testActivateChecksOnEvent() {
+    public void testActivateChecksOnEvent() throws InterruptedException {
         await("At the start checks are triggers and should set the state available")
             .until(checker::isAvailable);
         
@@ -119,7 +119,7 @@ public class JournalAvailableCheckerTest {
         // Signal second exception to checker to start the checks. Now we should see not available
         checker.handleEvent(event);
         await().until(() -> !checker.isAvailable());
-        
+        Thread.sleep(1000); // Make sure we get at least one failed doCheck
         makeCheckSucceed();
         await().until(checker::isAvailable);
     }