brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [07/11] git commit: Use Duration for AutoScalerPolicy.builder methods
Date Tue, 28 Oct 2014 15:37:18 GMT
Use Duration for AutoScalerPolicy.builder methods

- instead of taking long, take Duration parameter.
- for minPeriodBetweenExecs, resizeUpStabilizationDelay,
  resizeDownStabilizationDelay, and maxReachedNotificationDelay.
- Test tidy (for use of deprecated methods)


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/113fa0b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/113fa0b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/113fa0b3

Branch: refs/heads/master
Commit: 113fa0b33e00685f26764642789e3f0e64280ba1
Parents: ed8f972
Author: Aled Sage <aled.sage@gmail.com>
Authored: Mon Oct 27 09:46:06 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Oct 28 15:35:32 2014 +0000

----------------------------------------------------------------------
 .../policy/autoscaling/AutoScalerPolicy.java    | 36 ++++++++--
 .../autoscaling/AutoScalerPolicyMetricTest.java | 43 ++++++------
 .../autoscaling/AutoScalerPolicyRebindTest.java |  8 +--
 .../AutoScalerPolicyReconfigurationTest.java    | 29 ++++----
 .../autoscaling/AutoScalerPolicyTest.java       | 74 +++++++++-----------
 5 files changed, 106 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/113fa0b3/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java b/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
index f6247e9..a733fb6 100644
--- a/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
+++ b/policy/src/main/java/brooklyn/policy/autoscaling/AutoScalerPolicy.java
@@ -90,16 +90,16 @@ public class AutoScalerPolicy extends AbstractPolicy {
         private Number metricLowerBound;
         private int minPoolSize = 0;
         private int maxPoolSize = Integer.MAX_VALUE;
-        private long minPeriodBetweenExecs = 100;
-        private long resizeUpStabilizationDelay;
-        private long resizeDownStabilizationDelay;
+        private Duration minPeriodBetweenExecs;
+        private Duration resizeUpStabilizationDelay;
+        private Duration resizeDownStabilizationDelay;
         private ResizeOperator resizeOperator;
         private Function<Entity,Integer> currentSizeOperator;
         private BasicNotificationSensor<?> poolHotSensor;
         private BasicNotificationSensor<?> poolColdSensor;
         private BasicNotificationSensor<?> poolOkSensor;
         private BasicNotificationSensor<? super MaxPoolSizeReachedEvent> maxSizeReachedSensor;
-        private long maxReachedNotificationDelay;
+        private Duration maxReachedNotificationDelay;
         
         public Builder id(String val) {
             this.id = val; return this;
@@ -135,13 +135,34 @@ public class AutoScalerPolicy extends AbstractPolicy {
             maxPoolSize = max;
             return this;
         }
+        /**
+         * @deprecated since 0.7; use {@link #minPeriodBetweenExecs(Duration)}
+         */
+        @Deprecated
         public Builder minPeriodBetweenExecs(long val) {
+            return minPeriodBetweenExecs(Duration.of(val, TimeUnit.MILLISECONDS));
+        }
+        public Builder minPeriodBetweenExecs(Duration val) {
             this.minPeriodBetweenExecs = val; return this;
         }
+        /**
+         * @deprecated since 0.7; use {@link #resizeUpStabilizationDelay(Duration)}
+         */
+        @Deprecated
         public Builder resizeUpStabilizationDelay(long val) {
+            return resizeUpStabilizationDelay(Duration.of(val, TimeUnit.MILLISECONDS));
+        }
+        public Builder resizeUpStabilizationDelay(Duration val) {
             this.resizeUpStabilizationDelay = val; return this;
         }
+        /**
+         * @deprecated since 0.7; use {@link #resizeDownStabilizationDelay(Duration)}
+         */
+        @Deprecated
         public Builder resizeDownStabilizationDelay(long val) {
+            return resizeDownStabilizationDelay(Duration.of(val, TimeUnit.MILLISECONDS));
+        }
+        public Builder resizeDownStabilizationDelay(Duration val) {
             this.resizeDownStabilizationDelay = val; return this;
         }
         public Builder resizeOperator(ResizeOperator val) {
@@ -162,7 +183,14 @@ public class AutoScalerPolicy extends AbstractPolicy {
         public Builder maxSizeReachedSensor(BasicNotificationSensor<? super MaxPoolSizeReachedEvent>
val) {
             this.maxSizeReachedSensor = val; return this;
         }
+        /**
+         * @deprecated since 0.7; use {@link #maxReachedNotificationDelay(Duration)}
+         */
+        @Deprecated
         public Builder maxReachedNotificationDelay(long val) {
+            return maxReachedNotificationDelay(Duration.of(val, TimeUnit.MILLISECONDS));
+        }
+        public Builder maxReachedNotificationDelay(Duration val) {
             this.maxReachedNotificationDelay = val; return this;
         }
         public AutoScalerPolicy build() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/113fa0b3/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyMetricTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyMetricTest.java
b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyMetricTest.java
index 7cec2ed..7c5ee75 100644
--- a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyMetricTest.java
+++ b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyMetricTest.java
@@ -19,8 +19,6 @@
 package brooklyn.policy.autoscaling;
 
 import static brooklyn.policy.autoscaling.AutoScalerPolicyTest.currentSizeAsserter;
-import static brooklyn.test.TestUtils.assertSucceedsContinually;
-import static brooklyn.test.TestUtils.executeUntilSucceeds;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
@@ -38,6 +36,7 @@ import brooklyn.event.SensorEvent;
 import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.BasicNotificationSensor;
 import brooklyn.event.basic.Sensors;
+import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestCluster;
 import brooklyn.test.entity.TestEntity;
@@ -74,10 +73,10 @@ public class AutoScalerPolicyMetricTest {
         tc.addPolicy(policy);
 
         tc.setAttribute(MY_ATTRIBUTE, 100);
-        assertSucceedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
 
         tc.setAttribute(MY_ATTRIBUTE, 101);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
     }
     
     @Test
@@ -88,10 +87,10 @@ public class AutoScalerPolicyMetricTest {
         tc.addPolicy(policy);
 
         tc.setAttribute(MY_ATTRIBUTE, 50);
-        assertSucceedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
2));
 
         tc.setAttribute(MY_ATTRIBUTE, 49);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
     }
     
     @Test
@@ -103,11 +102,11 @@ public class AutoScalerPolicyMetricTest {
         
         // workload 200 so requires doubling size to 10 to handle: (200*5)/100 = 10
         tc.setAttribute(MY_ATTRIBUTE, 200);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
10));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
10));
         
         // workload 5, requires 1 entity: (10*110)/100 = 11
         tc.setAttribute(MY_ATTRIBUTE, 110);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
