This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 789c68d29cbb9aec9da6021205515976d95d71da Author: Alex Heneveld <[email protected]> AuthorDate: Thu Mar 23 17:34:16 2023 +0000 tidyup and tests of latency detector / enricher --- .../policy/enricher/HttpLatencyDetector.java | 2 +- .../policy/enricher/HttpLatencyDetectorTest.java | 30 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetector.java b/policy/src/main/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetector.java index d76c1fa2ea..24a7ced7da 100644 --- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetector.java +++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetector.java @@ -231,7 +231,7 @@ public class HttpLatencyDetector extends AbstractEnricher implements Enricher { Function<String, String> postProcessor = getConfig(URL_POST_PROCESSING); String newVal = (postProcessor != null) ? postProcessor.apply(currentVal.toString()) : currentVal.toString(); if (AtomicReferences.setIfDifferent(url, newVal)) { - log.debug("{} updated url on initial connectionon, to {}", this, newVal); + log.debug("{} updated url on initial connection, to {}", this, newVal); } } } diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetectorTest.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetectorTest.java index 248891b5cb..d731cff204 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetectorTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetectorTest.java @@ -24,13 +24,16 @@ import java.util.concurrent.TimeUnit; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.sensor.AttributeSensor; +import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.entity.EntityAsserts; import org.apache.brooklyn.core.sensor.Sensors; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.util.collections.MutableMap; +import org.apache.brooklyn.util.core.config.ConfigBag; import org.apache.brooklyn.util.core.http.BetterMockWebServer; +import org.apache.brooklyn.util.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod; @@ -120,7 +123,7 @@ public class HttpLatencyDetectorTest { } @Test(groups="Integration") - public void testWaitsForServiceUp() throws Exception { + public void testWaitsForServiceUp() throws Exception { entity.sensors().set(TestEntity.SERVICE_UP, false); entity.enrichers().add(HttpLatencyDetector.builder() @@ -137,6 +140,31 @@ public class HttpLatencyDetectorTest { entity.sensors().set(TestEntity.SERVICE_UP, true); assertLatencyAttributesNonNull(entity); } + + @Test(groups="Integration") + public void testWaitsForServiceUpWhenInitializedFromConfig() throws Exception { + entity.sensors().set(TestEntity.SERVICE_UP, false); + entity.sensors().set(TEST_URL, baseUrl.toString()); + + entity.enrichers().add( + new HttpLatencyDetector(ConfigBag.newInstance() +// .configure((ConfigKey) HttpLatencyDetector.URL, baseUrl) + .configure((ConfigKey) HttpLatencyDetector.URL_SENSOR, TEST_URL.getName()) + + .configure(HttpLatencyDetector.PERIOD, Duration.millis(100)) + .configure(HttpLatencyDetector.ROLLUP_WINDOW_SIZE, Duration.millis(1000)) + .configure(HttpLatencyDetector.REQUIRE_SERVICE_UP, true) + .getAllConfig())); + + // nothing until url is set + EntityAsserts.assertAttributeEqualsContinually( + MutableMap.of("timeout", 200), + entity, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT, null); + + // gets value after url is set, and gets rolling average + entity.sensors().set(TestEntity.SERVICE_UP, true); + assertLatencyAttributesNonNull(entity); + } protected void assertLatencyAttributesNonNull(Entity entity) { EntityAsserts.assertAttributeEventuallyNonNull(entity, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT);
