http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppUnitTestSupport.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppUnitTestSupport.java b/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppUnitTestSupport.java index b9fcd13..fa96e0b 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppUnitTestSupport.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/BrooklynAppUnitTestSupport.java @@ -19,12 +19,12 @@ package org.apache.brooklyn.core.test; import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.core.entity.BrooklynConfigKeys; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/NoopStartable.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/NoopStartable.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/NoopStartable.java index 190ac6b..91bd5c8 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/NoopStartable.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/NoopStartable.java @@ -20,7 +20,7 @@ package org.apache.brooklyn.core.test.entity; import java.util.Collection; -import org.apache.brooklyn.entity.trait.Startable; +import org.apache.brooklyn.core.entity.trait.Startable; public class NoopStartable implements Startable { public void start(Collection loc) {} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplication.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplication.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplication.java index 15dd766..63d9dd5 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplication.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplication.java @@ -25,9 +25,9 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.api.mgmt.ManagementContext; import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.core.StartableApplication; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.StartableApplication; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.location.core.SimulatedLocation; import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; import org.apache.brooklyn.sensor.core.Sensors; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplicationImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplicationImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplicationImpl.java index da8ccc9..2a76f03 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplicationImpl.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestApplicationImpl.java @@ -27,7 +27,7 @@ import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.SubscriptionHandle; import org.apache.brooklyn.api.sensor.Sensor; import org.apache.brooklyn.api.sensor.SensorEventListener; -import org.apache.brooklyn.entity.core.AbstractApplication; +import org.apache.brooklyn.core.entity.AbstractApplication; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.brooklyn.location.core.SimulatedLocation; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java index 8d425c9..0bc9e32 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java @@ -18,9 +18,9 @@ */ package org.apache.brooklyn.core.test.entity; +import org.apache.brooklyn.core.entity.lifecycle.QuorumCheck.QuorumChecks; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.entity.group.DynamicClusterImpl; -import org.apache.brooklyn.entity.lifecycle.QuorumCheck.QuorumChecks; -import org.apache.brooklyn.entity.trait.Startable; /** * Mock cluster entity for testing. http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java index bad7582..2106f18 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java @@ -29,18 +29,18 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.annotation.Effector; +import org.apache.brooklyn.core.annotation.EffectorParam; import org.apache.brooklyn.core.config.BasicConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; import org.apache.brooklyn.core.config.ListConfigKey; import org.apache.brooklyn.core.config.MapConfigKey; import org.apache.brooklyn.core.config.SetConfigKey; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.sensor.core.BasicNotificationSensor; import org.apache.brooklyn.sensor.core.Sensors; import org.apache.brooklyn.util.collections.MutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java index 680069d..786c908 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java @@ -29,9 +29,9 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.util.collections.MutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityTransientCopyImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityTransientCopyImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityTransientCopyImpl.java index 8a1d101..b04c5ae 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityTransientCopyImpl.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityTransientCopyImpl.java @@ -18,7 +18,7 @@ */ package org.apache.brooklyn.core.test.entity; -import org.apache.brooklyn.entity.core.internal.EntityTransientCopyInternal; +import org.apache.brooklyn.core.entity.internal.EntityTransientCopyInternal; /** * Entity to give compilation errors if {@link EntityTransientCopyInternal} methods are not aligned http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java index 3a0ecc1..6c2b334 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/longevity/EntityCleanupLongevityTestFixture.java @@ -26,6 +26,8 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.core.internal.storage.BrooklynStorage; import org.apache.brooklyn.core.internal.storage.DataGrid; import org.apache.brooklyn.core.internal.storage.impl.BrooklynStorageImpl; @@ -35,8 +37,6 @@ import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; import org.apache.brooklyn.util.core.task.BasicExecutionManager; import org.apache.brooklyn.util.core.task.TaskScheduler; import org.apache.brooklyn.util.text.Strings; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/AbstractPerformanceTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/AbstractPerformanceTest.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/AbstractPerformanceTest.java index cbf50f3..8c2b5e2 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/AbstractPerformanceTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/AbstractPerformanceTest.java @@ -23,9 +23,9 @@ import static org.testng.Assert.assertTrue; import java.util.concurrent.TimeUnit; import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; import org.apache.brooklyn.util.internal.DoubleSystemProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPerformanceTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPerformanceTest.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPerformanceTest.java index 7f4d325..aa9f7ff 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPerformanceTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPerformanceTest.java @@ -27,8 +27,8 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.exceptions.Exceptions; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorBasicTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorBasicTest.java b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorBasicTest.java index 227d5a4..98c788f 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorBasicTest.java +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorBasicTest.java @@ -25,12 +25,12 @@ import org.apache.brooklyn.api.entity.EntityLocal; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.mgmt.HasTaskChildren; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.trait.FailingEntity; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.trait.FailingEntity; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.test.TestUtils; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.task.Tasks; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorConcatenateTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorConcatenateTest.java b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorConcatenateTest.java index c33cb18..9372e41 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorConcatenateTest.java +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorConcatenateTest.java @@ -30,14 +30,14 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.mgmt.ExecutionManager; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.annotation.Effector; +import org.apache.brooklyn.core.annotation.EffectorParam; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestApplicationImpl; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.task.BasicExecutionContext; import org.apache.brooklyn.util.core.task.Tasks; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorMetadataTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorMetadataTest.java b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorMetadataTest.java index 9a4c8cc..b8b6bf4 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorMetadataTest.java +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorMetadataTest.java @@ -29,14 +29,14 @@ import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.core.annotation.EffectorParam; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.mgmt.internal.EffectorUtils; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.effector.core.BasicParameterType; import org.apache.brooklyn.effector.core.Effectors; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.trait.Startable; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -120,11 +120,11 @@ public class EffectorMetadataTest extends BrooklynAppUnitTestSupport { public interface MyAnnotatedEntity extends Entity { static MethodEffector<String> EFF_WITH_NEW_ANNOTATION = new MethodEffector<String>(MyAnnotatedEntity.class, "effWithNewAnnotation"); - @org.apache.brooklyn.entity.annotation.Effector(description="my effector description") + @org.apache.brooklyn.core.annotation.Effector(description="my effector description") public String effWithNewAnnotation( @EffectorParam(name="param1", defaultValue="my default val", description="my param description") String param1); - @org.apache.brooklyn.entity.annotation.Effector(description="my effector description") + @org.apache.brooklyn.core.annotation.Effector(description="my effector description") public String effWithAnnotationButNoConstant( @EffectorParam(name="param1", defaultValue="my default val", description="my param description") String param1); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiGroovyTest.groovy ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiGroovyTest.groovy b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiGroovyTest.groovy index d765b0c..ec5c442 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiGroovyTest.groovy +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiGroovyTest.groovy @@ -29,10 +29,10 @@ import org.apache.brooklyn.api.mgmt.Task import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.mgmt.internal.EffectorUtils import org.apache.brooklyn.core.test.entity.TestApplication -import org.apache.brooklyn.entity.annotation.EffectorParam -import org.apache.brooklyn.entity.core.AbstractEntity -import org.apache.brooklyn.entity.core.Entities -import org.apache.brooklyn.entity.trait.Startable +import org.apache.brooklyn.core.annotation.EffectorParam +import org.apache.brooklyn.core.entity.AbstractEntity +import org.apache.brooklyn.core.entity.Entities +import org.apache.brooklyn.core.entity.trait.Startable import org.slf4j.Logger import org.slf4j.LoggerFactory import org.testng.annotations.AfterMethod @@ -137,7 +137,7 @@ public interface CanSayHi { //slightly longer-winded pojo also supported static Effector<String> SAY_HI_1_ALT = new MethodEffector<String>(CanSayHi.class, "sayHi1"); - @org.apache.brooklyn.entity.annotation.Effector(description="says hello") + @org.apache.brooklyn.core.annotation.Effector(description="says hello") public String sayHi1( @EffectorParam(name="name") String name, @EffectorParam(name="greeting", defaultValue="hello", description="what to say") String greeting); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiTest.java b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiTest.java index 448f190..828cbd7 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiTest.java +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorSayHiTest.java @@ -33,13 +33,13 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.api.mgmt.ExecutionContext; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.annotation.EffectorParam; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.task.BasicTask; import org.slf4j.Logger; @@ -133,12 +133,12 @@ public class EffectorSayHiTest extends BrooklynAppUnitTestSupport { static MethodEffector<String> SAY_HI_1 = new MethodEffector<String>(CanSayHi.class, "sayHi1"); static MethodEffector<String> DELEGATE_SAY_HI_1 = new MethodEffector<String>(CanSayHi.class, "delegateSayHi1"); - @org.apache.brooklyn.entity.annotation.Effector(description="says hello") + @org.apache.brooklyn.core.annotation.Effector(description="says hello") public String sayHi1( @EffectorParam(name="name") String name, @EffectorParam(name="greeting", defaultValue="hello", description="what to say") String greeting); - @org.apache.brooklyn.entity.annotation.Effector(description="delegate says hello") + @org.apache.brooklyn.core.annotation.Effector(description="delegate says hello") public String delegateSayHi1( @EffectorParam(name="name") String name, @EffectorParam(name="greeting") String greeting); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/effector/core/EffectorTaskTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorTaskTest.java b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorTaskTest.java index 0d0e4a8..7d8a4f5 100644 --- a/core/src/test/java/org/apache/brooklyn/effector/core/EffectorTaskTest.java +++ b/core/src/test/java/org/apache/brooklyn/effector/core/EffectorTaskTest.java @@ -26,6 +26,10 @@ import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.mgmt.HasTaskChildren; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; @@ -34,10 +38,6 @@ import org.apache.brooklyn.effector.core.EffectorTasks; import org.apache.brooklyn.effector.core.EffectorWithBody; import org.apache.brooklyn.effector.core.Effectors; import org.apache.brooklyn.effector.core.EffectorTasks.EffectorTaskFactory; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.config.ConfigBag; import org.apache.brooklyn.util.core.task.DynamicSequentialTask; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/AbstractApplicationLegacyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/AbstractApplicationLegacyTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/AbstractApplicationLegacyTest.java deleted file mode 100644 index 740b9b2..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/AbstractApplicationLegacyTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.location.LocationSpec; -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.apache.brooklyn.entity.core.AbstractApplication; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import org.apache.brooklyn.location.core.SimulatedLocation; - -/** - * Tests the deprecated use of AbstractAppliation, where its constructor is called directly. - * - * @author aled - */ -public class AbstractApplicationLegacyTest extends BrooklynAppUnitTestSupport { - - private SimulatedLocation loc; - private List<SimulatedLocation> locs; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); - locs = ImmutableList.of(loc); - } - - // App and its children will be implicitly managed on first effector call on app - @Test - public void testStartAndStopUnmanagedAppAutomanagesTheAppAndChildren() throws Exception { - // deliberately unmanaged - TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); - TestEntity child = app2.addChild(EntitySpec.create(TestEntity.class)); - assertFalse(Entities.isManaged(app2)); - assertFalse(Entities.isManaged(child)); - - app2.invoke(AbstractApplication.START, ImmutableMap.of("locations", locs)).get(); - assertTrue(Entities.isManaged(app2)); - assertTrue(Entities.isManaged(child)); - assertEquals(child.getCallHistory(), ImmutableList.of("start")); - assertEquals(mgmt.getEntityManager().getEntity(app2.getId()), app2); - assertEquals(mgmt.getEntityManager().getEntity(child.getId()), child); - - app2.stop(); - assertEquals(child.getCallHistory(), ImmutableList.of("start", "stop")); - assertFalse(Entities.isManaged(child)); - assertFalse(Entities.isManaged(app2)); - } - - @Test - public void testStartAndStopWhenManagedCallsChildren() { - TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - assertTrue(Entities.isManaged(app)); - assertTrue(Entities.isManaged(child)); - - app.start(locs); - assertEquals(child.getCallHistory(), ImmutableList.of("start")); - - app.stop(); - assertEquals(child.getCallHistory(), ImmutableList.of("start", "stop")); - assertFalse(Entities.isManaged(child)); - assertFalse(Entities.isManaged(app)); - } - - @Test - public void testStartOnManagedAppDoesNotStartPremanagedChildren() { - TestEntity child = app.addChild(EntitySpec.create(TestEntity.class)); - - app.start(locs); - assertEquals(child.getCallHistory(), ImmutableList.of()); - } - - @Test - public void testStartOnManagedAppDoesNotStartUnmanagedChildren() { - TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - Entities.unmanage(child); - - app.start(locs); - assertEquals(child.getCallHistory(), ImmutableList.of()); - } - - @Test - public void testStopDoesNotStopUnmanagedChildren() { - TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - - app.start(locs); - assertEquals(child.getCallHistory(), ImmutableList.of("start")); - - Entities.unmanage(child); - - app.stop(); - assertEquals(child.getCallHistory(), ImmutableList.of("start")); - } - - @Test - public void testStopOnManagedAppDoesNotStopPremanagedChildren() { - app.start(locs); - - TestEntity child = app.addChild(EntitySpec.create(TestEntity.class)); - - app.stop(); - assertEquals(child.getCallHistory(), ImmutableList.of()); - } - - @Test - public void testAppUsesDefaultDisplayName() { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class) - .configure(AbstractApplication.DEFAULT_DISPLAY_NAME, "myDefaultName"); - TestApplication app2 = ApplicationBuilder.newManagedApp(appSpec, mgmt); - - assertEquals(app2.getDisplayName(), "myDefaultName"); - } - - @Test - public void testAppUsesDisplayNameOverDefaultName() { - EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class) - .displayName("myName") - .configure(AbstractApplication.DEFAULT_DISPLAY_NAME, "myDefaultName"); - TestApplication app2 = ApplicationBuilder.newManagedApp(appSpec, mgmt); - - assertEquals(app2.getDisplayName(), "myName"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/AbstractEntityLegacyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/AbstractEntityLegacyTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/AbstractEntityLegacyTest.java deleted file mode 100644 index 60da5ad..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/AbstractEntityLegacyTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.List; -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestApplicationImpl; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.util.collections.MutableMap; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -/** - * Tests the deprecated use of AbstractAppliation, where its constructor is called directly. - * - * @author aled - */ -public class AbstractEntityLegacyTest { - - private List<SimulatedLocation> locs; - private TestApplication app; - - @ImplementedBy(MyEntityImpl.class) - public interface MyEntity extends Entity { - int getConfigureCount(); - - int getConfigureDuringConstructionCount(); - } - - public static class MyEntityImpl extends AbstractEntity implements MyEntity { - volatile int configureCount; - volatile int configureDuringConstructionCount; - - public MyEntityImpl() { - super(); - configureDuringConstructionCount = configureCount; - } - - public MyEntityImpl(Entity parent) { - super(parent); - configureDuringConstructionCount = configureCount; - } - - public MyEntityImpl(Map flags, Entity parent) { - super(flags, parent); - configureDuringConstructionCount = configureCount; - } - - @Override - public AbstractEntity configure(Map flags) { - configureCount++; - return super.configure(flags); - } - - @Override - public int getConfigureCount() { - return configureCount; - } - - @Override - public int getConfigureDuringConstructionCount() { - return configureDuringConstructionCount; - } - } - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - @Test - public void testLegacyConstructionCallsConfigureMethod() throws Exception { - MyEntity entity = new MyEntityImpl(); - - assertEquals(entity.getConfigureCount(), 1); - assertEquals(entity.getConfigureDuringConstructionCount(), 1); - } - - @Test - public void testLegacyConstructionSetsDefaultDisplayName() throws Exception { - app = new TestApplicationImpl(); - MyEntity entity = new MyEntityImpl(app); - - assertTrue(entity.getDisplayName().startsWith("MyEntityImpl:"+entity.getId().substring(0,4)), "displayName="+entity.getDisplayName()); - - Entities.startManagement(app, LocalManagementContextForTests.newInstance()); - assertTrue(entity.getDisplayName().startsWith("MyEntity:"+entity.getId().substring(0,4)), "displayName="+entity.getDisplayName()); - } - - @Test - public void testLegacyConstructionUsesCustomDisplayName() throws Exception { - app = new TestApplicationImpl(MutableMap.of("displayName", "appname")); - MyEntity entity = new MyEntityImpl(MutableMap.of("displayName", "entityname"), app); - MyEntity entity2 = new MyEntityImpl(MutableMap.of("name", "entityname2"), app); - - assertEquals(app.getDisplayName(), "appname"); - assertEquals(entity.getDisplayName(), "entityname"); - assertEquals(entity2.getDisplayName(), "entityname2"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/AttributeMapTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/AttributeMapTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/AttributeMapTest.java deleted file mode 100644 index 69077d2..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/AttributeMapTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.apache.brooklyn.api.entity.Application; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestEntityImpl; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.sensor.core.AttributeMap; -import org.apache.brooklyn.sensor.core.Sensors; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.guava.Maybe; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class AttributeMapTest { - final int NUM_TASKS = Math.min(500 * Runtime.getRuntime().availableProcessors(), 1000); - - Application app; - TestEntityImpl entity; - AttributeMap map; - ExecutorService executor; - - @BeforeMethod(alwaysRun=true) - public void setUp() { - app = TestApplication.Factory.newManagedInstanceForTests(); - entity = new TestEntityImpl(app); - map = new AttributeMap(entity, Collections.synchronizedMap(MutableMap.<Collection<String>,Object>of())); - Entities.manage(entity); - executor = Executors.newCachedThreadPool(); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() { - if (executor != null) executor.shutdownNow(); - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - // See ENGR-2111 - @Test - public void testConcurrentUpdatesDoNotCauseConcurrentModificationException() throws Exception { - List<Future<?>> futures = Lists.newArrayList(); - - for (int i = 0; i < NUM_TASKS; i++) { - final AttributeSensor<String> nextSensor = Sensors.newStringSensor("attributeMapTest.exampleSensor"+i, ""); - Future<?> future = executor.submit(newUpdateMapRunnable(map, nextSensor, "a")); - futures.add(future); - } - - for (Future<?> future : futures) { - future.get(); - } - } - - @Test - public void testConcurrentUpdatesAndGetsDoNotCauseConcurrentModificationException() throws Exception { - List<Future<?>> futures = Lists.newArrayList(); - - for (int i = 0; i < NUM_TASKS; i++) { - final AttributeSensor<String> nextSensor = Sensors.newStringSensor("attributeMapTest.exampleSensor"+i, ""); - Future<?> future = executor.submit(newUpdateMapRunnable(map, nextSensor, "a")); - Future<?> future2 = executor.submit(newGetAttributeCallable(map, nextSensor)); - futures.add(future); - futures.add(future2); - } - - for (Future<?> future : futures) { - future.get(); - } - } - - @Test - public void testStoredSensorsCanBeRetrieved() throws Exception { - AttributeSensor<String> sensor1 = Sensors.newStringSensor("a", ""); - AttributeSensor<String> sensor2 = Sensors.newStringSensor("b.c", ""); - - map.update(sensor1, "1val"); - map.update(sensor2, "2val"); - - assertEquals(map.getValue(sensor1), "1val"); - assertEquals(map.getValue(sensor2), "2val"); - - assertEquals(map.getValue(ImmutableList.of("a")), "1val"); - assertEquals(map.getValue(ImmutableList.of("b","c")), "2val"); - } - - @Test - public void testStoredByPathCanBeRetrieved() throws Exception { - AttributeSensor<String> sensor1 = Sensors.newStringSensor("a", ""); - AttributeSensor<String> sensor2 = Sensors.newStringSensor("b.c", ""); - - map.update(ImmutableList.of("a"), "1val"); - map.update(ImmutableList.of("b", "c"), "2val"); - - assertEquals(map.getValue(sensor1), "1val"); - assertEquals(map.getValue(sensor2), "2val"); - - assertEquals(map.getValue(ImmutableList.of("a")), "1val"); - assertEquals(map.getValue(ImmutableList.of("b","c")), "2val"); - } - - @Test - public void testCanStoreSensorThenChildSensor() throws Exception { - AttributeSensor<String> sensor = Sensors.newStringSensor("a", ""); - AttributeSensor<String> childSensor = Sensors.newStringSensor("a.b", ""); - - map.update(sensor, "parentValue"); - map.update(childSensor, "childValue"); - - assertEquals(map.getValue(childSensor), "childValue"); - assertEquals(map.getValue(sensor), "parentValue"); - } - - @Test - public void testCanStoreChildThenParentSensor() throws Exception { - AttributeSensor<String> sensor = Sensors.newStringSensor("a", ""); - AttributeSensor<String> childSensor = Sensors.newStringSensor("a.b", ""); - - map.update(childSensor, "childValue"); - map.update(sensor, "parentValue"); - - assertEquals(map.getValue(childSensor), "childValue"); - assertEquals(map.getValue(sensor), "parentValue"); - } - - @Test - public void testConcurrentModifyAttributeCalls() throws Exception { - AttributeSensor<Integer> sensor = Sensors.newIntegerSensor("a", ""); - - Function<Integer, Maybe<Integer>> modifier = new Function<Integer, Maybe<Integer>>() { - @Override public Maybe<Integer> apply(Integer input) { - return Maybe.of((input == null) ? 1 : input + 1); - } - }; - - List<Future<?>> futures = Lists.newArrayList(); - - for (int i = 0; i < NUM_TASKS; i++) { - Future<?> future = executor.submit(newModifyAttributeCallable(map, sensor, modifier)); - futures.add(future); - } - - for (Future<?> future : futures) { - future.get(); - } - - assertEquals(map.getValue(sensor), Integer.valueOf(NUM_TASKS)); - } - - @Test - public void testModifyAttributeReturningAbsentDoesNotEmit() throws Exception { - AttributeSensor<Integer> sensor = Sensors.newIntegerSensor("a", ""); - AttributeSensor<Integer> childSensor = Sensors.newIntegerSensor("a.b", ""); - - final RecordingSensorEventListener<Object> listener = new RecordingSensorEventListener<>(); - entity.subscribe(entity, sensor, listener); - - map.modify(childSensor, Functions.constant(Maybe.<Integer>absent())); - - Asserts.succeedsContinually(new Runnable() { - @Override public void run() { - assertTrue(Iterables.isEmpty(listener.getEvents()), "events="+listener.getEvents()); - }}); - } - - protected <T> Runnable newUpdateMapRunnable(final AttributeMap map, final AttributeSensor<T> attribute, final T val) { - return new Runnable() { - @Override public void run() { - map.update(attribute, val); - } - }; - } - - protected <T> Callable<T> newGetAttributeCallable(final AttributeMap map, final AttributeSensor<T> attribute) { - return new Callable<T>() { - @Override public T call() { - return map.getValue(attribute); - } - }; - } - - protected <T> Callable<T> newModifyAttributeCallable(final AttributeMap map, final AttributeSensor<T> attribute, final Function<? super T, Maybe<T>> modifier) { - return new Callable<T>() { - @Override public T call() { - return map.modify(attribute, modifier); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/AttributeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/AttributeTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/AttributeTest.java deleted file mode 100644 index 225f40d..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/AttributeTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.core.test.entity.TestEntityImpl; -import org.apache.brooklyn.sensor.core.BasicAttributeSensor; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class AttributeTest { - static AttributeSensor<String> COLOR = new BasicAttributeSensor<String>(String.class, "my.color"); - - TestEntityImpl e; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - e = new TestEntityImpl(); - } - - @AfterMethod(alwaysRun = true) - public void tearDown(){ - // nothing to tear down; entity was not managed (i.e. had no management context) - } - - @Test - public void canGetAndSetAttribute() { - e.setAttribute(COLOR, "red"); - assertEquals(e.getAttribute(COLOR), "red"); - } - - @Test - public void missingAttributeIsNull() { - assertEquals(e.getAttribute(COLOR), null); - } - - @Test - public void canGetAttributeByNameParts() { - // Initially null - assertNull(e.getAttributeByNameParts(COLOR.getNameParts())); - - // Once set, returns val - e.setAttribute(COLOR, "red"); - assertEquals(e.getAttributeByNameParts(COLOR.getNameParts()), "red"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/ConfigEntityInheritanceTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/ConfigEntityInheritanceTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/ConfigEntityInheritanceTest.java deleted file mode 100644 index 5ea366b..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/ConfigEntityInheritanceTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.config.ConfigInheritance; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.entity.core.internal.ConfigMapTest.MyOtherEntity; -import org.apache.brooklyn.sensor.core.AttributeSensorAndConfigKey; -import org.apache.brooklyn.sensor.core.BasicAttributeSensorAndConfigKey.IntegerAttributeSensorAndConfigKey; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * There is a bug where: - * class XI extends SI implements X - * class SI implements S - * interface X extends Y - * config C is declared on S and overwritten at Y - */ -public class ConfigEntityInheritanceTest { - - private TestApplication app; - - @BeforeMethod(alwaysRun=true) - public void setUp() { - app = TestApplication.Factory.newManagedInstanceForTests(); - Entities.startManagement(app); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - protected void checkKeys(Entity entity2, Integer value) { - Assert.assertEquals(entity2.getConfig(MyOtherEntity.INT_KEY), value); - Assert.assertEquals(entity2.getConfig(MyOtherEntity.SENSOR_AND_CONFIG_KEY), value); - } - - @Test - public void testConfigKeysIncludesHasConfigKeys() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MyOtherEntity.class)), 1); - } - - @Test - public void testConfigKeysIncludesHasConfigKeysInheritsOverwritten() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MyOtherEntityOverwriting.class)), 2); - } - @Test - public void testConfigKeysIncludesHasConfigKeysInheritsOverwrittenThenInherited() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MyOtherEntityOverwritingThenInheriting.class)), 2); - } - - public static class MyOtherEntityOverwriting extends MyOtherEntity { - public static final ConfigKey<Integer> INT_KEY = ConfigKeys.newConfigKeyWithDefault(MyOtherEntity.INT_KEY, 2); - public static final IntegerAttributeSensorAndConfigKey SENSOR_AND_CONFIG_KEY = - new IntegerAttributeSensorAndConfigKey(MyOtherEntity.SENSOR_AND_CONFIG_KEY, 2); - } - public static class MyOtherEntityOverwritingThenInheriting extends MyOtherEntityOverwriting { - } - - // -------------------- - - @Test - public void testConfigKeysHere() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MyEntityHere.class)), 3); - } - @Test - public void testConfigKeysSub() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MySubEntityHere.class)), 4); - } - @Test - public void testConfigKeysSubExtended() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MySubEntityHere.class)), 4); - } - @Test - public void testConfigKeysSubInheriting() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MySubEntityHereInheriting.class)), 4); - } - @Test - public void testConfigKeysHereSubRight() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MySubEntityHereLeft.class)), 4); - } - @Test - public void testConfigKeysSubLeft() throws Exception { - checkKeys(app.addChild(EntitySpec.create(MySubEntityHereRight.class)), 4); - } - @Test - public void testConfigKeysExtAndImplIntTwoRight() throws Exception { - // this mirrors the bug observed in kafka entities; - // the right-side interface normally dominates, but not when it is transitive - // (although we shouldn't rely on order in any case; - // new routines check whether one config key extends another and if so it takes the extending one) - checkKeys(app.addChild(EntitySpec.create(MyEntityHereExtendingAndImplementingInterfaceImplementingTwoRight.class)), 4); - } - - public interface MyInterfaceDeclaring { - public static final ConfigKey<Integer> INT_KEY = - ConfigKeys.newIntegerConfigKey("intKey", "int key", 3); - public static final AttributeSensorAndConfigKey<Integer,Integer> SENSOR_AND_CONFIG_KEY = - new IntegerAttributeSensorAndConfigKey("sensorConfigKey", "sensor+config key", 3); - } - public interface MyInterfaceRedeclaringAndInheriting extends MyInterfaceDeclaring { - public static final ConfigKey<Integer> INT_KEY = ConfigKeys.newConfigKeyWithDefault(MyInterfaceDeclaring.INT_KEY, 4); - public static final IntegerAttributeSensorAndConfigKey SENSOR_AND_CONFIG_KEY = - new IntegerAttributeSensorAndConfigKey(MyInterfaceDeclaring.SENSOR_AND_CONFIG_KEY, 4); - } - - public interface MyInterfaceRedeclaring { - public static final ConfigKey<Integer> INT_KEY = ConfigKeys.newConfigKeyWithDefault(MyInterfaceDeclaring.INT_KEY, 4); - public static final IntegerAttributeSensorAndConfigKey SENSOR_AND_CONFIG_KEY = - new IntegerAttributeSensorAndConfigKey(MyInterfaceDeclaring.SENSOR_AND_CONFIG_KEY, 4); - } - - public interface MyInterfaceRedeclaringThenExtending extends MyInterfaceRedeclaring { - } - - public interface MyInterfaceExtendingLeft extends MyInterfaceRedeclaring, MyInterfaceDeclaring { - } - - public interface MyInterfaceExtendingRight extends MyInterfaceDeclaring, MyInterfaceRedeclaring { - } - - public static class MyEntityHere extends AbstractEntity implements MyInterfaceDeclaring { - } - - public static class MySubEntityHere extends MyEntityHere implements MyInterfaceRedeclaring { - } - - public static class MySubEntityHereInheriting extends MyEntityHere implements MyInterfaceRedeclaringAndInheriting { - } - - public static class MySubEntityHereExtended extends MyEntityHere implements MyInterfaceRedeclaringThenExtending { - } - - public static class MySubEntityHereLeft extends MyEntityHere implements MyInterfaceRedeclaring, MyInterfaceDeclaring { - } - - public static class MySubEntityHereRight extends MyEntityHere implements MyInterfaceDeclaring, MyInterfaceRedeclaring { - } - - public static class MyEntityHereExtendingAndImplementingInterfaceImplementingTwoRight extends MyEntityHere implements MyInterfaceExtendingRight { - } - - // -------------------- - - @Test - public void testConfigKeysInheritance() throws Exception { - app.setConfig(MyEntityWithPartiallyHeritableConfig.HERITABLE, "heritable"); - app.setConfig(MyEntityWithPartiallyHeritableConfig.UNINHERITABLE, "uninheritable"); - app.setConfig(MyEntityWithPartiallyHeritableConfig.ALWAYS_HERITABLE, "always_heritable"); - Entity child = app.addChild(EntitySpec.create(MyEntityWithPartiallyHeritableConfig.class)); - - Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.HERITABLE)); - Assert.assertNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.UNINHERITABLE), null); - Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.ALWAYS_HERITABLE)); - } - - public static class MyEntityWithPartiallyHeritableConfig extends AbstractEntity { - public static final ConfigKey<String> HERITABLE = ConfigKeys.builder(String.class, "herit.default").build(); - public static final ConfigKey<String> UNINHERITABLE = ConfigKeys.builder(String.class, "herit.none").inheritance(ConfigInheritance.NONE).build(); - // i find a strange joy in words where the prefix "in-" does not mean not, like inflammable - public static final ConfigKey<String> ALWAYS_HERITABLE = ConfigKeys.builder(String.class, "herit.always").inheritance(ConfigInheritance.ALWAYS).build(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/DependentConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/DependentConfigurationTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/DependentConfigurationTest.java deleted file mode 100644 index 23c6d3a..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/DependentConfigurationTest.java +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.sensor.core.DependentConfiguration; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.test.EntityTestUtils; -import org.apache.brooklyn.util.collections.MutableList; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.task.BasicTask; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.javalang.JavaClassNames; -import org.apache.brooklyn.util.text.StringPredicates; -import org.apache.brooklyn.util.time.Duration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.base.Joiner; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.Callables; - -/** Tests the standalone routines in dependent configuration. - * See e.g. LocalEntitiesTest for tests of attributeWhenReady etc. - */ -public class DependentConfigurationTest extends BrooklynAppUnitTestSupport { - - private static final Logger log = LoggerFactory.getLogger(DependentConfigurationTest.class); - - public static final int SHORT_WAIT_MS = 100; - public static final int TIMEOUT_MS = 30*1000; - - private TestEntity entity; - private TestEntity entity2; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - } - - @Test - public void testTransform() throws Exception { - Task<Integer> t = DependentConfiguration.transform( - new BasicTask<Integer>(Callables.returning(2)), - incrementerFunction()); - submit(t); - assertEquals(t.get(TIMEOUT_MS, TimeUnit.MILLISECONDS), Integer.valueOf(3)); - } - - private Function<Integer, Integer> incrementerFunction() { - return new Function<Integer, Integer>() { - @Override public Integer apply(Integer val) { - return val + 1; - }}; - } - - @Test - public void testFormatString() throws Exception { - Task<String> t = DependentConfiguration.formatString("%s://%s:%d/", - "http", - new BasicTask<String>(Callables.returning("localhost")), - DependentConfiguration.transform(new BasicTask<Integer>(Callables.returning(8080)), incrementerFunction())); - submit(t); - Assert.assertEquals(t.get(TIMEOUT_MS, TimeUnit.MILLISECONDS), "http://localhost:8081/"); - } - - @Test - public void testAttributeWhenReady() throws Exception { - final Task<String> t = submit(DependentConfiguration.attributeWhenReady(entity, TestEntity.NAME)); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.NAME, "myval"); - assertEquals(assertDoneEventually(t), "myval"); - } - - @Test - public void testAttributeWhenReadyWithPredicate() throws Exception { - final Task<String> t = submit(DependentConfiguration.attributeWhenReady(entity, TestEntity.NAME, Predicates.equalTo("myval2"))); - - entity.setAttribute(TestEntity.NAME, "myval"); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.NAME, "myval2"); - assertEquals(assertDoneEventually(t), "myval2"); - } - - @Test - public void testAttributeWhenReadyWithPostProcessing() throws Exception { - final Task<String> t = submit(DependentConfiguration.valueWhenAttributeReady(entity, TestEntity.SEQUENCE, Functions.toStringFunction())); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.SEQUENCE, 1); - assertEquals(assertDoneEventually(t), "1"); - } - - @Test - public void testAttributeWhenReadyWithPostProcessingWithBuilder() throws Exception { - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.SEQUENCE) - .postProcess(Functions.toStringFunction()) - .build()); - - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.SEQUENCE, 1); - assertEquals(assertDoneEventually(t), "1"); - } - - @Test - public void testAttributeWhenReadyWithPostProcessingWithBuilderWaitingNow() throws Exception { - final Task<String> t = submit(new Callable<String>() { - public String call() { - return DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.SEQUENCE) - .postProcess(Functions.toStringFunction()) - .runNow(); - }}); - - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.SEQUENCE, 1); - assertEquals(assertDoneEventually(t), "1"); - } - - @Test - public void testAttributeWhenReadyWithAbortHappyPath() throws Exception { - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1)) - .build()); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.NAME, "myval"); - assertEquals(assertDoneEventually(t), "myval"); - } - - @Test - public void testAttributeWhenReadyWithAbort() throws Exception { - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1)) - .build()); - - assertNotDoneContinually(t); - - entity2.setAttribute(TestEntity.SEQUENCE, 321); - assertNotDoneContinually(t); - - entity2.setAttribute(TestEntity.SEQUENCE, 1); - try { - assertDoneEventually(t); - fail(); - } catch (Exception e) { - if (!e.toString().contains("Aborted waiting for ready")) throw e; - } - } - - @Test - public void testAttributeWhenReadyWithAbortWaitingNow() throws Exception { - final Task<String> t = submit(new Callable<String>() { - public String call() { - return DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1)) - .runNow(); - }}); - - assertNotDoneContinually(t); - - entity2.setAttribute(TestEntity.SEQUENCE, 321); - assertNotDoneContinually(t); - - entity2.setAttribute(TestEntity.SEQUENCE, 1); - try { - assertDoneEventually(t); - fail(); - } catch (Exception e) { - if (!e.toString().contains("Aborted waiting for ready")) throw e; - } - } - - @Test - public void testAttributeWhenReadyWithAbortFailsWhenAbortConditionAlreadyHolds() throws Exception { - entity2.setAttribute(TestEntity.SEQUENCE, 1); - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1)) - .build()); - try { - assertDoneEventually(t); - fail(); - } catch (Exception e) { - if (!e.toString().contains("Aborted waiting for ready")) throw e; - } - } - - @Test - public void testAttributeWhenReadyWithAbortFailsWhenAbortConditionAlreadyHoldsWaitingNow() throws Exception { - entity2.setAttribute(TestEntity.SEQUENCE, 1); - final Task<String> t = submit(new Callable<String>() { - public String call() { - return DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1)) - .runNow(); - }}); - try { - assertDoneEventually(t); - fail(); - } catch (Exception e) { - if (!e.toString().contains("Aborted waiting for ready")) throw e; - } - } - - @Test - public void testAttributeWhenReadyRunNowWithoutPostProcess() throws Exception { - Task<String> t = submit(new Callable<String>() { - @Override - public String call() throws Exception { - return DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .runNow(); - } - }); - entity.setAttribute(TestEntity.NAME, "myentity"); - assertDoneEventually(t); - assertEquals(t.get(), "myentity"); - } - - @Test - public void testAttributeWhenReadyAbortsWhenOnFireByDefault() { - log.info("starting test "+JavaClassNames.niceClassAndMethod()); - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .build()); - - ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE); - EntityTestUtils.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); - - try { - assertDoneEventually(t); - fail("Should have failed already!"); - } catch (Throwable e) { - if (e.toString().contains("Aborted waiting for ready")) - return; - - log.warn("Did not abort as expected: "+e, e); - Entities.dumpInfo(entity); - - throw Exceptions.propagate(e); - } - } - - @Test(invocationCount=100, groups = "Integration") - public void testAttributeWhenReadyAbortsWhenOnfireByDefaultManyTimes() { - testAttributeWhenReadyAbortsWhenOnFireByDefault(); - } - - @Test - public void testAttributeWhenReadyAbortsWhenAlreadyOnFireByDefault() throws Exception { - ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE); - EntityTestUtils.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); - - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReady(entity, TestEntity.NAME) - .build()); - - try { - assertDoneEventually(t); - fail(); - } catch (Exception e) { - if (!e.toString().contains("Aborted waiting for ready")) throw e; - } - } - - @Test - public void testListAttributeWhenReadyFromMultipleEntities() throws Exception { - final Task<List<String>> t = submit(DependentConfiguration.builder() - .attributeWhenReadyFromMultiple(ImmutableList.of(entity, entity2), TestEntity.NAME) - .build()); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.NAME, "myval"); - assertNotDoneContinually(t); - - entity2.setAttribute(TestEntity.NAME, "myval2"); - assertEquals(ImmutableSet.copyOf(assertDoneEventually(t)), ImmutableSet.of("myval", "myval2")); - } - - @Test - public void testListAttributeWhenReadyFromMultipleEntitiesWithLocalReadinessPredicate() throws Exception { - final Task<List<String>> t = submit(DependentConfiguration.builder() - .attributeWhenReadyFromMultiple(ImmutableList.of(entity, entity2), TestEntity.NAME, StringPredicates.startsWith("myval")) - .build()); - - entity.setAttribute(TestEntity.NAME, "wrongval"); - entity2.setAttribute(TestEntity.NAME, "wrongval2"); - assertNotDoneContinually(t); - - entity.setAttribute(TestEntity.NAME, "myval"); - assertNotDoneContinually(t); - entity2.setAttribute(TestEntity.NAME, "myval2"); - assertEquals(ImmutableSet.copyOf(assertDoneEventually(t)), ImmutableSet.of("myval", "myval2")); - } - - @Test - public void testListAttributeWhenReadyFromMultipleEntitiesWithGlobalPostProcessor() throws Exception { - final Task<String> t = submit(DependentConfiguration.builder() - .attributeWhenReadyFromMultiple(ImmutableList.of(entity, entity2), TestEntity.SEQUENCE) - .postProcessFromMultiple(new Function<List<Integer>, String>() { - @Override public String apply(List<Integer> input) { - if (input == null) { - return null; - } else { - MutableList<Integer> inputCopy = MutableList.copyOf(input); - Collections.sort(inputCopy); - return Joiner.on(",").join(inputCopy); - } - }}) - .build()); - - entity.setAttribute(TestEntity.SEQUENCE, 1); - entity2.setAttribute(TestEntity.SEQUENCE, 2); - assertEquals(assertDoneEventually(t), "1,2"); - } - - private void assertNotDoneContinually(final Task<?> t) { - Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), new Callable<Void>() { - @Override public Void call() throws Exception { - if (t.isDone()) { - fail("task unexpectedly done: t="+t+"; result="+t.get()); - } - return null; - } - }); - } - - private <T> T assertDoneEventually(final Task<T> t) throws Exception { - final AtomicReference<ExecutionException> exception = new AtomicReference<ExecutionException>(); - T result = Asserts.succeedsEventually(MutableMap.of("timeout", Duration.FIVE_SECONDS), new Callable<T>() { - @Override public T call() throws InterruptedException, TimeoutException { - try { - return t.get(Duration.ONE_SECOND); - } catch (ExecutionException e) { - exception.set(e); - return null; - } catch (InterruptedException e) { - throw e; - } catch (TimeoutException e) { - throw e; - } - } - }); - if (exception.get() != null) { - throw exception.get(); - } - return result; - } - - - private <T> Task<T> submit(Task<T> task) { - return app.getExecutionContext().submit(task); - } - - private <T> Task<T> submit(Callable<T> job) { - return app.getExecutionContext().submit(new BasicTask<T>(job)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/DynamicEntityTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/DynamicEntityTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/DynamicEntityTest.java deleted file mode 100644 index 2bb3de8..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/DynamicEntityTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -import org.apache.brooklyn.api.entity.EntityInitializer; -import org.apache.brooklyn.api.entity.EntityLocal; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.effector.core.EffectorTaskTest; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.stock.BasicEntity; -import org.apache.brooklyn.util.collections.MutableMap; -import org.testng.annotations.Test; - -public class DynamicEntityTest extends BrooklynAppUnitTestSupport { - - @Test - public void testEffectorAddedDuringInit() { - BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class) - .addInitializer(new EntityInitializer() { - public void apply(EntityLocal entity) { - ((EntityInternal) entity).getMutableEntityType().addEffector(EffectorTaskTest.DOUBLE_1); - } - })); - assertEquals(entity.invoke(EffectorTaskTest.DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 5)).getUnchecked(), (Integer) 10); - } - - @Test - public void testEffectorRemovedDuringInit() { - TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) - .addInitializer(new EntityInitializer() { - @Override - public void apply(EntityLocal entity) { - ((EntityInternal) entity).getMutableEntityType().removeEffector(TestEntity.IDENTITY_EFFECTOR); - } - })); - assertFalse(entity.getMutableEntityType().getEffectors().containsKey(TestEntity.IDENTITY_EFFECTOR.getName())); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/core/EntitiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/core/EntitiesTest.java b/core/src/test/java/org/apache/brooklyn/entity/core/EntitiesTest.java deleted file mode 100644 index e413077..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/core/EntitiesTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.core; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.location.LocationSpec; -import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityAndAttribute; -import org.apache.brooklyn.entity.core.EntityInitializers; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.util.collections.MutableSet; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -public class EntitiesTest extends BrooklynAppUnitTestSupport { - - private static final int TIMEOUT_MS = 10*1000; - - private SimulatedLocation loc; - private TestEntity entity; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - loc = app.getManagementContext().getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - app.start(ImmutableList.of(loc)); - } - - @Test - public void testDescendants() throws Exception { - Assert.assertEquals(Iterables.size(Entities.descendants(app)), 2); - Assert.assertEquals(Iterables.getOnlyElement(Entities.descendants(app, TestEntity.class)), entity); - } - - @Test - public void testAttributeSupplier() throws Exception { - entity.setAttribute(TestEntity.NAME, "myname"); - assertEquals(Entities.attributeSupplier(entity, TestEntity.NAME).get(), "myname"); - } - - @Test - public void testAttributeSupplierUsingTuple() throws Exception { - entity.setAttribute(TestEntity.NAME, "myname"); - assertEquals(Entities.attributeSupplier(EntityAndAttribute.supplier(entity, TestEntity.NAME)).get(), "myname"); - } - - @Test(groups="Integration") // takes 1 second - public void testAttributeSupplierWhenReady() throws Exception { - final AtomicReference<String> result = new AtomicReference<String>(); - - final Thread t = new Thread(new Runnable() { - @Override public void run() { - result.set(Entities.attributeSupplierWhenReady(entity, TestEntity.NAME).get()); - - }}); - try { - t.start(); - - // should block, waiting for value - Asserts.succeedsContinually(new Runnable() { - @Override public void run() { - assertTrue(t.isAlive()); - } - }); - - entity.setAttribute(TestEntity.NAME, "myname"); - t.join(TIMEOUT_MS); - assertFalse(t.isAlive()); - assertEquals(result.get(), "myname"); - } finally { - t.interrupt(); - } - - // And now that it's set, the attribute-when-ready should return immediately - assertEquals(Entities.attributeSupplierWhenReady(entity, TestEntity.NAME).get(), "myname"); - } - - @Test - public void testCreateGetContainsAndRemoveTags() throws Exception { - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) - .tag(2) - .addInitializer(EntityInitializers.addingTags("foo"))); - - entity.tags().addTag(app); - - Assert.assertTrue(entity.tags().containsTag(app)); - Assert.assertTrue(entity.tags().containsTag("foo")); - Assert.assertTrue(entity.tags().containsTag(2)); - Assert.assertFalse(entity.tags().containsTag("bar")); - - Assert.assertEquals(entity.tags().getTags(), MutableSet.of(app, "foo", 2)); - - entity.tags().removeTag("foo"); - Assert.assertFalse(entity.tags().containsTag("foo")); - - Assert.assertTrue(entity.tags().containsTag(entity.getParent())); - Assert.assertFalse(entity.tags().containsTag(entity)); - - entity.tags().removeTag(2); - Assert.assertEquals(entity.tags().getTags(), MutableSet.of(app)); - } - -}