11));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
11));
     }
     
     @Test
@@ -119,14 +118,14 @@ public class AutoScalerPolicyMetricTest {
         
         // workload can be handled by 4 servers, within its valid range: (49*5)/50 = 4.9
         tc.setAttribute(MY_ATTRIBUTE, 49);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
4));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
4));
         
         // workload can be handled by 4 servers, within its valid range: (25*4)/50 = 2
         tc.setAttribute(MY_ATTRIBUTE, 25);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
         
         tc.setAttribute(MY_ATTRIBUTE, 0);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
0));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
0));
     }
     
     @Test
@@ -141,14 +140,14 @@ public class AutoScalerPolicyMetricTest {
 
         // Decreases to min-size only
         tc.setAttribute(MY_ATTRIBUTE, 0);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
         
         // Increases to max-size only
         tc.setAttribute(MY_ATTRIBUTE, 100000);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
     }
     
-    @Test
+    @Test(invocationCount=100)
     public void testWarnsWhenMaxCapReached() {
         final List<MaxPoolSizeReachedEvent> maxReachedEvents = Lists.newCopyOnWriteArrayList();
         tc.resize(1);
@@ -169,14 +168,14 @@ public class AutoScalerPolicyMetricTest {
 
         // workload can be handled by 6 servers, so no need to notify: 6 <= (100*6)/50
         tc.setAttribute(MY_ATTRIBUTE, 600);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
         assertTrue(maxReachedEvents.isEmpty());
         
         // Increases to above max capacity: would require (100000*6)/100 = 6000
         tc.setAttribute(MY_ATTRIBUTE, 100000);
         
         // Assert our listener gets notified (once)
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable()
{
             public void run() {
                 assertEquals(maxReachedEvents.size(), 1);
                 assertEquals(maxReachedEvents.get(0).getMaxAllowed(), 6);
@@ -185,7 +184,7 @@ public class AutoScalerPolicyMetricTest {
                 assertEquals(maxReachedEvents.get(0).getMaxUnbounded(), 6000);
                 assertEquals(maxReachedEvents.get(0).getTimeWindow(), 0);
             }});
-        assertSucceedsContinually(new Runnable() {
+        Asserts.succeedsContinually(new Runnable() {
                 @Override public void run() {
                     assertEquals(maxReachedEvents.size(), 1);
                 }});
@@ -204,7 +203,7 @@ public class AutoScalerPolicyMetricTest {
         assertFalse(policy.isRunning());
         
         tc.setAttribute(MY_ATTRIBUTE, 100000);
-        assertSucceedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
         
         // TODO Could assert all subscriptions have been de-registered as well, 
         // but that requires exposing more things just for testing...
@@ -234,7 +233,7 @@ public class AutoScalerPolicyMetricTest {
         policy.suspend();
         
         tc.setAttribute(MY_ATTRIBUTE, 100000);
-        assertSucceedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
     }
     
     @Test
@@ -247,7 +246,7 @@ public class AutoScalerPolicyMetricTest {
         policy.suspend();
         policy.resume();
         tc.setAttribute(MY_ATTRIBUTE, 101);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
     }
     
     @Test
@@ -266,10 +265,10 @@ public class AutoScalerPolicyMetricTest {
 
         // First confirm that tc is not being listened to for this entity
         tc.setAttribute(TestEntity.SEQUENCE, 101);
-        assertSucceedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), currentSizeAsserter(tc,
1));
 
         // Then confirm we listen to the correct "entityWithMetric"
         entityWithMetric.setAttribute(TestEntity.SEQUENCE, 101);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/113fa0b3/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
index 61e2974..7191030 100644
--- a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
+++ b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
@@ -77,14 +77,14 @@ public class AutoScalerPolicyRebindTest extends RebindTestFixtureWithApp
{
                 .metricLowerBound(2)
                 .minPoolSize(0)
                 .maxPoolSize(3)
-                .minPeriodBetweenExecs(4)
-                .resizeUpStabilizationDelay(5)
-                .resizeDownStabilizationDelay(6)
+                .minPeriodBetweenExecs(Duration.of(4, TimeUnit.MILLISECONDS))
+                .resizeUpStabilizationDelay(Duration.of(5, TimeUnit.MILLISECONDS))
+                .resizeDownStabilizationDelay(Duration.of(6, TimeUnit.MILLISECONDS))
                 .poolHotSensor(POOL_HOT_SENSOR)
                 .poolColdSensor(POOL_COLD_SENSOR)
                 .poolOkSensor(POOL_OK_SENSOR)
                 .maxSizeReachedSensor(MAX_SIZE_REACHED_SENSOR)
-                .maxReachedNotificationDelay(7)
+                .maxReachedNotificationDelay(Duration.of(7, TimeUnit.MILLISECONDS))
                 .buildSpec());
         
         TestApplication newApp = rebind();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/113fa0b3/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java
b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java
index d4bc23d..6591977 100644
--- a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java
+++ b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyReconfigurationTest.java
@@ -19,17 +19,16 @@
 package brooklyn.policy.autoscaling;
 
 import static brooklyn.policy.autoscaling.AutoScalerPolicyTest.currentSizeAsserter;
-import static brooklyn.test.TestUtils.executeUntilSucceeds;
 
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.event.AttributeSensor;
 import brooklyn.event.basic.Sensors;
+import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestCluster;
 import brooklyn.util.time.Duration;
@@ -46,7 +45,7 @@ public class AutoScalerPolicyReconfigurationTest {
     
     @BeforeMethod(alwaysRun=true)
     public void before() throws Exception {
-        app = ApplicationBuilder.newManagedApp(TestApplication.class);
+        app = TestApplication.Factory.newManagedInstanceForTests();
         tc = app.createAndManageChild(EntitySpec.create(TestCluster.class)
                 .configure("initialSize", 1));
     }
@@ -68,7 +67,7 @@ public class AutoScalerPolicyReconfigurationTest {
 
         policy.setConfig(AutoScalerPolicy.MIN_POOL_SIZE, 3);
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
3));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
3));
     }
     
     @Test
@@ -83,12 +82,12 @@ public class AutoScalerPolicyReconfigurationTest {
         
         // 25*4 = 100 -> 2 nodes at 50 each
         tc.setAttribute(MY_ATTRIBUTE, 25);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
 
         // Decreases to new min-size
         policy.setConfig(AutoScalerPolicy.MIN_POOL_SIZE, 1);
         tc.setAttribute(MY_ATTRIBUTE, 0);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
     }
     
     @Test
@@ -103,7 +102,7 @@ public class AutoScalerPolicyReconfigurationTest {
 
         policy.setConfig(AutoScalerPolicy.MAX_POOL_SIZE, 4);
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
4));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
4));
     }
     
     @Test
