brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [4/8] brooklyn-server git commit: Simplify and tidy up tests for both entities
Date Tue, 11 Apr 2017 14:13:11 GMT
Simplify and tidy up tests for both entities


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/68a6f146
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/68a6f146
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/68a6f146

Branch: refs/heads/master
Commit: 68a6f1465b01e6cb49163149af173d4680ac7a7f
Parents: 77d0ddb
Author: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Tue Feb 7 14:26:22 2017 +0000
Committer: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Tue Apr 11 14:34:26 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/group/SequenceGroup.java    |  7 +-
 .../entity/group/SequenceGroupImpl.java         | 14 ++-
 .../brooklyn/entity/stock/SequenceEntity.java   | 27 ++----
 .../entity/stock/SequenceEntityImpl.java        | 28 +-----
 .../entity/group/SequenceGroupTest.java         | 96 +++++++++++++-------
 .../entity/stock/SequenceEntityTest.java        | 55 ++++-------
 6 files changed, 98 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroup.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroup.java b/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroup.java
index 851d3b7..4d7d082 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroup.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroup.java
@@ -55,7 +55,7 @@ import com.google.common.reflect.TypeToken;
  *                 - $brooklyn:attributeWhenReady("application.id")
  *           - $brooklyn:object:
  *               type: org.apache.brooklyn.core.entity.EntityPredicates
- *               factoryMethod.name: "configEquelTo"
+ *               factoryMethod.name: "configEqualTo"
  *               factoryMethod.args:
  *                 - "sequence.set"
  *                 - true
@@ -65,11 +65,6 @@ import com.google.common.reflect.TypeToken;
  *     sequenceValueSensor: $brooklyn:sensor("entity.sequence")
  *     sequenceStringSensor: $brooklyn:sensor("entity.name")
  * }</pre>
