http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java index 9637235..1e4fb97 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java @@ -62,7 +62,7 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .minPoolSize(2) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.MIN_POOL_SIZE, 3); @@ -77,15 +77,15 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .minPoolSize(2) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); // 25*4 = 100 -> 2 nodes at 50 each - tc.setAttribute(MY_ATTRIBUTE, 25); + tc.sensors().set(MY_ATTRIBUTE, 25); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 2)); // Decreases to new min-size policy.config().set(AutoScalerPolicy.MIN_POOL_SIZE, 1); - tc.setAttribute(MY_ATTRIBUTE, 0); + tc.sensors().set(MY_ATTRIBUTE, 0); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 1)); } @@ -97,7 +97,7 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .maxPoolSize(6) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.MAX_POOL_SIZE, 4); @@ -112,16 +112,16 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .maxPoolSize(6) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); // 200*3 = 600 -> 6 nodes at 100 each - tc.setAttribute(MY_ATTRIBUTE, 200); + tc.sensors().set(MY_ATTRIBUTE, 200); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 6)); policy.config().set(AutoScalerPolicy.MAX_POOL_SIZE, 8); // Increases to max-size only - tc.setAttribute(MY_ATTRIBUTE, 100000); + tc.sensors().set(MY_ATTRIBUTE, 100000); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 8)); } @@ -132,11 +132,11 @@ public class AutoScalerPolicyReconfigurationTest { AutoScalerPolicy policy = new AutoScalerPolicy.Builder().metric(MY_ATTRIBUTE) .metricLowerBound(50).metricUpperBound(100) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.METRIC_LOWER_BOUND, 51); - tc.setAttribute(MY_ATTRIBUTE, 50); + tc.sensors().set(MY_ATTRIBUTE, 50); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 1)); } @@ -147,11 +147,11 @@ public class AutoScalerPolicyReconfigurationTest { AutoScalerPolicy policy = new AutoScalerPolicy.Builder().metric(MY_ATTRIBUTE) .metricLowerBound(50).metricUpperBound(100) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.METRIC_UPPER_BOUND, 99); - tc.setAttribute(MY_ATTRIBUTE, 100); + tc.sensors().set(MY_ATTRIBUTE, 100); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 2)); } @@ -163,11 +163,11 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .resizeUpStabilizationDelay(Duration.TWO_MINUTES) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.RESIZE_UP_STABILIZATION_DELAY, Duration.ZERO); - tc.setAttribute(MY_ATTRIBUTE, 101); + tc.sensors().set(MY_ATTRIBUTE, 101); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 2)); } @@ -179,11 +179,11 @@ public class AutoScalerPolicyReconfigurationTest { .metricLowerBound(50).metricUpperBound(100) .resizeDownStabilizationDelay(Duration.TWO_MINUTES) .build(); - tc.addPolicy(policy); + tc.policies().add(policy); policy.config().set(AutoScalerPolicy.RESIZE_DOWN_STABILIZATION_DELAY, Duration.ZERO); - tc.setAttribute(MY_ATTRIBUTE, 1); + tc.sensors().set(MY_ATTRIBUTE, 1); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc, 1)); } }
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java index 9cd149a..c324dbe 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java @@ -87,7 +87,7 @@ public class AutoScalerPolicyTest { return ((Resizable)entity).resize(desiredSize); } }); - policy = resizable.addPolicy(policySpec); + policy = resizable.policies().add(policySpec); policyResizes.clear(); } @@ -109,7 +109,7 @@ public class AutoScalerPolicyTest { public void testShrinkColdPool() throws Exception { resizable.resize(4); // all metrics as per-node here - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(30d/4, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(30d/4, 10, 20)); // expect pool to shrink to 3 (i.e. maximum to have >= 10 per container) assertSizeEventually(3); @@ -119,7 +119,7 @@ public class AutoScalerPolicyTest { public void testShrinkColdPoolTotals() throws Exception { resizable.resize(4); // all metrics as totals here - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(30L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(30L, 4*10L, 4*20L)); // expect pool to shrink to 3 (i.e. maximum to have >= 10 per container) assertSizeEventually(3); @@ -128,7 +128,7 @@ public class AutoScalerPolicyTest { @Test public void testShrinkColdPoolRoundsUpDesiredNumberOfContainers() throws Exception { resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1L, 4*10L, 4*20L)); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1)); } @@ -137,7 +137,7 @@ public class AutoScalerPolicyTest { public void testGrowHotPool() throws Exception { resizable.resize(2); // all metrics as per-node here - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(21L, 10L, 20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(21L, 10L, 20L)); // expect pool to grow to 3 (i.e. minimum to have <= 20 per container) assertSizeEventually(3); @@ -147,7 +147,7 @@ public class AutoScalerPolicyTest { public void testGrowHotPoolTotals() throws Exception { resizable.resize(2); // all metrics as totals here - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(41L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(41L, 2*10L, 2*20L)); // expect pool to grow to 3 (i.e. minimum to have <= 20 per container) assertSizeEventually(3); @@ -161,50 +161,50 @@ public class AutoScalerPolicyTest { policy.config().set(AutoScalerPolicy.RESIZE_DOWN_ITERATION_INCREMENT, 3); policy.config().set(AutoScalerPolicy.RESIZE_DOWN_ITERATION_MAX, 3); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(42/2, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(42/2, 10, 20)); // expect pool to grow to 4 (i.e. to have <= 20 per container we need 3, but increment is 2) assertSizeEventually(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(200/4, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(200/4, 10, 20)); // a single hot message can only make it go to 8 assertSizeEventually(8); assertEquals(policyResizes, MutableList.of(4, 8)); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(200/8, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(200/8, 10, 20)); assertSizeEventually(10); assertEquals(policyResizes, MutableList.of(4, 8, 10)); // now shrink policyResizes.clear(); policy.config().set(AutoScalerPolicy.MIN_POOL_SIZE, 2); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); assertSizeEventually(7); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); assertSizeEventually(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(1, 10, 20)); assertSizeEventually(2); assertEquals(policyResizes, MutableList.of(7, 4, 2)); } @Test public void testHasId() throws Exception { - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .minPoolSize(2) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); Assert.assertTrue(policy.getId()!=null); } @Test public void testNeverShrinkBelowMinimum() throws Exception { - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .minPoolSize(2) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 0L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 0L, 4*10L, 4*20L)); // expect pool to shrink only to the minimum Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 2)); @@ -212,14 +212,14 @@ public class AutoScalerPolicyTest { @Test public void testNeverGrowAboveMaximmum() throws Exception { - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .maxPoolSize(5) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 1000000L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 1000000L, 4*10L, 4*20L)); // expect pool to grow only to the maximum Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 5)); @@ -228,7 +228,7 @@ public class AutoScalerPolicyTest { @Test public void testNeverGrowColdPool() throws Exception { resizable.resize(2); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1000L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1000L, 2*10L, 2*20L)); Thread.sleep(SHORT_WAIT_MS); assertEquals(resizable.getCurrentSize(), (Integer)2); @@ -238,7 +238,7 @@ public class AutoScalerPolicyTest { public void testNeverShrinkHotPool() throws Exception { resizable.resizeSleepTime = 0; resizable.resize(2); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 0L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 0L, 2*10L, 2*20L)); // if had been a POOL_COLD, would have shrunk to 3 Thread.sleep(SHORT_WAIT_MS); @@ -249,10 +249,10 @@ public class AutoScalerPolicyTest { public void testConcurrentShrinkShrink() throws Exception { resizable.resizeSleepTime = 250; resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L)); // would cause pool to shrink to 3 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L)); // now expect pool to shrink to 1 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1)); @@ -262,10 +262,10 @@ public class AutoScalerPolicyTest { public void testConcurrentGrowGrow() throws Exception { resizable.resizeSleepTime = 250; resizable.resize(2); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 41L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 41L, 2*10L, 2*20L)); // would cause pool to grow to 3 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L)); // now expect pool to grow to 5 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 5)); @@ -275,10 +275,10 @@ public class AutoScalerPolicyTest { public void testConcurrentGrowShrink() throws Exception { resizable.resizeSleepTime = 250; resizable.resize(2); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L)); // would cause pool to grow to 5 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1L, 2*10L, 2*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1L, 2*10L, 2*20L)); // now expect pool to shrink to 1 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1)); @@ -288,10 +288,10 @@ public class AutoScalerPolicyTest { public void testConcurrentShrinkGrow() throws Exception { resizable.resizeSleepTime = 250; resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L)); // would cause pool to shrink to 1 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 81L, 4*10L, 4*20L)); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 81L, 4*10L, 4*20L)); // now expect pool to grow to 5 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 5)); @@ -304,9 +304,9 @@ public class AutoScalerPolicyTest { // TODO is this too time sensitive? the resize takes only 250ms so if it finishes before the next emit we'd also see size=2 resizable.resizeSleepTime = 500; resizable.resize(4); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L)); // shrink to 3 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 20L, 4*10L, 4*20L)); // shrink to 2 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 10L, 4*10L, 4*20L)); // shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L)); // shrink to 3 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 20L, 4*10L, 4*20L)); // shrink to 2 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 10L, 4*10L, 4*20L)); // shrink to 1 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1)); assertEquals(resizable.sizes, ImmutableList.of(4, 3, 1)); @@ -315,7 +315,7 @@ public class AutoScalerPolicyTest { @Test public void testUsesResizeOperatorOverride() throws Exception { - resizable.removePolicy(policy); + resizable.policies().remove(policy); final AtomicInteger counter = new AtomicInteger(); policy = AutoScalerPolicy.builder() @@ -325,9 +325,9 @@ public class AutoScalerPolicyTest { return desiredSize; }}) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 21L, 1*10L, 1*20L)); // grow to 2 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 21L, 1*10L, 1*20L)); // grow to 2 Asserts.succeedsEventually(MutableMap.of("timeout",TIMEOUT_MS), new Runnable() { public void run() { @@ -337,7 +337,7 @@ public class AutoScalerPolicyTest { @Test public void testUsesCustomSensorOverride() throws Exception { - resizable.removePolicy(policy); + resizable.policies().remove(policy); @SuppressWarnings("rawtypes") BasicNotificationSensor<Map> customPoolHotSensor = new BasicNotificationSensor<Map>(Map.class, "custom.hot", ""); @@ -350,12 +350,12 @@ public class AutoScalerPolicyTest { .poolColdSensor(customPoolColdSensor) .poolOkSensor(customPoolOkSensor) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); - resizable.emit(customPoolHotSensor, message(1, 21L, 1*10L, 1*20L)); // grow to 2 + resizable.sensors().emit(customPoolHotSensor, message(1, 21L, 1*10L, 1*20L)); // grow to 2 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 2)); - resizable.emit(customPoolColdSensor, message(2, 1L, 1*10L, 1*20L)); // shrink to 1 + resizable.sensors().emit(customPoolColdSensor, message(2, 1L, 1*10L, 1*20L)); // shrink to 1 Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1)); } @@ -363,19 +363,19 @@ public class AutoScalerPolicyTest { public void testResizeUpStabilizationDelayIgnoresBlip() throws Exception { long resizeUpStabilizationDelay = 1000L; Duration minPeriodBetweenExecs = Duration.ZERO; - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(1); // Ignores temporary blip - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 Thread.sleep(resizeUpStabilizationDelay-OVERHEAD_DURATION_MS); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(1, 11L, 4*10L, 4*20L)); // but 1 is still adequate + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(1, 11L, 4*10L, 4*20L)); // but 1 is still adequate assertEquals(resizable.getCurrentSize(), (Integer)1); Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() { @@ -407,26 +407,26 @@ public class AutoScalerPolicyTest { public void testResizeUpStabilizationDelayTakesMaxSustainedDesired() throws Exception { long resizeUpStabilizationDelay = 1100L; Duration minPeriodBetweenExecs = Duration.ZERO; - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(1); // Will grow to only the max sustained in this time window // (i.e. to 2 within the first $resizeUpStabilizationDelay milliseconds) Stopwatch stopwatch = Stopwatch.createStarted(); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 21L, 1*10L, 1*20L)); // would grow to 2 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 21L, 1*10L, 1*20L)); // would grow to 2 Thread.sleep(resizeUpStabilizationDelay-OVERHEAD_DURATION_MS); long postSleepTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 61L, 1*10L, 1*20L)); // would grow to 4 // Wait for it to reach size 2, and confirm take expected time // TODO This is time sensitive, and sometimes fails in CI with size=4 if we wait for currentSize==2 (presumably GC kicking in?) @@ -457,9 +457,9 @@ public class AutoScalerPolicyTest { public void testResizeUpStabilizationDelayResizesAfterDelay() { final long resizeUpStabilizationDelay = 1000L; Duration minPeriodBetweenExecs = Duration.ZERO; - resizable.removePolicy(policy); + resizable.policies().remove(policy); - policy = resizable.addPolicy(AutoScalerPolicy.builder() + policy = resizable.policies().add(AutoScalerPolicy.builder() .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .buildSpec()); @@ -468,14 +468,14 @@ public class AutoScalerPolicyTest { // After suitable delay, grows to desired final long emitTime = System.currentTimeMillis(); final Map<String, Object> need4 = message(1, 61L, 1*10L, 1*20L); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, need4); // would grow to 4 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, need4); // would grow to 4 final AtomicInteger emitCount = new AtomicInteger(0); Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { public void run() { if (System.currentTimeMillis() - emitTime > (2+emitCount.get())*resizeUpStabilizationDelay) { //first one may not have been received, in a registration race - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, need4); + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, need4); emitCount.incrementAndGet(); } assertEquals(resizable.getCurrentSize(), (Integer)4); @@ -489,19 +489,19 @@ public class AutoScalerPolicyTest { public void testResizeDownStabilizationDelayIgnoresBlip() throws Exception { long resizeStabilizationDelay = 1000L; Duration minPeriodBetweenExecs = Duration.ZERO; - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .resizeDownStabilizationDelay(Duration.of(resizeStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(2); // Ignores temporary blip - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1L, 2*10L, 2*20L)); // would shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1L, 2*10L, 2*20L)); // would shrink to 1 Thread.sleep(resizeStabilizationDelay-OVERHEAD_DURATION_MS); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(2, 20L, 1*10L, 1*20L)); // but 2 is still adequate + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(2, 20L, 1*10L, 1*20L)); // but 2 is still adequate assertEquals(resizable.getCurrentSize(), (Integer)2); Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() { @@ -526,26 +526,26 @@ public class AutoScalerPolicyTest { long resizeDownStabilizationDelay = 1100L; Duration minPeriodBetweenExecs = Duration.ZERO; policy.suspend(); - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .resizeDownStabilizationDelay(Duration.of(resizeDownStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(3); // Will shrink to only the min sustained in this time window // (i.e. to 2 within the first $resizeUpStabilizationDelay milliseconds) Stopwatch stopwatch = Stopwatch.createStarted(); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 1L, 3*10L, 3*20L)); // would shrink to 1 - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 20L, 3*10L, 3*20L)); // would shrink to 2 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 1L, 3*10L, 3*20L)); // would shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 20L, 3*10L, 3*20L)); // would shrink to 2 Thread.sleep(resizeDownStabilizationDelay-OVERHEAD_DURATION_MS); long postSleepTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 1L, 3*10L, 3*20L)); // would shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(3, 1L, 3*10L, 3*20L)); // would shrink to 1 // Wait for it to reach size 2, and confirm take expected time // TODO This is time sensitive, and sometimes fails in CI with size=1 if we wait for currentSize==2 (presumably GC kicking in?) @@ -576,26 +576,26 @@ public class AutoScalerPolicyTest { public void testResizeDownStabilizationDelayResizesAfterDelay() throws Exception { final long resizeDownStabilizationDelay = 1000L; Duration minPeriodBetweenExecs = Duration.ZERO; - resizable.removePolicy(policy); + resizable.policies().remove(policy); policy = AutoScalerPolicy.builder() .resizeDownStabilizationDelay(Duration.of(resizeDownStabilizationDelay, TimeUnit.MILLISECONDS)) .minPeriodBetweenExecs(minPeriodBetweenExecs) .build(); - resizable.addPolicy(policy); + resizable.policies().add(policy); resizable.resize(2); // After suitable delay, grows to desired final long emitTime = System.currentTimeMillis(); final Map<String, Object> needJust1 = message(2, 1L, 2*10L, 2*20L); - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, needJust1); // would shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, needJust1); // would shrink to 1 final AtomicInteger emitCount = new AtomicInteger(0); Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { public void run() { if (System.currentTimeMillis() - emitTime > (2+emitCount.get())*resizeDownStabilizationDelay) { //first one may not have been received, in a registration race - resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, needJust1); // would shrink to 1 + resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, needJust1); // would shrink to 1 emitCount.incrementAndGet(); } assertEquals(resizable.getCurrentSize(), (Integer)1); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java index d5dec9e..5550899 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java @@ -45,7 +45,7 @@ public class LocallyResizableEntity extends AbstractEntity implements Resizable public LocallyResizableEntity (Entity parent, TestCluster tc) { super(parent); this.cluster = tc; - setAttribute(Startable.SERVICE_UP, true); + sensors().set(Startable.SERVICE_UP, true); } @Override http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.groovy ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.groovy b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.groovy index 2004ebd..3c5f192 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.groovy +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.groovy @@ -59,7 +59,7 @@ class DeltaEnrichersTests { @Test public void testDeltaEnricher() { DeltaEnricher delta = new DeltaEnricher<Integer>(producer, intSensor, deltaSensor) - producer.addEnricher(delta) + producer.enrichers().add(delta) delta.onEvent(intSensor.newEvent(producer, 0)) delta.onEvent(intSensor.newEvent(producer, 0)) @@ -76,7 +76,7 @@ class DeltaEnrichersTests { public void testMonospaceTimeWeightedDeltaEnricher() { TimeWeightedDeltaEnricher delta = TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer, intSensor, deltaSensor) - producer.addEnricher(delta) + producer.enrichers().add(delta) delta.onEvent(intSensor.newEvent(producer, 0), 0) assertEquals(producer.getAttribute(deltaSensor), null) @@ -94,7 +94,7 @@ class DeltaEnrichersTests { public void testVariableTimeWeightedDeltaEnricher() { TimeWeightedDeltaEnricher delta = TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer, intSensor, deltaSensor) - producer.addEnricher(delta) + producer.enrichers().add(delta) delta.onEvent(intSensor.newEvent(producer, 0), 0) delta.onEvent(intSensor.newEvent(producer, 0), 2000) @@ -112,7 +112,7 @@ class DeltaEnrichersTests { @Test public void testPostProcessorCalledForDeltaEnricher() { TimeWeightedDeltaEnricher delta = new TimeWeightedDeltaEnricher(producer, intSensor, deltaSensor, 1000, {it+123}) - producer.addEnricher(delta) + producer.enrichers().add(delta) delta.onEvent(intSensor.newEvent(producer, 0), 0) delta.onEvent(intSensor.newEvent(producer, 0), 1000) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/HttpLatencyDetectorTest.java ---------------------------------------------------------------------- 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 0aeac73..d361898 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 @@ -76,9 +76,9 @@ public class HttpLatencyDetectorTest { @Test(groups="Integration") public void testPollsUrl() throws Exception { - entity.setAttribute(TestEntity.SERVICE_UP, true); + entity.sensors().set(TestEntity.SERVICE_UP, true); - entity.addEnricher(HttpLatencyDetector.builder() + entity.enrichers().add(HttpLatencyDetector.builder() .url(baseUrl) .rollup(500, TimeUnit.MILLISECONDS) .period(100, TimeUnit.MILLISECONDS) @@ -89,7 +89,7 @@ public class HttpLatencyDetectorTest { @Test(groups="Integration") public void testWaitsForSensorThenPolls() throws Exception { - entity.addEnricher(HttpLatencyDetector.builder() + entity.enrichers().add(HttpLatencyDetector.builder() .url(TEST_URL) .noServiceUp() .rollup(500, TimeUnit.MILLISECONDS) @@ -102,15 +102,15 @@ public class HttpLatencyDetectorTest { entity, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT, null); // gets value after url is set, and gets rolling average - entity.setAttribute(TEST_URL, baseUrl.toString()); + entity.sensors().set(TEST_URL, baseUrl.toString()); assertLatencyAttributesNonNull(entity); } @Test(groups="Integration") public void testGetsSensorIfAlredySetThenPolls() throws Exception { - entity.setAttribute(TEST_URL, baseUrl.toString()); + entity.sensors().set(TEST_URL, baseUrl.toString()); - entity.addEnricher(HttpLatencyDetector.builder() + entity.enrichers().add(HttpLatencyDetector.builder() .url(TEST_URL) .noServiceUp() .rollup(500, TimeUnit.MILLISECONDS) @@ -122,9 +122,9 @@ public class HttpLatencyDetectorTest { @Test(groups="Integration") public void testWaitsForServiceUp() throws Exception { - entity.setAttribute(TestEntity.SERVICE_UP, false); + entity.sensors().set(TestEntity.SERVICE_UP, false); - entity.addEnricher(HttpLatencyDetector.builder() + entity.enrichers().add(HttpLatencyDetector.builder() .url(baseUrl) .period(100, TimeUnit.MILLISECONDS) .build()); @@ -135,7 +135,7 @@ public class HttpLatencyDetectorTest { entity, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT, null); // gets value after url is set, and gets rolling average - entity.setAttribute(TestEntity.SERVICE_UP, true); + entity.sensors().set(TestEntity.SERVICE_UP, true); assertLatencyAttributesNonNull(entity); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java index 7f3dfb1..434eb99 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java @@ -63,12 +63,12 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp { @Test public void testDeltaEnricher() throws Exception { - origApp.addEnricher(new DeltaEnricher<Integer>(origApp, INT_METRIC, INT_METRIC2)); + origApp.enrichers().add(new DeltaEnricher<Integer>(origApp, INT_METRIC, INT_METRIC2)); TestApplication newApp = rebind(); - newApp.setAttribute(INT_METRIC, 1); - newApp.setAttribute(INT_METRIC, 10); + newApp.sensors().set(INT_METRIC, 1); + newApp.sensors().set(INT_METRIC, 10); EntityTestUtils.assertAttributeEqualsEventually(newApp, INT_METRIC2, 9); } @@ -81,17 +81,17 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp { webServer.play(); URL baseUrl = webServer.getUrl("/"); - origApp.addEnricher(HttpLatencyDetector.builder() + origApp.enrichers().add(HttpLatencyDetector.builder() .rollup(Duration.of(50, TimeUnit.MILLISECONDS)) .period(Duration.of(10, TimeUnit.MILLISECONDS)) .url(baseUrl) .build()); - origApp.setAttribute(Attributes.SERVICE_UP, true); + origApp.sensors().set(Attributes.SERVICE_UP, true); TestApplication newApp = rebind(); - newApp.setAttribute(HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT, null); - newApp.setAttribute(HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW, null); + newApp.sensors().set(HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT, null); + newApp.sensors().set(HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW, null); EntityTestUtils.assertAttributeEventuallyNonNull(newApp, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT); EntityTestUtils.assertAttributeEventuallyNonNull(newApp, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW); @@ -99,29 +99,29 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp { @Test public void testRollingMeanEnricher() throws Exception { - origApp.addEnricher(new RollingMeanEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, 2)); + origApp.enrichers().add(new RollingMeanEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, 2)); TestApplication newApp = rebind(); - newApp.setAttribute(INT_METRIC, 10); + newApp.sensors().set(INT_METRIC, 10); EntityTestUtils.assertAttributeEqualsEventually(newApp, DOUBLE_METRIC, 10d); } @Test public void testRollingTimeWindowMeanEnricher() throws Exception { - origApp.addEnricher(new RollingTimeWindowMeanEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, Duration.of(10, TimeUnit.MILLISECONDS))); + origApp.enrichers().add(new RollingTimeWindowMeanEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, Duration.of(10, TimeUnit.MILLISECONDS))); TestApplication newApp = rebind(); - newApp.setAttribute(INT_METRIC, 10); + newApp.sensors().set(INT_METRIC, 10); Time.sleep(Duration.millis(10)); - newApp.setAttribute(INT_METRIC, 10); + newApp.sensors().set(INT_METRIC, 10); EntityTestUtils.assertAttributeEqualsEventually(newApp, DOUBLE_METRIC, 10d); } @Test public void testTimeFractionDeltaEnricher() throws Exception { - origApp.addEnricher(new TimeFractionDeltaEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, TimeUnit.MILLISECONDS)); + origApp.enrichers().add(new TimeFractionDeltaEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, TimeUnit.MILLISECONDS)); final TestApplication newApp = rebind(); @@ -130,14 +130,14 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp { Asserts.succeedsEventually(new Runnable() { private int counter; public void run() { - newApp.setAttribute(INT_METRIC, counter++); + newApp.sensors().set(INT_METRIC, counter++); assertNotNull(newApp.getAttribute(DOUBLE_METRIC)); }}); } @Test public void testTimeWeightedDeltaEnricher() throws Exception { - origApp.addEnricher(new TimeWeightedDeltaEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, 1000)); + origApp.enrichers().add(new TimeWeightedDeltaEnricher<Integer>(origApp, INT_METRIC, DOUBLE_METRIC, 1000)); final TestApplication newApp = rebind(); @@ -146,7 +146,7 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp { Asserts.succeedsEventually(new Runnable() { private int counter; public void run() { - newApp.setAttribute(INT_METRIC, counter++); + newApp.sensors().set(INT_METRIC, counter++); assertNotNull(newApp.getAttribute(DOUBLE_METRIC)); }}); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.groovy ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.groovy b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.groovy index 7e5ae62..bb7d2b7 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.groovy +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.groovy @@ -53,9 +53,9 @@ class RollingMeanEnricherTest { deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor") avgSensor = new BasicAttributeSensor<Double>(Integer.class, "avg sensor") - producer.addEnricher(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor)) + producer.enrichers().add(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor)) averager = new RollingMeanEnricher<Integer>(producer, deltaSensor, avgSensor, 4) - producer.addEnricher(averager) + producer.enrichers().add(averager) } @AfterMethod(alwaysRun=true) @@ -71,7 +71,7 @@ class RollingMeanEnricherTest { @Test public void testZeroWindowSize() { averager = new RollingMeanEnricher<Integer>(producer, deltaSensor, avgSensor, 0) - producer.addEnricher(averager) + producer.enrichers().add(averager) averager.onEvent(intSensor.newEvent(producer, 10)) assertEquals(averager.getAverage(), null) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.groovy ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.groovy b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.groovy index bd9c13f..492d672 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.groovy +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.groovy @@ -57,9 +57,9 @@ class RollingTimeWindowMeanEnricherTest { deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor") avgSensor = new BasicAttributeSensor<Double>(Integer.class, "avg sensor") - producer.addEnricher(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor)) + producer.enrichers().add(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor)) averager = new RollingTimeWindowMeanEnricher<Integer>(producer, deltaSensor, avgSensor, timePeriod) - producer.addEnricher(averager) + producer.enrichers().add(averager) } @AfterMethod(alwaysRun=true) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java index bd18631..6f260a1 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java @@ -66,7 +66,7 @@ public class TimeFractionDeltaEnricherTest { @Test public void testCalculatesFractions() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, TimeUnit.MILLISECONDS); - producer.addEnricher(enricher); + producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1001000L)); @@ -85,7 +85,7 @@ public class TimeFractionDeltaEnricherTest { @Test public void testConvertsTimeUnits() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, TimeUnit.MICROSECONDS); - producer.addEnricher(enricher); + producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 1000000, 1001000L)); @@ -95,7 +95,7 @@ public class TimeFractionDeltaEnricherTest { @Test public void testConverts100NanosTimeBlocks() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, 100); - producer.addEnricher(enricher); + producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 10000000, 1001000L)); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/followthesun/AbstractFollowTheSunPolicyTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/AbstractFollowTheSunPolicyTest.java b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/AbstractFollowTheSunPolicyTest.java index ba62dc7..bd1ef6f 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/AbstractFollowTheSunPolicyTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/AbstractFollowTheSunPolicyTest.java @@ -102,13 +102,13 @@ public class AbstractFollowTheSunPolicyTest { pool = app.createAndManageChild(EntitySpec.create(FollowTheSunPool.class)); pool.setContents(containerGroup, itemGroup); policy = new FollowTheSunPolicy(MockItemEntity.ITEM_USAGE_METRIC, model, FollowTheSunParameters.newDefault()); - pool.addPolicy(policy); + pool.policies().add(policy); app.start(ImmutableList.of(loc1, loc2)); } @AfterMethod(alwaysRun=true) public void tearDown() { - if (pool != null && policy != null) pool.removePolicy(policy); + if (pool != null && policy != null) pool.policies().remove(policy); if (app != null) Entities.destroyAll(app.getManagementContext()); MockItemEntityImpl.totalMoveCount.set(0); MockItemEntityImpl.lastMoveTime.set(0); @@ -229,7 +229,7 @@ public class AbstractFollowTheSunPolicyTest { protected static MockItemEntity newItem(TestApplication app, MockContainerEntity container, String name, Map<? extends Entity, Double> workpattern) { MockItemEntity item = newItem(app, container, name); if (workpattern != null) { - ((EntityLocal)item).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, (Map) workpattern); + ((EntityLocal)item).sensors().set(MockItemEntity.ITEM_USAGE_METRIC, (Map) workpattern); } return item; } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicySoakTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicySoakTest.java b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicySoakTest.java index 44be76b..9649193 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicySoakTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicySoakTest.java @@ -211,7 +211,7 @@ public class FollowTheSunPolicySoakTest extends AbstractFollowTheSunPolicyTest { double jitteredWorkrate = Math.max(0, baseWorkrate + (random.nextDouble()*jitter*2 - jitter)); workrates.put(source, jitteredWorkrate); } - ((EntityLocal)item).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, workrates); + ((EntityLocal)item).sensors().set(MockItemEntity.ITEM_USAGE_METRIC, workrates); } // Stop containers, and start others http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicyTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicyTest.java b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicyTest.java index 325400e..a334cd7 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicyTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/followthesun/FollowTheSunPolicyTest.java @@ -28,7 +28,6 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntityLocal; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; @@ -59,7 +58,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { final MockContainerEntity containerA = newContainer(app, loc1, "A"); final MockItemEntity item1 = newItem(app, containerA, "1"); final MockItemEntity item2 = newItem(app, containerA, "2"); - ((EntityLocal)item2).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 11d)); + item2.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 11d)); Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() { @Override public void run() { @@ -73,7 +72,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { @Test public void testPolicyAcceptsLocationFinder() { - pool.removePolicy(policy); + pool.policies().remove(policy); Function<Entity, Location> customLocationFinder = new Function<Entity, Location>() { @Override public Location apply(Entity input) { @@ -86,7 +85,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { model, FollowTheSunParameters.newDefault()); - pool.addPolicy(customPolicy); + pool.policies().add(customPolicy); final MockContainerEntity containerA = newContainer(app, loc1, "A"); @@ -116,7 +115,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.<MockItemEntity>of(), containerB, ImmutableList.of(item1, item2))); } @@ -129,7 +128,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 0.1d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 0.1d)); Thread.sleep(SHORT_WAIT_MS); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1), containerB, ImmutableList.of(item2))); @@ -144,7 +143,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item2 = newItem(app, containerA, "2"); MockItemEntity item3 = newItem(app, containerB, "3"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 100.1d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 100.1d)); Thread.sleep(SHORT_WAIT_MS); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1, item2), containerB, ImmutableList.of(item3))); @@ -158,8 +157,8 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 100d)); - ((EntityLocal)item2).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 100d)); + item2.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); Thread.sleep(SHORT_WAIT_MS); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1), containerB, ImmutableList.of(item2))); @@ -174,7 +173,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item2 = newItem(app, containerA, "2"); MockItemEntity item3 = newItem(app, containerB, "3"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 1000d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 1000d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item2), containerB, ImmutableList.of(item1, item3))); @@ -193,7 +192,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item2 = newItem(app, containerA, "2"); MockItemEntity item3 = newItem(app, containerB, "3"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 1000d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 1000d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item2), containerB, ImmutableList.of(item1, item3))); @@ -209,7 +208,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item1 = newLockedItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerB, "2"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1), containerB, ImmutableList.of(item2))); } @@ -221,7 +220,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { MockItemEntity item1 = newLockedItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerA, "2"); - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item1, 100d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1, item2), containerB, ImmutableList.<MockItemEntity>of())); } @@ -247,7 +246,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { final long minPeriodBetweenExecs = 1000; final long timePrecision = 250; - pool.removePolicy(policy); + pool.policies().remove(policy); MockContainerEntity containerA = newContainer(app, loc1, "A"); MockContainerEntity containerB = newContainer(app, loc2, "B"); @@ -261,7 +260,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { model, FollowTheSunParameters.newDefault()); - pool.addPolicy(customPolicy); + pool.policies().add(customPolicy); // Record times that things are moved, by lisening to the container sensor being set final Stopwatch stopwatch = Stopwatch.createStarted(); @@ -269,7 +268,7 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { final List<Long> eventTimes = Lists.newCopyOnWriteArrayList(); final Semaphore semaphore = new Semaphore(0); - app.subscribe(item1, Movable.CONTAINER, new SensorEventListener<Entity>() { + app.subscriptions().subscribe(item1, Movable.CONTAINER, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { long eventTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); LOG.info("Received {} at {}", event, eventTime); @@ -280,12 +279,12 @@ public class FollowTheSunPolicyTest extends AbstractFollowTheSunPolicyTest { String errmsg = ""; for (int i = 0; i < MAX_ATTEMPTS; i++) { // Set the workrate, causing the policy to move item1 to item2's location, and wait for it to happen - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d)); assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertEquals(item1.getAttribute(Movable.CONTAINER), containerB); // now cause item1 to be moved to item3's location, and wait for it to happen - ((EntityLocal)item1).setAttribute(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item3, 100d)); + item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item3, 100d)); assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS)); assertEquals(item1.getAttribute(Movable.CONTAINER), containerA); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/ha/ConnectionFailureDetectorTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/ha/ConnectionFailureDetectorTest.java b/policy/src/test/java/org/apache/brooklyn/policy/ha/ConnectionFailureDetectorTest.java index 6faf6ac..1b34c11 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/ha/ConnectionFailureDetectorTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/ha/ConnectionFailureDetectorTest.java @@ -122,7 +122,7 @@ public class ConnectionFailureDetectorTest { public void testNotNotifiedOfFailuresForHealthy() throws Exception { // Create members before and after the policy is registered, to test both scenarios - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); assertNoEventsContinually(); @@ -130,7 +130,7 @@ public class ConnectionFailureDetectorTest { @Test public void testNotifiedOfFailure() throws Exception { - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); stopServerSocket(); @@ -141,7 +141,7 @@ public class ConnectionFailureDetectorTest { @Test public void testNotifiedOfRecovery() throws Exception { - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); stopServerSocket(); @@ -157,7 +157,7 @@ public class ConnectionFailureDetectorTest { public void testReportsFailureWhenAlreadyDownOnRegisteringPolicy() throws Exception { stopServerSocket(); - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress)); assertHasEventEventually(HASensors.CONNECTION_FAILED, Predicates.<Object>equalTo(app), null); @@ -165,7 +165,7 @@ public class ConnectionFailureDetectorTest { @Test(groups="Integration") // Because slow public void testNotNotifiedOfTemporaryFailuresDuringStabilisationDelay() throws Exception { - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_FAILED_STABILIZATION_DELAY, Duration.ONE_MINUTE)); @@ -180,7 +180,7 @@ public class ConnectionFailureDetectorTest { public void testNotifiedOfFailureAfterStabilisationDelay() throws Exception { final int stabilisationDelay = 1000; - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_FAILED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); @@ -194,7 +194,7 @@ public class ConnectionFailureDetectorTest { public void testFailuresThenUpDownResetsStabilisationCount() throws Exception { final long stabilisationDelay = 1000; - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_FAILED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); @@ -213,7 +213,7 @@ public class ConnectionFailureDetectorTest { public void testNotNotifiedOfTemporaryRecoveryDuringStabilisationDelay() throws Exception { final long stabilisationDelay = 1000; - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); @@ -232,7 +232,7 @@ public class ConnectionFailureDetectorTest { public void testNotifiedOfRecoveryAfterStabilisationDelay() throws Exception { final int stabilisationDelay = 1000; - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); @@ -249,7 +249,7 @@ public class ConnectionFailureDetectorTest { public void testRecoversThenDownUpResetsStabilisationCount() throws Exception { final long stabilisationDelay = 1000; - app.addPolicy(PolicySpec.create(ConnectionFailureDetector.class) + app.policies().add(PolicySpec.create(ConnectionFailureDetector.class) .configure(ConnectionFailureDetector.ENDPOINT, serverSocketAddress) .configure(ConnectionFailureDetector.CONNECTION_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/ha/HaPolicyRebindTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/ha/HaPolicyRebindTest.java b/policy/src/test/java/org/apache/brooklyn/policy/ha/HaPolicyRebindTest.java index 242a33b..05f4ba4 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/ha/HaPolicyRebindTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/ha/HaPolicyRebindTest.java @@ -77,13 +77,13 @@ public class HaPolicyRebindTest extends RebindTestFixtureWithApp { @Test public void testServiceRestarterWorksAfterRebind() throws Exception { - origEntity.addPolicy(PolicySpec.create(ServiceRestarter.class) + origEntity.policies().add(PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); TestApplication newApp = rebind(); final TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); - newEntity.emit(HASensors.ENTITY_FAILED, new FailureDescriptor(origEntity, "simulate failure")); + newEntity.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(origEntity, "simulate failure")); Asserts.succeedsEventually(new Runnable() { @Override public void run() { @@ -99,7 +99,7 @@ public class HaPolicyRebindTest extends RebindTestFixtureWithApp { .configure(DynamicCluster.INITIAL_SIZE, 3)); origApp.start(ImmutableList.<Location>of(origLoc)); - origCluster.addPolicy(PolicySpec.create(ServiceReplacer.class) + origCluster.policies().add(PolicySpec.create(ServiceReplacer.class) .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); // rebind @@ -113,7 +113,7 @@ public class HaPolicyRebindTest extends RebindTestFixtureWithApp { newApp.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_FAILED, eventListener); newApp.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_RECOVERED, eventListener); - e1.emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); + e1.sensors().emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure")); // Expect e1 to be replaced Asserts.succeedsEventually(new Runnable() { @@ -132,7 +132,7 @@ public class HaPolicyRebindTest extends RebindTestFixtureWithApp { @Test public void testServiceFailureDetectorWorksAfterRebind() throws Exception { - origEntity.addEnricher(EnricherSpec.create(ServiceFailureDetector.class)); + origEntity.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); // rebind TestApplication newApp = rebind(); @@ -140,11 +140,11 @@ public class HaPolicyRebindTest extends RebindTestFixtureWithApp { newApp.getManagementContext().getSubscriptionManager().subscribe(newEntity, HASensors.ENTITY_FAILED, eventListener); - newEntity.setAttribute(TestEntity.SERVICE_UP, true); + newEntity.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(newEntity, Lifecycle.RUNNING); // trigger the failure - newEntity.setAttribute(TestEntity.SERVICE_UP, false); + newEntity.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(newEntity), null); assertEquals(events.size(), 1, "events="+events); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java ---------------------------------------------------------------------- diff --git a/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java b/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java index 1090b11..8c67489 100644 --- a/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java +++ b/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java @@ -73,7 +73,7 @@ public class ServiceFailureDetectorStabilizationTest { managementContext = new LocalManagementContextForTests(); app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); app.getManagementContext().getSubscriptionManager().subscribe( @@ -101,12 +101,12 @@ public class ServiceFailureDetectorStabilizationTest { @Test(groups="Integration") // Because slow public void testNotNotifiedOfTemporaryFailuresDuringStabilisationDelay() throws Exception { - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_STABILIZATION_DELAY, Duration.ONE_MINUTE)); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); Thread.sleep(100); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); assertNoEventsContinually(); } @@ -115,10 +115,10 @@ public class ServiceFailureDetectorStabilizationTest { public void testNotifiedOfFailureAfterStabilisationDelay() throws Exception { final int stabilisationDelay = 1000; - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); @@ -129,15 +129,15 @@ public class ServiceFailureDetectorStabilizationTest { LOG.debug("Running testFailuresThenUpDownResetsStabilisationCount"); final long stabilisationDelay = 1000; - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); Thread.sleep(OVERHEAD); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); @@ -147,16 +147,16 @@ public class ServiceFailureDetectorStabilizationTest { public void testNotNotifiedOfTemporaryRecoveryDuringStabilisationDelay() throws Exception { final long stabilisationDelay = 1000; - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); events.clear(); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); Thread.sleep(100); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(Duration.of(stabilisationDelay + OVERHEAD)); } @@ -165,14 +165,14 @@ public class ServiceFailureDetectorStabilizationTest { public void testNotifiedOfRecoveryAfterStabilisationDelay() throws Exception { final int stabilisationDelay = 1000; - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); events.clear(); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); assertHasEventEventually(HASensors.ENTITY_RECOVERED, Predicates.<Object>equalTo(e1), null); } @@ -181,19 +181,19 @@ public class ServiceFailureDetectorStabilizationTest { public void testRecoversThenDownUpResetsStabilisationCount() throws Exception { final long stabilisationDelay = 1000; - e1.addEnricher(EnricherSpec.create(ServiceFailureDetector.class) + e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_RECOVERED_STABILIZATION_DELAY, Duration.of(stabilisationDelay))); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); events.clear(); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); - e1.setAttribute(TestEntity.SERVICE_UP, false); + e1.sensors().set(TestEntity.SERVICE_UP, false); Thread.sleep(OVERHEAD); - e1.setAttribute(TestEntity.SERVICE_UP, true); + e1.sensors().set(TestEntity.SERVICE_UP, true); assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD)); assertHasEventEventually(HASensors.ENTITY_RECOVERED, Predicates.<Object>equalTo(e1), null);