@@ -118,13 +117,13 @@ public class AutoScalerPolicyReconfigurationTest {
 
         // 200*3 = 600 -> 6 nodes at 100 each
         tc.setAttribute(MY_ATTRIBUTE, 200);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
6));
         
         policy.setConfig(AutoScalerPolicy.MAX_POOL_SIZE, 8);
         
         // Increases to max-size only
         tc.setAttribute(MY_ATTRIBUTE, 100000);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
8));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
8));
     }
     
     @Test
@@ -139,7 +138,7 @@ public class AutoScalerPolicyReconfigurationTest {
         policy.setConfig(AutoScalerPolicy.METRIC_LOWER_BOUND, 51);
 
         tc.setAttribute(MY_ATTRIBUTE, 50);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
     }
 
     @Test
@@ -154,7 +153,7 @@ public class AutoScalerPolicyReconfigurationTest {
         policy.setConfig(AutoScalerPolicy.METRIC_UPPER_BOUND, 99);
 
         tc.setAttribute(MY_ATTRIBUTE, 100);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
     }
 
     @Test
@@ -163,14 +162,14 @@ public class AutoScalerPolicyReconfigurationTest {
         
         AutoScalerPolicy policy = new AutoScalerPolicy.Builder().metric(MY_ATTRIBUTE)
                 .metricLowerBound(50).metricUpperBound(100)
-                .resizeUpStabilizationDelay(100000)
+                .resizeUpStabilizationDelay(Duration.TWO_MINUTES)
                 .build();
         tc.addPolicy(policy);
 
         policy.setConfig(AutoScalerPolicy.RESIZE_UP_STABILIZATION_DELAY, Duration.ZERO);
 
         tc.setAttribute(MY_ATTRIBUTE, 101);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
2));
     }
     
     @Test