- * <p>
- * <b>IMPORTANT</b> Relationship management will fail in unpredictable ways
- * if an entity is a member of multiple sequences that use the same
- * {@link #SEQUENCE_VALUE_SENSOR sensor}, however this usage will probably
- * not have the desired effect in any case.
  */
 @ImplementedBy(SequenceGroupImpl.class)
 public interface SequenceGroup extends DynamicGroup {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroupImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroupImpl.java
index fc9c526..0e8c39c 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroupImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/SequenceGroupImpl.java
@@ -33,6 +33,11 @@ public class SequenceGroupImpl extends DynamicGroupImpl implements SequenceGroup
 
     public SequenceGroupImpl() { }
 
+    public void init() {
+        super.init();
+        reset();
+    }
+
     @Override
     public Void reset() {
         synchronized (memberChangeMutex) {
@@ -45,14 +50,6 @@ public class SequenceGroupImpl extends DynamicGroupImpl implements SequenceGroup
     }
 
     @Override
-    public void rescanEntities() {
-        synchronized (memberChangeMutex) {
-            reset();
-            super.rescanEntities();
-        }
-    }
-
-    @Override
     public boolean addMember(Entity member) {
         synchronized (memberChangeMutex) {
             boolean changed = super.addMember(member);
@@ -96,6 +93,7 @@ public class SequenceGroupImpl extends DynamicGroupImpl implements SequenceGroup
 
         entity.sensors().set(valueSensor, current);
         entity.sensors().set(stringSensor, string);
+        LOG.debug("Sequence on {} set to to {}", entity, current);
 
         sensors().set(SEQUENCE_CURRENT, entity);
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java b/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java
index f53ba65..6b73d8f 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java
@@ -28,6 +28,8 @@ import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.entity.group.SequenceGroup;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 
+import com.google.common.base.Supplier;
+
 /**
  * An entity that supplies a sequence of values through an effector.
  * <p>
@@ -38,31 +40,23 @@ import org.apache.brooklyn.util.core.flags.SetFromFlag;
  *   brooklyn.config:
  *     sequence.start: 0
  *     sequence.increment: 1
- *     sequence.format: "global-%03d"
  * }</pre>
  */
 @ImplementedBy(SequenceEntityImpl.class)
-public interface SequenceEntity extends Entity, Startable {
+public interface SequenceEntity extends Entity, Startable, Supplier<Integer> {
 
     AttributeSensor<Integer> SEQUENCE_VALUE = SequenceGroup.SEQUENCE_VALUE;
 
-    AttributeSensor<String> SEQUENCE_STRING = SequenceGroup.SEQUENCE_STRING;
-
     @SetFromFlag("sequenceStart")
     ConfigKey<Integer> SEQUENCE_START = SequenceGroup.SEQUENCE_START;
 
     @SetFromFlag("sequenceIncrement")
     ConfigKey<Integer> SEQUENCE_INCREMENT = SequenceGroup.SEQUENCE_INCREMENT;
 
-    @SetFromFlag("sequenceFormat")
-    ConfigKey<String> SEQUENCE_FORMAT = SequenceGroup.SEQUENCE_FORMAT;
-
     MethodEffector<Void> RESET = new MethodEffector<Void>(SequenceEntity.class,
"reset");
     MethodEffector<Void> INCREMENT = new MethodEffector<Void>(SequenceEntity.class,
"increment");
-    MethodEffector<Integer> CURRENT_VALUE = new MethodEffector<Integer>(SequenceEntity.class,
"currentValue");
-    MethodEffector<String> CURRENT_STRING = new MethodEffector<String>(SequenceEntity.class,
"currentString");
-    MethodEffector<Integer> NEXT_VALUE = new MethodEffector<Integer>(SequenceEntity.class,
"nextValue");
-    MethodEffector<String> NEXT_STRING = new MethodEffector<String>(SequenceEntity.class,
"nextString");
+    MethodEffector<Integer> GET = new MethodEffector<Integer>(SequenceEntity.class,
"get");
+    MethodEffector<Integer> INCREMENT_AND_GET = new MethodEffector<Integer>(SequenceEntity.class,
"incrementAndGet");
 
     @Effector(description = "Reset the sequence to initial value")
     Void reset();
@@ -71,14 +65,9 @@ public interface SequenceEntity extends Entity, Startable {
     Void increment();
 
     @Effector(description = "Return the current numeric value of the sequence")
-    Integer currentValue();
-
-    @Effector(description = "Return the current string representation of the sequence")
-    String currentString();
+    Integer get();
 
-    @Effector(description = "Update and return the next numeric value of the sequence")
-    Integer nextValue();
+    @Effector(description = "Update and return the next value of the sequence")
+    Integer incrementAndGet();
 
-    @Effector(description = "Update and return the next string representation of the sequence")
-    String nextString();
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntityImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntityImpl.java
index 0ddb134..b731dfe 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntityImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntityImpl.java
@@ -52,32 +52,17 @@ public class SequenceEntityImpl extends AbstractEntity implements SequenceEntity
     }
 
     @Override
-    public Integer currentValue() {
+    public Integer get() {
         synchronized (mutex) {
             return sensors().get(SEQUENCE_VALUE);
         }
     }
 
     @Override
-    public String currentString() {
-        synchronized (mutex) {
-            return sensors().get(SEQUENCE_STRING);
-        }
-    }
-
-    @Override
-    public Integer nextValue() {
+    public Integer incrementAndGet() {
         synchronized (mutex) {
             increment();
-            return currentValue();
-        }
-    }
-
-    @Override
-    public String nextString() {
-        synchronized (mutex) {
-            increment();
-            return currentString();
+            return get();
         }
     }
 
@@ -85,7 +70,7 @@ public class SequenceEntityImpl extends AbstractEntity implements SequenceEntity
     public Void increment() {
         synchronized (mutex) {
             Integer increment = config().get(SEQUENCE_INCREMENT);
-            Integer current = currentValue();
+            Integer current = get();
             sequence(current + increment);
             return null;
         }
@@ -101,12 +86,7 @@ public class SequenceEntityImpl extends AbstractEntity implements SequenceEntity
     }
 
     private void sequence(Integer value) {
-        String format = config().get(SEQUENCE_FORMAT);
-        String string = String.format(format, value);
-
         sensors().set(SEQUENCE_VALUE, value);
-        sensors().set(SEQUENCE_STRING, string);
-
         LOG.debug("Sequence for {} set to {}", this, value);
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java
index 148eb5b..d835c7d 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java
@@ -18,22 +18,22 @@
  */
 package org.apache.brooklyn.entity.group;
 
+import static org.apache.brooklyn.core.entity.EntityAsserts.assertAttribute;
+import static org.apache.brooklyn.core.entity.EntityAsserts.assertAttributeEquals;
+import static org.apache.brooklyn.core.entity.EntityAsserts.assertAttributeEqualsEventually;
 import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
-import static org.apache.brooklyn.test.Asserts.*;
-import static org.apache.brooklyn.core.entity.EntityAsserts.*;
-
-import java.util.Set;
+import static org.apache.brooklyn.test.Asserts.assertTrue;
+import static org.apache.brooklyn.test.Asserts.succeedsEventually;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityPredicates;
+import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
-import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -43,7 +43,7 @@ import com.google.common.collect.ImmutableSet;
 
 public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
 
-    private TestApplication app;
+    private SimulatedLocation loc1;
     private SequenceGroup group;
     private TestEntity e1, e2, e3;
 
@@ -51,33 +51,35 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
     @Override
     public void setUp() throws Exception {
         super.setUp();
-
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
-                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, Sensors.newStringSensor("test.sequence"))
-                .configure(SequenceGroup.SEQUENCE_FORMAT, "test-%02d"));
-        e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+        loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
     }
 
-    @AfterMethod(alwaysRun=true)
-    @Override
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-
-        super.tearDown();
+    protected void createTestEntities() throws Exception {
+        e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-one"));
+        e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-two"));
+        e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-three"));
     }
 
-
     @Test
     public void testGroupDefaults() throws Exception {
+        group = app.addChild(EntitySpec.create(SequenceGroup.class));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
+
+        assertAttribute(group, SequenceGroup.SEQUENCE_VALUE, Predicates.isNull());
         assertTrue(group.getMembers().isEmpty());
     }
 
     @Test
     public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception
{
-        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
+                .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("test-one")));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
 
         assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
         assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1);
@@ -86,9 +88,17 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
 
     @Test
     public void testGroupConfiguration() throws Exception {
-        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
+                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR,  Sensors.newStringSensor("test.sequence"))
+                .configure(SequenceGroup.SEQUENCE_FORMAT, "test-%02d")
+                .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("test-one")));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
 
         assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
+        assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1);
         assertAttributeEquals(e1, SequenceGroup.SEQUENCE_STRING, null);
         assertAttributeEquals(e1, Sensors.newStringSensor("test.sequence"), "test-01");
     }
@@ -97,13 +107,17 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
     public void testAlternateGroupConfiguration() throws Exception {
         AttributeSensor<Integer> value = Sensors.newIntegerSensor("test.value");
         AttributeSensor<String> string = Sensors.newStringSensor("test.string");
-        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
                 .configure(SequenceGroup.SEQUENCE_START, 12345)
                 .configure(SequenceGroup.SEQUENCE_INCREMENT, 678)
                 .configure(SequenceGroup.SEQUENCE_VALUE_SENSOR, value)
                 .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, string)
-                .configure(SequenceGroup.SEQUENCE_FORMAT, "0x%04X"));
-        group.setEntityFilter(EntityPredicates.hasInterfaceMatching(".*TestEntity"));
+                .configure(SequenceGroup.SEQUENCE_FORMAT, "0x%04X")
+                .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.hasInterfaceMatching(".*TestEntity")));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
 
         assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3));
         assertAttributeEquals(e1, value, 12345);
