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 2020/01/27 10:58:10 UTC
[sling-org-apache-sling-distribution-journal] branch master
updated: SLING-9020 - Remove support for triggering on nth error
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
The following commit(s) were added to refs/heads/master by this push:
new afa6dd6 SLING-9020 - Remove support for triggering on nth error
afa6dd6 is described below
commit afa6dd6393e59e0f017c63417403a7f173b741ba
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Mon Jan 27 11:56:56 2020 +0100
SLING-9020 - Remove support for triggering on nth error
---
.../journal/impl/shared/JournalAvailableChecker.java | 15 +++------------
.../impl/shared/JournalAvailableServiceMarker.java | 3 +++
.../journal/impl/shared/JournalAvailableCheckerTest.java | 2 +-
3 files changed, 7 insertions(+), 13 deletions(-)
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 d9fee3f..5dee552 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
@@ -23,7 +23,6 @@ import static java.time.temporal.ChronoUnit.MINUTES;
import static java.util.Objects.requireNonNull;
import java.time.Duration;
-import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.io.IOUtils;
import org.apache.sling.distribution.journal.ExceptionEventSender;
@@ -50,15 +49,10 @@ public class JournalAvailableChecker implements EventHandler {
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
- public static final int MIN_ERRORS = 1;
-
private static final Logger LOG = LoggerFactory.getLogger(JournalAvailableChecker.class);
private final ExponentialBackOff backoffRetry;
- private final AtomicInteger numErrors;
-
@Reference
Topics topics;
@@ -73,7 +67,6 @@ public class JournalAvailableChecker implements EventHandler {
private GaugeService<Boolean> gauge;
public JournalAvailableChecker() {
- this.numErrors = new AtomicInteger();
this.backoffRetry = new ExponentialBackOff(INITIAL_RETRY_DELAY, MAX_RETRY_DELAY, true, this::run);
}
@@ -104,7 +97,6 @@ public class JournalAvailableChecker implements EventHandler {
private void available() {
LOG.info("Journal is available");
- this.numErrors.set(0);
this.marker.register();
}
@@ -132,13 +124,12 @@ public class JournalAvailableChecker implements EventHandler {
@Override
public synchronized void handleEvent(Event event) {
String type = (String) event.getProperty(ExceptionEventSender.KEY_TYPE);
- int curNumErrors = this.numErrors.incrementAndGet();
- if (curNumErrors == MIN_ERRORS) {
+ if (this.marker.isRegistered()) {
LOG.warn("Received exception event {}. Journal is considered unavailable.", type);
this.marker.unRegister();
- this.backoffRetry.startChecks();
+ this.backoffRetry.startChecks();
} else {
- LOG.info("Received exception event {}. {} of {} errors occurred.", type, curNumErrors, MIN_ERRORS);
+ LOG.info("Received exception event {}. Journal still unavailable.", type);
}
}
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableServiceMarker.java b/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableServiceMarker.java
index c6ac778..287f3fa 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableServiceMarker.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/shared/JournalAvailableServiceMarker.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.distribution.journal.impl.shared;
+import java.util.Objects;
+
import org.apache.sling.distribution.journal.JournalAvailable;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -34,6 +36,7 @@ class JournalAvailableServiceMarker implements JournalAvailable {
synchronized void register() {
if (this.reg == null) {
this.reg = context.registerService(JournalAvailable.class, this, null);
+ Objects.requireNonNull(this.reg); // To make incomplete mocking visible in tests
}
}
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 2e07ae0..13ff1be 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", new RuntimeException("Nested exception")))
+ doThrow(new MessagingException("expected", new RuntimeException("expected nested exception")))
.when(provider).assertTopic(INVALID_TOPIC);
when(context.registerService(Mockito.eq(JournalAvailable.class), Mockito.any(JournalAvailable.class), Mockito.any()))
.thenReturn(sreg);