@@ -179,13 +178,13 @@ public class AutoScalerPolicyReconfigurationTest {
         
         AutoScalerPolicy policy = new AutoScalerPolicy.Builder().metric(MY_ATTRIBUTE)
                 .metricLowerBound(50).metricUpperBound(100)
-                .resizeDownStabilizationDelay(100000)
+                .resizeDownStabilizationDelay(Duration.TWO_MINUTES)
                 .build();
         tc.addPolicy(policy);
 
         policy.setConfig(AutoScalerPolicy.RESIZE_DOWN_STABILIZATION_DELAY, Duration.ZERO);
 
         tc.setAttribute(MY_ATTRIBUTE, 1);
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(tc,
1));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/113fa0b3/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
index eeab7cd..14f2f6f 100644
--- a/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
+++ b/policy/src/test/java/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
@@ -18,8 +18,6 @@
  */
 package brooklyn.policy.autoscaling;
 
-import static brooklyn.test.TestUtils.assertSucceedsContinually;
-import static brooklyn.test.TestUtils.executeUntilSucceeds;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
@@ -39,15 +37,15 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Resizable;
 import brooklyn.event.basic.BasicNotificationSensor;
+import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestCluster;
 import brooklyn.util.collections.MutableMap;
-import brooklyn.util.internal.TimeExtras;
+import brooklyn.util.time.Duration;
 
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
@@ -55,8 +53,6 @@ import com.google.common.collect.ImmutableMap;
 
 public class AutoScalerPolicyTest {
 
-    static { TimeExtras.init(); }
-
     private static long TIMEOUT_MS = 10*1000;
     private static long SHORT_WAIT_MS = 250;
     private static long OVERHEAD_DURATION_MS = 500;
@@ -92,7 +88,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L,
4*20L));
         
         // expect pool to shrink to 3 (i.e. maximum to have >= 40 per container)
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
3));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
3));
     }
     
     @Test
@@ -100,7 +96,7 @@ public class AutoScalerPolicyTest {
         resizable.resize(4);
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L));
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
     }
 
     @Test
@@ -109,7 +105,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 41L, 2*10L, 2*20L));
         
         // expect pool to grow to 3 (i.e. minimum to have <= 80 per container)
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
3));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
3));
     }
 
     @Test
@@ -134,7 +130,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 0L, 4*10L, 4*20L));
         
         // expect pool to shrink only to the minimum
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
2));
     }
     
     @Test
