http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/CustomAggregatingEnricherTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/CustomAggregatingEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/CustomAggregatingEnricherTest.java index dbc84ed..4aed5c6 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/CustomAggregatingEnricherTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/CustomAggregatingEnricherTest.java @@ -71,7 +71,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWithNoProducersDefaultsToNull() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -82,7 +82,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWithNoProducers() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -95,7 +95,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWhenNoSensorValuesYet() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -108,7 +108,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWhenNoSensorValuesYetDefaultsToNull() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -119,7 +119,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWithNoValues() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -130,33 +130,33 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testSummingEnricherWithOneValue() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromHardcodedProducers(ImmutableList.of(entity)) .build()); - entity.setAttribute(intSensor, 1); + entity.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); } @Test public void testSummingEnricherWhenNullSensorValue() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromHardcodedProducers(ImmutableList.of(entity)) .build()); - entity.setAttribute(intSensor, null); + entity.sensors().set(intSensor, null); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, target, null); } @Test public void testSummingEnricherWhenDefaultValueForUnreportedSensors() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -167,13 +167,13 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, target, 3); - entity.setAttribute(intSensor, null); + entity.sensors().set(intSensor, null); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, target, 3); - entity.setAttribute(intSensor, 1); + entity.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); - entity.setAttribute(intSensor, 7); + entity.sensors().set(intSensor, 7); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 7); } @@ -183,20 +183,20 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromHardcodedProducers(ImmutableList.of(producer1, producer2, producer3)) .build()); - producer3.setAttribute(intSensor, 1); + producer3.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); - producer1.setAttribute(intSensor, 2); + producer1.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 3); - producer2.setAttribute(intSensor, 4); + producer2.sensors().set(intSensor, 4); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 7); } @@ -204,7 +204,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { public void testAveragingEnricherWhenNoAndNullSensorValues() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -213,7 +213,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); - producer1.setAttribute(intSensor, null); + producer1.sensors().set(intSensor, null); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); } @@ -221,7 +221,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { public void testAveragingEnricherWhenDefaultValueForUnreportedSensors() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -232,16 +232,16 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 3d); - producer1.setAttribute(intSensor, null); + producer1.sensors().set(intSensor, null); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, 3d); - producer1.setAttribute(intSensor, 4); + producer1.sensors().set(intSensor, 4); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 4d); } @Test public void testAveragingEnricherWhenNoSensors() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -255,7 +255,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testAveragingEnricherWhenNoProducersDefaultsToNull() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -271,7 +271,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -280,16 +280,16 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, null); - producer1.setAttribute(intSensor, 3); + producer1.sensors().set(intSensor, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 3d); - producer2.setAttribute(intSensor, 1); + producer2.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 2d); - producer3.setAttribute(intSensor, 5); + producer3.sensors().set(intSensor, 5); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 3d); - producer2.setAttribute(intSensor, 4); + producer2.sensors().set(intSensor, 4); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 4d); } @@ -299,7 +299,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() @@ -310,13 +310,13 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 0d); - producer1.setAttribute(intSensor, 3); + producer1.sensors().set(intSensor, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 1d); - producer2.setAttribute(intSensor, 3); + producer2.sensors().set(intSensor, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 2d); - producer3.setAttribute(intSensor, 3); + producer3.sensors().set(intSensor, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, doubleSensor, 3d); } @@ -327,7 +327,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity p2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); log.debug("created {} and the entities it will contain {} {}", new Object[] {group, p1, p2}); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -339,11 +339,11 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(group, target, 0); group.addMember(p1); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(group, target, 1); group.addMember(p2); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(group, target, 3); group.removeMember(p2); @@ -362,10 +362,10 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity p2 = app.getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(group)); group.addMember(p1); group.addMember(p2); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); Entities.manage(group); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -375,7 +375,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(group, target, 1); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(group, target, 3); group.removeMember(p2); @@ -389,10 +389,10 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity p2 = app.getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(group)); group.addMember(p1); group.addMember(p2); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); Entities.manage(group); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -403,7 +403,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(app, target, 1); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(app, target, 3); group.removeMember(p2); @@ -418,11 +418,11 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { TestEntity p3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); group.addMember(p1); group.addMember(p2); - p1.setAttribute(intSensor, 1); - p2.setAttribute(intSensor, 2); - p3.setAttribute(intSensor, 4); + p1.sensors().set(intSensor, 1); + p2.sensors().set(intSensor, 2); + p3.sensors().set(intSensor, 4); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -438,7 +438,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testAggregatesNewChidren() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -450,11 +450,11 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, target, 0); TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 3); Entities.unmanage(p2); @@ -465,9 +465,9 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { public void testAggregatesExistingChildren() { TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -477,7 +477,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 3); Entities.unmanage(p2); @@ -488,9 +488,9 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { public void testAggregatesChildrenOfProducer() { TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -501,7 +501,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(app, target, 1); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(app, target, 3); Entities.unmanage(p2); @@ -511,9 +511,9 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testAppliesFilterWhenAggregatingChildrenOfGroup() { TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p1.setAttribute(intSensor, 1); + p1.sensors().set(intSensor, 1); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() @@ -524,7 +524,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); - p2.setAttribute(intSensor, 2); + p2.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), entity, target, 1); } @@ -539,7 +539,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { } }; - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computing(aggregator) @@ -550,7 +550,7 @@ public class CustomAggregatingEnricherTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(entity, target, 1); // Event by producer - producer1.setAttribute(intSensor, 2); + producer1.sensors().set(intSensor, 2); EntityTestUtils.assertAttributeEqualsEventually(entity, target, 5); } }
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/EnrichersTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/EnrichersTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/EnrichersTest.java index e5c48fa..832b974 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/EnrichersTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/EnrichersTest.java @@ -82,10 +82,9 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); } - @SuppressWarnings("unchecked") @Test public void testAdding() { - Enricher enr = entity.addEnricher(Enrichers.builder() + Enricher enr = entity.enrichers().add(Enrichers.builder() .combining(NUM1, NUM2) .publishing(NUM3) .computingSum() @@ -93,29 +92,27 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { Assert.assertEquals(EntityAdjuncts.getNonSystemEnrichers(entity), ImmutableList.of(enr)); - entity.setAttribute(NUM1, 2); - entity.setAttribute(NUM2, 3); + entity.sensors().set(NUM1, 2); + entity.sensors().set(NUM2, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, NUM3, 5); } - @SuppressWarnings("unchecked") @Test public void testCombiningWithCustomFunction() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .combining(NUM1, NUM2) .publishing(NUM3) .computing(Functions.constant(1)) .build()); - entity.setAttribute(NUM1, 2); - entity.setAttribute(NUM2, 3); + entity.sensors().set(NUM1, 2); + entity.sensors().set(NUM2, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, NUM3, 1); } - @SuppressWarnings("unchecked") @Test(groups="Integration") // because takes a second public void testCombiningRespectsUnchanged() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .combining(NUM1, NUM2) .<Object>publishing(NUM3) .computing(new Function<Iterable<Integer>, Object>() { @@ -128,54 +125,54 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { }}) .build()); - entity.setAttribute(NUM1, 123); - entity.setAttribute(NUM2, 3); + entity.sensors().set(NUM1, 123); + entity.sensors().set(NUM2, 3); EntityTestUtils.assertAttributeEqualsEventually(entity, NUM3, 126); - entity.setAttribute(NUM1, 2); + entity.sensors().set(NUM1, 2); EntityTestUtils.assertAttributeEqualsContinually(entity, NUM3, 126); } @Test public void testFromEntity() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(NUM1) .publishing(NUM1) .computing(Functions.<Integer>identity()) .from(entity2) .build()); - entity2.setAttribute(NUM1, 2); + entity2.sensors().set(NUM1, 2); EntityTestUtils.assertAttributeEqualsEventually(entity, NUM1, 2); } @Test public void testTransforming() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(STR1) .publishing(STR2) .computing(StringFunctions.append("mysuffix")) .build()); - entity.setAttribute(STR1, "myval"); + entity.sensors().set(STR1, "myval"); EntityTestUtils.assertAttributeEqualsEventually(entity, STR2, "myvalmysuffix"); } @Test public void testTransformingCastsResult() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(NUM1) .publishing(LONG1) .computing(Functions.constant(Long.valueOf(1))) .build()); - entity.setAttribute(NUM1, 123); + entity.sensors().set(NUM1, 123); EntityTestUtils.assertAttributeEqualsEventually(entity, LONG1, Long.valueOf(1)); } @Test public void testTransformingFromEvent() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(STR1) .publishing(STR2) .computingFromEvent(new Function<SensorEvent<String>, String>() { @@ -184,7 +181,7 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { }}) .build()); - entity.setAttribute(STR1, "myval"); + entity.sensors().set(STR1, "myval"); EntityTestUtils.assertAttributeEqualsEventually(entity, STR2, "myvalmysuffix"); } @@ -193,7 +190,7 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>(); app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(STR1) .<Object>publishing(STR2) .computing(new Function<String, Object>() { @@ -203,20 +200,20 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { .build()); Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(0)); - entity.setAttribute(STR1, "myval"); + entity.sensors().set(STR1, "myval"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1)); EntityTestUtils.assertAttributeEquals(entity, STR2, "myval"); - entity.setAttribute(STR1, "ignoredval"); + entity.sensors().set(STR1, "ignoredval"); EntityTestUtils.assertAttributeEqualsContinually(entity, STR2, "myval"); - entity.setAttribute(STR1, "myval2"); + entity.sensors().set(STR1, "myval2"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(2)); EntityTestUtils.assertAttributeEquals(entity, STR2, "myval2"); - entity.setAttribute(STR1, "myval2"); - entity.setAttribute(STR1, "myval2"); - entity.setAttribute(STR1, "myval3"); + entity.sensors().set(STR1, "myval2"); + entity.sensors().set(STR1, "myval2"); + entity.sensors().set(STR1, "myval3"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(5)); } @@ -224,46 +221,46 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>(); app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record); - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .transforming(STR1) .publishing(STR2) .computing(Functions.<String>identity()) .suppressDuplicates(true) .build()); - entity.setAttribute(STR1, "myval"); + entity.sensors().set(STR1, "myval"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1)); EntityTestUtils.assertAttributeEquals(entity, STR2, "myval"); - entity.setAttribute(STR1, "myval2"); - entity.setAttribute(STR1, "myval2"); - entity.setAttribute(STR1, "myval3"); + entity.sensors().set(STR1, "myval2"); + entity.sensors().set(STR1, "myval2"); + entity.sensors().set(STR1, "myval3"); EntityTestUtils.assertAttributeEqualsContinually(entity, STR2, "myval3"); Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(3)); } @Test public void testPropagating() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .propagating(ImmutableList.of(STR1)) .from(entity2) .build()); - entity2.setAttribute(STR1, "myval"); + entity2.sensors().set(STR1, "myval"); EntityTestUtils.assertAttributeEqualsEventually(entity, STR1, "myval"); - entity2.setAttribute(STR1, null); + entity2.sensors().set(STR1, null); EntityTestUtils.assertAttributeEqualsEventually(entity, STR1, null); } @Test public void testPropagatingAndRenaming() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(STR1, STR2)) .from(entity2) .build()); - entity2.setAttribute(STR1, "myval"); + entity2.sensors().set(STR1, "myval"); EntityTestUtils.assertAttributeEqualsEventually(entity, STR2, "myval"); } @@ -274,16 +271,16 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { Entities.manage(child1); group.addMember(entity); group.addMember(entity2); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .publishing(NUM2) .fromMembers() .computingSum() .build()); - child1.setAttribute(NUM1, 1); - entity.setAttribute(NUM1, 2); - entity2.setAttribute(NUM1, 3); + child1.sensors().set(NUM1, 1); + entity.sensors().set(NUM1, 2); + entity2.sensors().set(NUM1, 3); EntityTestUtils.assertAttributeEqualsEventually(group, NUM2, 5); } @@ -294,16 +291,16 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { Entities.manage(child1); TestEntity child2 = group.addChild(EntitySpec.create(TestEntity.class)); Entities.manage(child2); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .publishing(NUM2) .fromChildren() .computingSum() .build()); - entity.setAttribute(NUM1, 1); - child1.setAttribute(NUM1, 2); - child2.setAttribute(NUM1, 3); + entity.sensors().set(NUM1, 1); + child1.sensors().set(NUM1, 2); + child2.sensors().set(NUM1, 3); EntityTestUtils.assertAttributeEqualsEventually(group, NUM2, 5); } @@ -311,7 +308,7 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { public void testAggregatingExcludingBlankString() { group.addMember(entity); group.addMember(entity2); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(STR1) .publishing(SET1) .fromMembers() @@ -323,23 +320,23 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { }}) .build()); - entity.setAttribute(STR1, "1"); - entity2.setAttribute(STR1, "2"); + entity.sensors().set(STR1, "1"); + entity2.sensors().set(STR1, "2"); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("1", "2")); - entity.setAttribute(STR1, "3"); - entity2.setAttribute(STR1, null); + entity.sensors().set(STR1, "3"); + entity2.sensors().set(STR1, null); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("3")); - entity.setAttribute(STR1, ""); - entity2.setAttribute(STR1, "4"); + entity.sensors().set(STR1, ""); + entity2.sensors().set(STR1, "4"); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of("4")); } @Test public void testAggregatingExcludingNull() { group.addMember(entity); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .publishing(SET1) .fromMembers() @@ -353,34 +350,34 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of()); - entity.setAttribute(NUM1, 1); + entity.sensors().set(NUM1, 1); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of(1)); - entity.setAttribute(NUM1, null); + entity.sensors().set(NUM1, null); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of()); - entity.setAttribute(NUM1, 2); + entity.sensors().set(NUM1, 2); EntityTestUtils.assertAttributeEqualsEventually(group, SET1, ImmutableSet.<Object>of(2)); } @Test public void testAggregatingCastsResult() { group.addMember(entity); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .publishing(LONG1) .fromMembers() .computing(Functions.constant(Long.valueOf(1))) .build()); - entity.setAttribute(NUM1, 123); + entity.sensors().set(NUM1, 123); EntityTestUtils.assertAttributeEqualsEventually(group, LONG1, Long.valueOf(1)); } @Test(groups="Integration") // because takes a second public void testAggregatingRespectsUnchanged() { group.addMember(entity); - group.addEnricher(Enrichers.builder() + group.enrichers().add(Enrichers.builder() .aggregating(NUM1) .<Object>publishing(LONG1) .fromMembers() @@ -394,15 +391,15 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { }}) .build()); - entity.setAttribute(NUM1, 123); + entity.sensors().set(NUM1, 123); EntityTestUtils.assertAttributeEqualsEventually(group, LONG1, Long.valueOf(123)); - entity.setAttribute(NUM1, 987654); + entity.sensors().set(NUM1, 987654); EntityTestUtils.assertAttributeEqualsContinually(group, LONG1, Long.valueOf(123)); } @Test public void testUpdatingMap1() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .updatingMap(MAP1) .from(LONG1) .computing(Functionals.ifEquals(-1L).value("-1 is not allowed")) @@ -414,7 +411,7 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testUpdatingMap2() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .updatingMap((AttributeSensor)MAP2) .from(LONG1) .computing(Functionals.ifEquals(-1L).value("-1 is not allowed")) @@ -427,11 +424,11 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { protected void doUpdatingMapChecks(AttributeSensor mapSensor) { EntityTestUtils.assertAttributeEqualsEventually(entity, mapSensor, MutableMap.<String,String>of()); - entity.setAttribute(LONG1, -1L); + entity.sensors().set(LONG1, -1L); EntityTestUtils.assertAttributeEqualsEventually(entity, mapSensor, MutableMap.<String,String>of( LONG1.getName(), "-1 is not allowed")); - entity.setAttribute(LONG1, 1L); + entity.sensors().set(LONG1, 1L); EntityTestUtils.assertAttributeEqualsEventually(entity, mapSensor, MutableMap.<String,String>of()); } @@ -439,27 +436,27 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { @Test public void testJoinerDefault() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .joining(LIST_SENSOR) .publishing(TestEntity.NAME) .build()); // null values ignored, and it quotes - entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "\"b").append(null)); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "\"b").append(null)); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, "\"a\",\"\\\"b\""); // empty list causes "" - entity.setAttribute(LIST_SENSOR, MutableList.<String>of().append(null)); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of().append(null)); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, ""); // null causes null - entity.setAttribute(LIST_SENSOR, null); + entity.sensors().set(LIST_SENSOR, null); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null); } @Test public void testJoinerUnquoted() { - entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "\"b", "ccc").append(null)); - entity.addEnricher(Enrichers.builder() + entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "\"b", "ccc").append(null)); + entity.enrichers().add(Enrichers.builder() .joining(LIST_SENSOR) .publishing(TestEntity.NAME) .minimum(1) @@ -471,13 +468,13 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEquals(entity, TestEntity.NAME, "a:\"b"); // empty list causes null here, because below the minimum - entity.setAttribute(LIST_SENSOR, MutableList.<String>of().append(null)); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of().append(null)); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null); } @Test public void testJoinerMinMax() { - entity.addEnricher(Enrichers.builder() + entity.enrichers().add(Enrichers.builder() .joining(LIST_SENSOR) .publishing(TestEntity.NAME) .minimum(2) @@ -485,15 +482,15 @@ public class EnrichersTest extends BrooklynAppUnitTestSupport { .quote(false) .build()); // null values ignored, and it quotes - entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "b")); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "b")); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, "a,b"); // empty list causes "" - entity.setAttribute(LIST_SENSOR, MutableList.<String>of("x")); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of("x")); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, null); // null causes null - entity.setAttribute(LIST_SENSOR, MutableList.<String>of("a", "b", "c", "d", "e")); + entity.sensors().set(LIST_SENSOR, MutableList.<String>of("a", "b", "c", "d", "e")); EntityTestUtils.assertAttributeEqualsEventually(entity, TestEntity.NAME, "a,b,c,d"); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherDeprecatedTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherDeprecatedTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherDeprecatedTest.java index a52e2ee..2f7eca9 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherDeprecatedTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherDeprecatedTest.java @@ -51,58 +51,58 @@ public class SensorPropagatingEnricherDeprecatedTest extends BrooklynAppUnitTest @Test public void testPropagatesSpecificSensor() { - app.addEnricher(SensorPropagatingEnricher.newInstanceListeningTo(entity, TestEntity.NAME)); + app.enrichers().add(SensorPropagatingEnricher.newInstanceListeningTo(entity, TestEntity.NAME)); // name propagated - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); } @Test public void testPropagatesAllSensors() { - app.addEnricher(SensorPropagatingEnricher.newInstanceListeningToAllSensors(entity)); + app.enrichers().add(SensorPropagatingEnricher.newInstanceListeningToAllSensors(entity)); // all attributes propagated - entity.setAttribute(TestEntity.NAME, "foo"); - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2); // notification-sensor propagated final AtomicReference<Integer> notif = new AtomicReference<Integer>(); - app.subscribe(app, TestEntity.MY_NOTIF, new SensorEventListener<Integer>() { + app.subscriptions().subscribe(app, TestEntity.MY_NOTIF, new SensorEventListener<Integer>() { @Override public void onEvent(SensorEvent<Integer> event) { notif.set(event.getValue()); }}); - entity.emit(TestEntity.MY_NOTIF, 7); + entity.sensors().emit(TestEntity.MY_NOTIF, 7); Asserts.eventually(AtomicReferences.supplier(notif), Predicates.equalTo(7)); } @Test public void testPropagatesAllBut() { - app.addEnricher(SensorPropagatingEnricher.newInstanceListeningToAllSensorsBut(entity, TestEntity.SEQUENCE)) ; + app.enrichers().add(SensorPropagatingEnricher.newInstanceListeningToAllSensorsBut(entity, TestEntity.SEQUENCE)) ; // name propagated - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); } @Test public void testPropagatingAsDifferentSensor() { final AttributeSensor<String> ANOTHER_ATTRIBUTE = Sensors.newStringSensor("another.attribute", ""); - app.addEnricher(SensorPropagatingEnricher.newInstanceRenaming(entity, ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE))); + app.enrichers().add(SensorPropagatingEnricher.newInstanceRenaming(entity, ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE))); // name propagated as different attribute - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, ANOTHER_ATTRIBUTE, "foo"); } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherTest.java index 090b0a4..4343127 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/SensorPropagatingEnricherTest.java @@ -54,25 +54,25 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testPropagatesSpecificSensor() { - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(TestEntity.NAME) .from(entity) .build()); // name propagated - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); } @Test public void testPropagatesCurrentValue() { - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(TestEntity.NAME) .from(entity) .build()); @@ -83,25 +83,25 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testPropagatesAllStaticSensors() { - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagatingAll() .from(entity) .build()); // all attributes propagated - entity.setAttribute(TestEntity.NAME, "foo"); - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2); // notification-sensor propagated final AtomicReference<Integer> notif = new AtomicReference<Integer>(); - app.subscribe(app, TestEntity.MY_NOTIF, new SensorEventListener<Integer>() { + app.subscriptions().subscribe(app, TestEntity.MY_NOTIF, new SensorEventListener<Integer>() { @Override public void onEvent(SensorEvent<Integer> event) { notif.set(event.getValue()); }}); - entity.emit(TestEntity.MY_NOTIF, 7); + entity.sensors().emit(TestEntity.MY_NOTIF, 7); Asserts.eventually(AtomicReferences.supplier(notif), Predicates.equalTo(7)); } @@ -110,38 +110,38 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { AttributeSensor<String> dynamicAttribute = Sensors.newStringSensor("test.dynamicsensor.strattrib"); BasicNotificationSensor<String> dynamicNotificationSensor = new BasicNotificationSensor(String.class, "test.dynamicsensor.strnotif"); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagatingAll() .from(entity) .build()); - entity.setAttribute(dynamicAttribute, "foo"); + entity.sensors().set(dynamicAttribute, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, dynamicAttribute, "foo"); // notification-sensor propagated final AtomicReference<String> notif = new AtomicReference<String>(); - app.subscribe(app, dynamicNotificationSensor, new SensorEventListener<String>() { + app.subscriptions().subscribe(app, dynamicNotificationSensor, new SensorEventListener<String>() { @Override public void onEvent(SensorEvent<String> event) { notif.set(event.getValue()); }}); - entity.emit(dynamicNotificationSensor, "mynotifval"); + entity.sensors().emit(dynamicNotificationSensor, "mynotifval"); Asserts.eventually(AtomicReferences.supplier(notif), Predicates.equalTo("mynotifval")); } @Test public void testPropagatesAllBut() { - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagatingAllBut(TestEntity.SEQUENCE) .from(entity) .build()); // name propagated - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); } @@ -149,30 +149,30 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { public void testPropagatingAsDifferentSensor() { final AttributeSensor<String> ANOTHER_ATTRIBUTE = Sensors.newStringSensor("another.attribute", ""); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE)) .from(entity) .build()); // name propagated as different attribute - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, ANOTHER_ATTRIBUTE, "foo"); } @Test public void testEnricherSpecPropagatesSpecificSensor() throws Exception { - app.addEnricher(EnricherSpec.create(Propagator.class) + app.enrichers().add(EnricherSpec.create(Propagator.class) .configure(MutableMap.builder() .putIfNotNull(Propagator.PRODUCER, entity) .putIfNotNull(Propagator.PROPAGATING, ImmutableList.of(TestEntity.NAME)) .build())); // name propagated - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); } @@ -180,7 +180,7 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { public void testEnricherSpecPropagatesSpecificSensorAndMapsOthers() throws Exception { final AttributeSensor<String> ANOTHER_ATTRIBUTE = Sensors.newStringSensor("another.attribute", ""); - app.addEnricher(EnricherSpec.create(Propagator.class) + app.enrichers().add(EnricherSpec.create(Propagator.class) .configure(MutableMap.builder() .putIfNotNull(Propagator.PRODUCER, entity) .putIfNotNull(Propagator.SENSOR_MAPPING, ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE)) @@ -188,11 +188,11 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { .build())); // name propagated as alternative sensor - entity.setAttribute(TestEntity.NAME, "foo"); + entity.sensors().set(TestEntity.NAME, "foo"); EntityTestUtils.assertAttributeEqualsEventually(app, ANOTHER_ATTRIBUTE, "foo"); // sequence also propagated - entity.setAttribute(TestEntity.SEQUENCE, 2); + entity.sensors().set(TestEntity.SEQUENCE, 2); EntityTestUtils.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2); // name not propagated as original sensor @@ -202,7 +202,7 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testEnricherSpecThrowsOnPropagatesAndPropagatesAllSet() throws Exception { try { - app.addEnricher(EnricherSpec.create(Propagator.class) + app.enrichers().add(EnricherSpec.create(Propagator.class) .configure(MutableMap.builder() .put(Propagator.PRODUCER, entity) .put(Propagator.PROPAGATING, ImmutableList.of(TestEntity.NAME)) @@ -219,7 +219,7 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { AttributeSensor<String> origSensor = Sensors.newSensor(String.class, "origSensor"); AttributeSensor<Object> sourceSensorFromYaml = Sensors.newSensor(Object.class, "origSensor"); AttributeSensor<Object> targetSensor = Sensors.newSensor(Object.class, "newSensor"); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(sourceSensorFromYaml, targetSensor)) .from(entity) .build()); @@ -253,11 +253,11 @@ public class SensorPropagatingEnricherTest extends BrooklynAppUnitTestSupport { */ AttributeSensor<Object> targetSensor = Sensors.newSensor(Object.class, "newSensor"); AttributeSensor<Object> sourceSensorFromYaml = Sensors.newSensor(Object.class, TestEntity.NAME.getName()); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(Sensors.newSensor(Object.class, TestEntity.NAME.getName())) .from(entity) .build()); - app.addEnricher(Enrichers.builder() + app.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(sourceSensorFromYaml, targetSensor)) .from(app) .build()); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.groovy ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.groovy b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.groovy index b524738..9d4952d 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.groovy +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.groovy @@ -69,9 +69,9 @@ public class TransformingEnricherDeprecatedTest { final SensorTransformingEnricher e1 = new SensorTransformingEnricher<Integer,Long>(intSensorA, target, { 2*it }); - producer.setAttribute(intSensorA, 3); + producer.sensors().set(intSensorA, 3); //ensure previous values get picked up - producer.addEnricher(e1); + producer.enrichers().add(e1); Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Callable<Object>() { public Object call() { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java index ee8fc9e..74ea6ff 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherTest.java @@ -57,9 +57,9 @@ public class TransformingEnricherTest extends BrooklynAppUnitTestSupport { @Test public void testTransformingEnricher() throws Exception { //ensure previous values get picked up - producer.setAttribute(intSensorA, 3); + producer.sensors().set(intSensorA, 3); - producer.addEnricher(Enrichers.builder() + producer.enrichers().add(Enrichers.builder() .transforming(intSensorA) //.computing(MathFunctions.times(2)) // TODO calling it before "publishing" means it doesn't check return type! .publishing(target) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricherTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricherTest.java index af683ac..58eed85 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricherTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlRollingTimeWindowMeanEnricherTest.java @@ -65,12 +65,12 @@ public class YamlRollingTimeWindowMeanEnricherTest { deltaSensor = new BasicAttributeSensor<Double>(Double.class, "delta sensor"); avgSensor = new BasicAttributeSensor<Double>(Double.class, "avg sensor"); - delta = producer.addEnricher(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) + delta = producer.enrichers().add(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) .configure(YamlTimeWeightedDeltaEnricher.PRODUCER, producer) .configure(YamlTimeWeightedDeltaEnricher.SOURCE_SENSOR, intSensor) .configure(YamlTimeWeightedDeltaEnricher.TARGET_SENSOR, deltaSensor)); - averager = producer.addEnricher(EnricherSpec.create(YamlRollingTimeWindowMeanEnricher.class) + averager = producer.enrichers().add(EnricherSpec.create(YamlRollingTimeWindowMeanEnricher.class) .configure(YamlRollingTimeWindowMeanEnricher.PRODUCER, producer) .configure(YamlRollingTimeWindowMeanEnricher.SOURCE_SENSOR, deltaSensor) .configure(YamlRollingTimeWindowMeanEnricher.TARGET_SENSOR, avgSensor) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricherTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricherTest.java b/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricherTest.java index 41b75a7..8923333 100644 --- a/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricherTest.java +++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/YamlTimeWeightedDeltaEnricherTest.java @@ -62,7 +62,7 @@ public class YamlTimeWeightedDeltaEnricherTest { @Test public void testMonospaceTimeWeightedDeltaEnricher() { @SuppressWarnings("unchecked") - YamlTimeWeightedDeltaEnricher<Integer> delta = producer.addEnricher(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) + YamlTimeWeightedDeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) .configure(YamlTimeWeightedDeltaEnricher.PRODUCER, producer) .configure(YamlTimeWeightedDeltaEnricher.SOURCE_SENSOR, intSensor) .configure(YamlTimeWeightedDeltaEnricher.TARGET_SENSOR, deltaSensor)); @@ -86,7 +86,7 @@ public class YamlTimeWeightedDeltaEnricherTest { @Test public void testVariableTimeWeightedDeltaEnricher() { @SuppressWarnings("unchecked") - YamlTimeWeightedDeltaEnricher<Integer> delta = producer.addEnricher(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) + YamlTimeWeightedDeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(YamlTimeWeightedDeltaEnricher.class) .configure(YamlTimeWeightedDeltaEnricher.PRODUCER, producer) .configure(YamlTimeWeightedDeltaEnricher.SOURCE_SENSOR, intSensor) .configure(YamlTimeWeightedDeltaEnricher.TARGET_SENSOR, deltaSensor)); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java index 44e4fbd..f575a42 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java @@ -215,7 +215,7 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport { .configure(DynamicCluster.INITIAL_SIZE, 1)); RecordingSensorEventListener<Lifecycle> r = new RecordingSensorEventListener<>(); - app.subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, r); + app.subscriptions().subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, r); cluster.start(ImmutableList.of(loc)); EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java index 42c7d90..4acc317 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java @@ -76,7 +76,7 @@ public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTest @Test public void testPicksCorrectNumSubLocations() throws Exception { - ((EntityLocal)cluster).setConfig(DynamicCluster.NUM_AVAILABILITY_ZONES, 2); + ((EntityLocal)cluster).config().set(DynamicCluster.NUM_AVAILABILITY_ZONES, 2); cluster.start(ImmutableList.of(loc)); List<Location> subLocations = cluster.getAttribute(DynamicCluster.SUB_LOCATIONS); List<String> subLocationNames = getLocationNames(subLocations); @@ -85,7 +85,7 @@ public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTest @Test public void testPicksCorrectNamedSubLocations() throws Exception { - ((EntityLocal)cluster).setConfig(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone2", "zone4")); + ((EntityLocal)cluster).config().set(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone2", "zone4")); cluster.start(ImmutableList.of(loc)); List<Location> subLocations = cluster.getAttribute(DynamicCluster.SUB_LOCATIONS); List<String> subLocationNames = getLocationNames(subLocations); @@ -94,7 +94,7 @@ public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTest @Test public void testSpreadsEntitiesAcrossZonesEvenly() throws Exception { - ((EntityLocal)cluster).setConfig(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); + ((EntityLocal)cluster).config().set(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); cluster.start(ImmutableList.of(loc)); cluster.resize(4); @@ -112,7 +112,7 @@ public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTest @Test public void testReplacesEntityInSameZone() throws Exception { - ((EntityLocal)cluster).setConfig(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); + ((EntityLocal)cluster).config().set(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); cluster.start(ImmutableList.of(loc)); cluster.resize(4); @@ -144,9 +144,9 @@ public class DynamicClusterWithAvailabilityZonesTest extends BrooklynAppUnitTest } }; - ((EntityLocal)cluster).setConfig(DynamicCluster.ZONE_FAILURE_DETECTOR, new ProportionalZoneFailureDetector(2, Duration.ONE_HOUR, 0.9, ticker)); - ((EntityLocal)cluster).setConfig(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); - ((EntityLocal)cluster).setConfig(DynamicCluster.MEMBER_SPEC, EntitySpec.create(FailingEntity.class) + ((EntityLocal)cluster).config().set(DynamicCluster.ZONE_FAILURE_DETECTOR, new ProportionalZoneFailureDetector(2, Duration.ONE_HOUR, 0.9, ticker)); + ((EntityLocal)cluster).config().set(DynamicCluster.AVAILABILITY_ZONE_NAMES, ImmutableList.of("zone1", "zone2")); + ((EntityLocal)cluster).config().set(DynamicCluster.MEMBER_SPEC, EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_START_CONDITION, failurePredicate)); cluster.start(ImmutableList.of(loc)); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java index 1b7ec97..dc327e3 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java @@ -45,9 +45,6 @@ import org.apache.brooklyn.core.entity.EntityPredicates; import org.apache.brooklyn.core.sensor.Sensors; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.group.AbstractGroup; -import org.apache.brooklyn.entity.group.DynamicGroup; -import org.apache.brooklyn.entity.group.DynamicGroupImpl; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.exceptions.Exceptions; @@ -156,7 +153,7 @@ public class DynamicGroupTest { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of()); // When changed (such that subscription spots it), then entity added - e1.setAttribute(MY_ATTRIBUTE, "yes"); + e1.sensors().set(MY_ATTRIBUTE, "yes"); Asserts.succeedsEventually(new Runnable() { public void run() { @@ -164,7 +161,7 @@ public class DynamicGroupTest { }}); // When it stops matching, entity is removed - e1.setAttribute(MY_ATTRIBUTE, "no"); + e1.sensors().set(MY_ATTRIBUTE, "no"); Asserts.succeedsEventually(new Runnable() { public void run() { @@ -195,8 +192,8 @@ public class DynamicGroupTest { // Does not subscribe to things which do not match predicate filter, // so event from e1 should normally be ignored // but pending rescans may cause it to pick up e1, so we ignore e1 in the entity filter also - e1.setAttribute(MY_ATTRIBUTE, "yes"); - e2.setAttribute(MY_ATTRIBUTE, "yes"); + e1.sensors().set(MY_ATTRIBUTE, "yes"); + e2.sensors().set(MY_ATTRIBUTE, "yes"); Asserts.succeedsEventually(new Runnable() { public void run() { @@ -272,7 +269,7 @@ public class DynamicGroupTest { final AtomicInteger removedNotifications = new AtomicInteger(0); final List<Exception> exceptions = new CopyOnWriteArrayList<Exception>(); - app.subscribe(group, DynamicGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { + app.subscriptions().subscribe(group, DynamicGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { public void onEvent(SensorEvent<Entity> event) { try { TestEntity val = (TestEntity) event.getValue(); @@ -286,7 +283,7 @@ public class DynamicGroupTest { } }}); - app.subscribe(group, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() { + app.subscriptions().subscribe(group, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() { public void onEvent(SensorEvent<Entity> event) { try { TestEntity val = (TestEntity) event.getValue(); @@ -376,7 +373,7 @@ public class DynamicGroupTest { notificationCount.incrementAndGet(); } }; - ((EntityLocal)group2).setConfig(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)); + group2.config().set(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)); app.addChild(group2); Entities.manage(group2); @@ -427,7 +424,7 @@ public class DynamicGroupTest { super.onEntityAdded(item); } }; - ((EntityLocal)group2).setConfig(DynamicGroup.ENTITY_FILTER, Predicates.<Object>equalTo(e3)); + group2.config().set(DynamicGroup.ENTITY_FILTER, Predicates.<Object>equalTo(e3)); app.addChild(group2); Thread t1 = new Thread(new Runnable() { @@ -476,18 +473,24 @@ public class DynamicGroupTest { final List<Entity> membersAdded = new CopyOnWriteArrayList<Entity>(); final DynamicGroupImpl group2 = new DynamicGroupImpl() { - @Override - public <T> void emit(Sensor<T> sensor, T val) { - // intercept inside AbstractGroup.addMember, while it still holds lock on members - if (sensor == AbstractGroup.MEMBER_ADDED && addingMemberDoLatching.get()) { - addingMemberReachedLatch.countDown(); - try { - addingMemberContinueLatch.await(); - } catch (InterruptedException e) { - throw Exceptions.propagate(e); + private final BasicSensorSupport interceptedSensors = new BasicSensorSupport() { + @Override + public <T> void emit(Sensor<T> sensor, T val) { + // intercept inside AbstractGroup.addMember, while it still holds lock on members + if (sensor == AbstractGroup.MEMBER_ADDED && addingMemberDoLatching.get()) { + addingMemberReachedLatch.countDown(); + try { + addingMemberContinueLatch.await(); + } catch (InterruptedException e) { + throw Exceptions.propagate(e); + } } + super.emit(sensor, val); } - super.emit(sensor, val); + }; + @Override + public BasicSensorSupport sensors() { + return interceptedSensors; } @Override public boolean removeMember(final Entity member) { @@ -495,11 +498,11 @@ public class DynamicGroupTest { return super.removeMember(member); } }; - group2.setConfig(DynamicGroup.MEMBER_DELEGATE_CHILDREN, true); + group2.config().set(DynamicGroup.MEMBER_DELEGATE_CHILDREN, true); app.addChild(group2); Entities.manage(group2); - app.subscribe(group2, AbstractGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { + app.subscriptions().subscribe(group2, AbstractGroup.MEMBER_ADDED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { membersAdded.add(event.getValue()); }}); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java index d0d1235..7f96d71 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java @@ -78,7 +78,7 @@ public class DynamicMultiGroupTest { .configure(ENTITY_FILTER, instanceOf(TestEntity.class)) .configure(BUCKET_FUNCTION, bucketFromAttribute(SENSOR)) ); - app.subscribeToChildren(group, SENSOR, new SensorEventListener<String>() { + app.subscriptions().subscribeToChildren(group, SENSOR, new SensorEventListener<String>() { public void onEvent(SensorEvent<String> event) { dmg.rescanEntities(); } }); @@ -118,7 +118,7 @@ public class DynamicMultiGroupTest { .configure(ENTITY_FILTER, instanceOf(TestEntity.class)) .configure(BUCKET_FUNCTION, bucketFromAttribute(SENSOR)) ); - app.subscribeToChildren(group, SENSOR, new SensorEventListener<String>() { + app.subscriptions().subscribeToChildren(group, SENSOR, new SensorEventListener<String>() { public void onEvent(SensorEvent<String> event) { dmg.rescanEntities(); } }); @@ -127,8 +127,8 @@ public class DynamicMultiGroupTest { TestEntity child2 = app.createAndManageChild(EntitySpec.create(childSpec).displayName("child2")); // Expect two buckets: bucketA and bucketB - child1.setAttribute(SENSOR, "bucketA"); - child2.setAttribute(SENSOR, "bucketB"); + child1.sensors().set(SENSOR, "bucketA"); + child2.sensors().set(SENSOR, "bucketB"); dmg.rescanEntities(); Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); @@ -136,8 +136,8 @@ public class DynamicMultiGroupTest { assertNotNull(bucketB); // Expect second bucket to be removed when empty - child1.setAttribute(SENSOR, "bucketA"); - child2.setAttribute(SENSOR, "bucketA"); + child1.sensors().set(SENSOR, "bucketA"); + child2.sensors().set(SENSOR, "bucketA"); dmg.rescanEntities(); bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); @@ -147,8 +147,8 @@ public class DynamicMultiGroupTest { private void checkDistribution(final Group group, final DynamicMultiGroup dmg, final EntitySpec<TestEntity> childSpec, final TestEntity child1, final TestEntity child2) { // Start with both children in bucket A; there is no bucket B - child1.setAttribute(SENSOR, "bucketA"); - child2.setAttribute(SENSOR, "bucketA"); + child1.sensors().set(SENSOR, "bucketA"); + child2.sensors().set(SENSOR, "bucketA"); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); @@ -160,7 +160,7 @@ public class DynamicMultiGroupTest { }); // Move child 1 into bucket B - child1.setAttribute(SENSOR, "bucketB"); + child1.sensors().set(SENSOR, "bucketB"); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); @@ -173,7 +173,7 @@ public class DynamicMultiGroupTest { }); // Move child 2 into bucket B; there is now no bucket A - child2.setAttribute(SENSOR, "bucketB"); + child2.sensors().set(SENSOR, "bucketB"); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); @@ -187,7 +187,7 @@ public class DynamicMultiGroupTest { // Add new child 3, associated with new bucket C final TestEntity child3 = group.addChild(EntitySpec.create(childSpec).displayName("child3")); Entities.manage(child3); - child3.setAttribute(SENSOR, "bucketC"); + child3.sensors().set(SENSOR, "bucketC"); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketC = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketC"), null); @@ -198,7 +198,7 @@ public class DynamicMultiGroupTest { // Un-set the sensor on child 3 -- gets removed from bucket C, which then // disappears as it is empty. - child3.setAttribute(SENSOR, null); + child3.sensors().set(SENSOR, null); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); @@ -210,7 +210,7 @@ public class DynamicMultiGroupTest { }); // Add child 3 back to bucket C -- this should result in a new group entity - child3.setAttribute(SENSOR, "bucketC"); + child3.sensors().set(SENSOR, "bucketC"); Asserts.succeedsEventually(new Runnable() { public void run() { Group bucketC = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketC"), null); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java index 2ab2230..68db69a 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java @@ -55,7 +55,7 @@ public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport { super.setUp(); group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); - group.addPolicy(PolicySpec.create(FindUpServicesWithNameBob.class)); + group.policies().add(PolicySpec.create(FindUpServicesWithNameBob.class)); } @Test @@ -67,8 +67,8 @@ public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport { EntityTestUtils.assertAttributeEquals(group, BasicGroup.GROUP_SIZE, 0); - e1.setAttribute(Startable.SERVICE_UP, true); - e1.setAttribute(TestEntity.NAME, "bob"); + e1.sensors().set(Startable.SERVICE_UP, true); + e1.sensors().set(TestEntity.NAME, "bob"); EntityTestUtils.assertAttributeEqualsEventually(group, BasicGroup.GROUP_SIZE, 1); Asserts.assertEqualsIgnoringOrder(group.getAttribute(BasicGroup.GROUP_MEMBERS), ImmutableList.of(e1)); @@ -79,12 +79,12 @@ public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport { Assert.assertEquals(group.getMembers().size(), 1); Assert.assertTrue(group.getMembers().contains(e1)); - e2.setAttribute(Startable.SERVICE_UP, true); - e2.setAttribute(TestEntity.NAME, "fred"); + e2.sensors().set(Startable.SERVICE_UP, true); + e2.sensors().set(TestEntity.NAME, "fred"); EntityTestUtils.assertAttributeEquals(group, BasicGroup.GROUP_SIZE, 1); - e2.setAttribute(TestEntity.NAME, "BOB"); + e2.sensors().set(TestEntity.NAME, "BOB"); EntityTestUtils.assertAttributeEqualsEventually(group, BasicGroup.GROUP_SIZE, 2); Asserts.succeedsEventually(new Runnable() { public void run() { @@ -113,7 +113,7 @@ public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport { public void setEntity(EntityLocal entity) { assert entity instanceof Group; super.setEntity(entity); - subscribe(null, Startable.SERVICE_UP, handler); + subscriptions().subscribe(null, Startable.SERVICE_UP, handler); for (Entity e : ((EntityInternal) entity).getManagementContext().getEntityManager().getEntities()) { if (Objects.equal(e.getApplicationId(), entity.getApplicationId())) updateMembership(e); @@ -143,7 +143,7 @@ public class GroupPickUpEntitiesTest extends BrooklynAppUnitTestSupport { @Override public void setEntity(EntityLocal entity) { super.setEntity(entity); - subscribe(null, TestEntity.NAME, handler); + subscriptions().subscribe(null, TestEntity.NAME, handler); } @Override http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d08310c/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java index cae461f..40c6693 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java @@ -74,10 +74,10 @@ public class GroupTest extends BrooklynAppUnitTestSupport { @Test public void testEntityGetGroups() throws Exception { group.addMember(entity1); - Asserts.assertEqualsIgnoringOrder(entity1.getGroups(), ImmutableSet.of(group)); + Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of(group)); group.removeMember(entity1); - Asserts.assertEqualsIgnoringOrder(entity1.getGroups(), ImmutableSet.of()); + Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of()); } @Test @@ -91,7 +91,7 @@ public class GroupTest extends BrooklynAppUnitTestSupport { public void testUnmanagedGroupAutomaticallyRemovedMembers() throws Exception { group.addMember(entity1); Entities.unmanage(group); - Asserts.assertEqualsIgnoringOrder(entity1.getGroups(), ImmutableSet.of()); + Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of()); } @Test @@ -115,7 +115,7 @@ public class GroupTest extends BrooklynAppUnitTestSupport { mgmt.getSubscriptionManager().subscribe(entity1, AbstractEntity.GROUP_ADDED, groupAddedListener); mgmt.getSubscriptionManager().subscribe(entity1, AbstractEntity.GROUP_REMOVED, groupRemovedListener); - entity1.addGroup(group); + group.addMember(entity1); Asserts.succeedsEventually(new Runnable() { public void run() { String msg = "events="+groupAddedListener.getEvents(); @@ -125,7 +125,7 @@ public class GroupTest extends BrooklynAppUnitTestSupport { }}); assertEquals(groupRemovedListener.getEvents().size(), 0, "events="+groupRemovedListener.getEvents()); - entity1.removeGroup(group); + group.removeMember(entity1); Asserts.succeedsEventually(new Runnable() { public void run() { String msg = "events="+groupRemovedListener.getEvents();
