You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2022/10/12 16:25:12 UTC
[sling-org-apache-sling-discovery-oak] branch SLING-11619 created (now efc3d63)
This is an automated email from the ASF dual-hosted git repository.
stefanegli pushed a change to branch SLING-11619
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-oak.git
at efc3d63 SLING-11619 : safeguard backoff factors config
This branch includes the following new commits:
new efc3d63 SLING-11619 : safeguard backoff factors config
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-discovery-oak] 01/01: SLING-11619 : safeguard backoff factors config
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
stefanegli pushed a commit to branch SLING-11619
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-oak.git
commit efc3d63e2b9741151e1a1ae8ef5182e1c9505ef4
Author: Stefan Egli <st...@apache.org>
AuthorDate: Wed Oct 12 18:25:01 2022 +0200
SLING-11619 : safeguard backoff factors config
---
.../java/org/apache/sling/discovery/oak/Config.java | 15 +++++++++++++--
.../java/org/apache/sling/discovery/oak/ConfigTest.java | 17 +++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/discovery/oak/Config.java b/src/main/java/org/apache/sling/discovery/oak/Config.java
index d596311..514ba27 100644
--- a/src/main/java/org/apache/sling/discovery/oak/Config.java
+++ b/src/main/java/org/apache/sling/discovery/oak/Config.java
@@ -22,10 +22,12 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
+import java.util.function.Function;
import org.apache.sling.discovery.base.connectors.BaseConfig;
import org.apache.sling.discovery.commons.providers.spi.base.DiscoveryLiteConfig;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentException;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.Designate;
@@ -235,8 +237,8 @@ public class Config implements BaseConfig, DiscoveryLiteConfig {
sharedKey = config.sharedKey();
keyInterval = config.hmacSharedKeyTTL();
- backoffStandbyFactor = config.backoffStandbyFactor();
- backoffStableFactor = config.backoffStableFactor();
+ backoffStandbyFactor = guard((c) -> config.backoffStandbyFactor(), "backoffStandbyFactor", DEFAULT_BACKOFF_STANDBY_FACTOR);
+ backoffStableFactor = guard((c) -> config.backoffStableFactor(), "backoffStableFactor", DEFAULT_BACKOFF_STABLE_FACTOR);
this.invertLeaderElectionPrefixOrder = config.invertLeaderElectionPrefixOrder();
logger.debug("configure: invertLeaderElectionPrefixOrder='{}'", this.invertLeaderElectionPrefixOrder);
@@ -254,6 +256,15 @@ public class Config implements BaseConfig, DiscoveryLiteConfig {
logger.debug("configure: joinerDelaySeconds='{}'", this.joinerDelaySeconds);
}
+ private Integer guard(Function<Void, Integer> injectedConfig, String key, int def) {
+ try {
+ return injectedConfig.apply(null);
+ } catch(RuntimeException re) {
+ logger.info("configure: got RuntimeException for " + key + ", using default: " + re);
+ return def;
+ }
+ }
+
/**
* Returns the socket connect() timeout used by the topology connector, 0 disables the timeout
*
diff --git a/src/test/java/org/apache/sling/discovery/oak/ConfigTest.java b/src/test/java/org/apache/sling/discovery/oak/ConfigTest.java
index eb28a1b..70096e0 100644
--- a/src/test/java/org/apache/sling/discovery/oak/ConfigTest.java
+++ b/src/test/java/org/apache/sling/discovery/oak/ConfigTest.java
@@ -26,6 +26,7 @@ import org.junit.Test;
import java.util.Dictionary;
import java.util.Hashtable;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class ConfigTest {
@@ -46,4 +47,20 @@ public class ConfigTest {
public void testIfServiceActive() {
assertNotNull(config);
}
+
+ @Test
+ public void testEmptyValues() {
+ Dictionary<String, Object> properties = new Hashtable<>();
+ properties.put("backoffStandbyFactor", "");
+ config = context.registerInjectActivateService(new Config(), properties);
+ assertEquals(5, config.getBackoffStandbyFactor());
+ properties = new Hashtable<>();
+ properties.put("backoffStandbyFactor", "4");
+ config = context.registerInjectActivateService(new Config(), properties);
+ assertEquals(4, config.getBackoffStandbyFactor());
+ properties = new Hashtable<>();
+ properties.put("backoffStableFactor", "");
+ config = context.registerInjectActivateService(new Config(), properties);
+ assertEquals(5, config.getBackoffStandbyFactor());
+ }
}
\ No newline at end of file