@@ -149,7 +145,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 1000000L, 4*10L,
4*20L));
         
         // expect pool to grow only to the maximum
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
     }
     
     @Test
@@ -182,7 +178,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L));
         // now expect pool to shrink to 1
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
     }
     
     @Test(groups="Integration")
@@ -195,7 +191,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L));
         // now expect pool to grow to 5
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
     }
     
     @Test(groups="Integration")
@@ -208,7 +204,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(2, 1L, 2*10L, 2*20L));
         // now expect pool to shrink to 1
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
     }
     
     @Test(groups="Integration")
@@ -221,7 +217,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(4, 81L, 4*10L, 4*20L));
         // now expect pool to grow to 5
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
5));
     }
     
     // FIXME failed in jenkins (e.g. #1035); with "lists don't have the same size expected:<3>
but was:<2>"
@@ -235,7 +231,7 @@ public class AutoScalerPolicyTest {
         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
         
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
         assertEquals(resizable.sizes, ImmutableList.of(4, 3, 1));
     }
     
@@ -256,7 +252,7 @@ public class AutoScalerPolicyTest {
         
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(1, 21L, 1*10L, 1*20L));
// grow to 2
         
-        executeUntilSucceeds(MutableMap.of("timeout",TIMEOUT_MS), new Runnable() {
+        Asserts.succeedsEventually(MutableMap.of("timeout",TIMEOUT_MS), new Runnable() {
                 public void run() {
                     assertTrue(counter.get() >= 1, "cccounter="+counter);
                 }});
@@ -277,20 +273,20 @@ public class AutoScalerPolicyTest {
         resizable.addPolicy(policy);
         
         resizable.emit(customPoolHotSensor, message(1, 21L, 1*10L, 1*20L)); // grow to 2
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
2));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
2));
         
         resizable.emit(customPoolColdSensor, message(2, 1L, 1*10L, 1*20L)); // shrink to
1
-        executeUntilSucceeds(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
+        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable,
1));
     }
     
     @Test(groups="Integration")
     public void testResizeUpStabilizationDelayIgnoresBlip() throws Exception {
         long resizeUpStabilizationDelay = 1000L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         resizable.removePolicy(policy);
         
         policy = AutoScalerPolicy.builder()
-                .resizeUpStabilizationDelay(resizeUpStabilizationDelay) 
+                .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS))

                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .build();
         resizable.addPolicy(policy);
@@ -302,7 +298,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(1, 11L, 4*10L, 4*20L));
// but 1 is still adequate
         
         assertEquals(resizable.getCurrentSize(), (Integer)1);
-        assertSucceedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
+        Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
                 @Override public void run() {
                     assertEquals(resizable.sizes, ImmutableList.of(1));
                 }});
@@ -329,11 +325,11 @@ public class AutoScalerPolicyTest {
     @Test(groups="Integration")
     public void testResizeUpStabilizationDelayTakesMaxSustainedDesired() throws Exception
{
         long resizeUpStabilizationDelay = 1100L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         resizable.removePolicy(policy);
         
         policy = AutoScalerPolicy.builder()
-                .resizeUpStabilizationDelay(resizeUpStabilizationDelay) 
+                .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS))

                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .build();
         resizable.addPolicy(policy);
@@ -354,7 +350,7 @@ public class AutoScalerPolicyTest {
         // 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?)
         //      Therefore do strong assertion of currentSize==2 later, so can write out times
if it goes wrong.
-        executeUntilSucceeds(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), new Runnable()
{
+        Asserts.succeedsEventually(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), new
Runnable() {
             public void run() {
                 assertTrue(resizable.getCurrentSize() >= 2, "currentSize="+resizable.getCurrentSize());
             }});
@@ -367,7 +363,7 @@ public class AutoScalerPolicyTest {
                 "Resizing to 2: time="+timeToResizeTo2+"; resizeUpStabilizationDelay="+resizeUpStabilizationDelay);
 
         // Will then grow to 4 $resizeUpStabilizationDelay milliseconds after that emission
-        executeUntilSucceeds(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), 
+        Asserts.succeedsEventually(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), 
                 currentSizeAsserter(resizable, 4));
         long timeToResizeTo4 = stopwatch.elapsed(TimeUnit.MILLISECONDS) - postSleepTime;
         