@@ -116,7 +130,12 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
 
     @Test
     public void testGroupWithMatchingFilterReturnsEverythingThatMatches() throws Exception
{
-        group.setEntityFilter(Predicates.alwaysTrue());
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
+                .configure(SequenceGroup.ENTITY_FILTER, Predicates.alwaysTrue()));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
 
         assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3, app, group));
         assertAttributeEquals(app, SequenceGroup.SEQUENCE_VALUE, 1);
@@ -130,8 +149,14 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
 
     @Test
     public void testGroupDetectsNewlyManagedMatchingMember() throws Exception {
-        group.setEntityFilter(EntityPredicates.displayNameEqualTo("myname"));
-        final Entity e = app.addChild(EntitySpec.create(TestEntity.class).displayName("myname"));
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
+                .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("test-four")));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
+
+        final Entity e = app.addChild(EntitySpec.create(TestEntity.class).displayName("test-four"));
 
         succeedsEventually(new Runnable() {
             public void run() {
@@ -142,8 +167,13 @@ public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
     }
 
     @Test
-    public void testGroupUsesNewFilter() throws Exception {
-        group.setEntityFilter(EntityPredicates.hasInterfaceMatching(".*TestEntity"));
+    public void testGroupAddsNewMatchingMember() throws Exception {
+        group = app.addChild(EntitySpec.create(SequenceGroup.class)
+                .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.hasInterfaceMatching(".*TestEntity")));
+        createTestEntities();
+        app.start(ImmutableList.of(loc1));
+
+        assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true);
 
         assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3));
         assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/68a6f146/core/src/test/java/org/apache/brooklyn/entity/stock/SequenceEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/stock/SequenceEntityTest.java b/core/src/test/java/org/apache/brooklyn/entity/stock/SequenceEntityTest.java
