SLING-9020 - Remove support for triggering on nth error
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.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 @@
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 @@
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 @@
private void available() {
LOG.info("Journal is available");
- this.numErrors.set(0);
this.marker.register();
}
@@ -132,13 +124,12 @@
@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 @@
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 @@
@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);