@@ -379,11 +375,11 @@ public class AutoScalerPolicyTest {
     @Test(groups="Integration")
     public void testResizeUpStabilizationDelayResizesAfterDelay() {
         final long resizeUpStabilizationDelay = 1000L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         resizable.removePolicy(policy);
         
         policy = resizable.addPolicy(AutoScalerPolicy.builder()
-                .resizeUpStabilizationDelay(resizeUpStabilizationDelay) 
+                .resizeUpStabilizationDelay(Duration.of(resizeUpStabilizationDelay, TimeUnit.MILLISECONDS))

                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .buildSpec());
         resizable.resize(1);
@@ -394,7 +390,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, need4); // would grow to
4
         final AtomicInteger emitCount = new AtomicInteger(0);
         
-        executeUntilSucceeds(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
+        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 
@@ -411,11 +407,11 @@ public class AutoScalerPolicyTest {
     @Test(groups="Integration")
     public void testResizeDownStabilizationDelayIgnoresBlip() throws Exception {
         long resizeStabilizationDelay = 1000L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         resizable.removePolicy(policy);
         
         policy = AutoScalerPolicy.builder()
-                .resizeDownStabilizationDelay(resizeStabilizationDelay) 
+                .resizeDownStabilizationDelay(Duration.of(resizeStabilizationDelay, TimeUnit.MILLISECONDS))

                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .build();
         resizable.addPolicy(policy);
@@ -427,7 +423,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_OK_SENSOR, message(2, 20L, 1*10L, 1*20L));
// but 2 is still adequate
         
         assertEquals(resizable.getCurrentSize(), (Integer)2);
-        assertSucceedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
+        Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
                 public void run() {
                     assertEquals(resizable.sizes, ImmutableList.of(2));
                 }});
@@ -448,12 +444,12 @@ public class AutoScalerPolicyTest {
     @Test(groups="Integration")
     public void testResizeDownStabilizationDelayTakesMinSustainedDesired() throws Exception
{
         long resizeDownStabilizationDelay = 1100L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         policy.suspend();
         resizable.removePolicy(policy);
         
         policy = AutoScalerPolicy.builder()
-                .resizeDownStabilizationDelay(resizeDownStabilizationDelay)
+                .resizeDownStabilizationDelay(Duration.of(resizeDownStabilizationDelay, TimeUnit.MILLISECONDS))
                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .build();
         resizable.addPolicy(policy);
@@ -474,7 +470,7 @@ public class AutoScalerPolicyTest {
         // 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?)
         //      Therefore do strong assertion of currentSize==2 later, so can write out times
if it goes wrong.
-        executeUntilSucceeds(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), new Runnable()
{
+        Asserts.succeedsEventually(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), new
Runnable() {
                 public void run() {
                     assertTrue(resizable.getCurrentSize() <= 2, "currentSize="+resizable.getCurrentSize());
                 }});
@@ -487,7 +483,7 @@ public class AutoScalerPolicyTest {
                 "Resizing to 2: time="+timeToResizeTo2+"; resizeDownStabilizationDelay="+resizeDownStabilizationDelay);
 
         // Will then shrink to 1 $resizeUpStabilizationDelay milliseconds after that emission
-        executeUntilSucceeds(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), 
+        Asserts.succeedsEventually(MutableMap.of("period", 1, "timeout", TIMEOUT_MS), 
                 currentSizeAsserter(resizable, 1));
         long timeToResizeTo1 = stopwatch.elapsed(TimeUnit.MILLISECONDS) - postSleepTime;
         
@@ -499,11 +495,11 @@ public class AutoScalerPolicyTest {
     @Test(groups="Integration")
     public void testResizeDownStabilizationDelayResizesAfterDelay() throws Exception {
         final long resizeDownStabilizationDelay = 1000L;
-        long minPeriodBetweenExecs = 0;
+        Duration minPeriodBetweenExecs = Duration.ZERO;
         resizable.removePolicy(policy);
         
         policy = AutoScalerPolicy.builder()
-                .resizeDownStabilizationDelay(resizeDownStabilizationDelay)
+                .resizeDownStabilizationDelay(Duration.of(resizeDownStabilizationDelay, TimeUnit.MILLISECONDS))
                 .minPeriodBetweenExecs(minPeriodBetweenExecs)
                 .build();
         resizable.addPolicy(policy);
@@ -515,7 +511,7 @@ public class AutoScalerPolicyTest {
         resizable.emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, needJust1); // would shrink
to 1
         final AtomicInteger emitCount = new AtomicInteger(0);
         
-        executeUntilSucceeds(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
+        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


Mime
View raw message