index 2ec8a79..c4b3b86 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/stock/SequenceEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/stock/SequenceEntityTest.java
@@ -55,20 +55,17 @@ public class SequenceEntityTest extends BrooklynAppUnitTestSupport {
         assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 0);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "0");
     }
 
     @Test
     public void testSequenceInitialConfig() throws Exception {
         sequence = app.addChild(EntitySpec.create(SequenceEntity.class)
-                .configure(SequenceEntity.SEQUENCE_START, 42)
-                .configure(SequenceEntity.SEQUENCE_FORMAT, "id-%02x"));
+                .configure(SequenceEntity.SEQUENCE_START, 42));
         app.start(ImmutableList.of(loc1));
 
         assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 42);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "id-2a");
     }
 
     @Test
@@ -78,54 +75,41 @@ public class SequenceEntityTest extends BrooklynAppUnitTestSupport {
 
         EntityAsserts.assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(1));
-        assertEquals(sequence.currentString(), "1");
+        assertEquals(sequence.get(), Integer.valueOf(1));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 1);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "1");
 
         sequence.increment();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(2));
-        assertEquals(sequence.currentString(), "2");
+        assertEquals(sequence.get(), Integer.valueOf(2));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 2);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "2");
 
         sequence.invoke(SequenceEntity.INCREMENT, ImmutableMap.<String, Object>of()).getUnchecked();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(3));
-        assertEquals(sequence.currentString(), "3");
+        assertEquals(sequence.get(), Integer.valueOf(3));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 3);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "3");
     }
 
     @Test
     public void testSequenceIncrementEffectorConfig() throws Exception {
         sequence = app.addChild(EntitySpec.create(SequenceEntity.class)
                 .configure(SequenceEntity.SEQUENCE_START, 0)
-                .configure(SequenceEntity.SEQUENCE_INCREMENT, 2)
-                .configure(SequenceEntity.SEQUENCE_FORMAT, "%03d"));
+                .configure(SequenceEntity.SEQUENCE_INCREMENT, 2));
         app.start(ImmutableList.of(loc1));
 
         EntityAsserts.assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(0));
-        assertEquals(sequence.currentString(), "000");
+        assertEquals(sequence.get(), Integer.valueOf(0));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 0);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "000");
 
         sequence.increment();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(2));
-        assertEquals(sequence.currentString(), "002");
+        assertEquals(sequence.get(), Integer.valueOf(2));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 2);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "002");
 
         sequence.invoke(SequenceEntity.INCREMENT, ImmutableMap.<String, Object>of()).getUnchecked();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(4));
-        assertEquals(sequence.currentString(), "004");
+        assertEquals(sequence.get(), Integer.valueOf(4));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 4);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "004");
     }
 
     @Test
@@ -135,19 +119,16 @@ public class SequenceEntityTest extends BrooklynAppUnitTestSupport {
 
         assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(1));
-        assertEquals(sequence.currentString(), "1");
+        assertEquals(sequence.get(), Integer.valueOf(1));
 
-        Integer nextValue = sequence.invoke(SequenceEntity.NEXT_VALUE, ImmutableMap.<String,
Object>of()).getUnchecked();
+        Integer nextValue = sequence.invoke(SequenceEntity.INCREMENT_AND_GET, ImmutableMap.<String,
Object>of()).getUnchecked();
         assertEquals(nextValue, Integer.valueOf(2));
 
-        String nextString = sequence.invoke(SequenceEntity.NEXT_STRING, ImmutableMap.<String,
Object>of()).getUnchecked();
-        assertEquals(nextString, "3");
+        nextValue = sequence.invoke(SequenceEntity.INCREMENT_AND_GET, ImmutableMap.<String,
Object>of()).getUnchecked();
+        assertEquals(nextValue, Integer.valueOf(3));
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(3));
-        assertEquals(sequence.currentString(), "3");
+        assertEquals(sequence.get(), Integer.valueOf(3));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 3);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "3");
     }
 
     @Test
@@ -157,23 +138,19 @@ public class SequenceEntityTest extends BrooklynAppUnitTestSupport {
 
         assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(1));
+        assertEquals(sequence.get(), Integer.valueOf(1));
 
         sequence.increment();
         sequence.increment();
         sequence.increment();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(4));
-        assertEquals(sequence.currentString(), "4");
+        assertEquals(sequence.get(), Integer.valueOf(4));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 4);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "4");
 
         sequence.invoke(SequenceEntity.RESET, ImmutableMap.<String, Object>of()).getUnchecked();
 
-        assertEquals(sequence.currentValue(), Integer.valueOf(1));
-        assertEquals(sequence.currentString(), "1");
+        assertEquals(sequence.get(), Integer.valueOf(1));
         assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 1);
-        assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_STRING, "1");
     }
 
 }


Mime
View raw message