You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/05/17 13:43:27 UTC
[2/5] brooklyn-server git commit: Delete entity constructors
Delete entity constructors
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/2a394007
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/2a394007
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/2a394007
Branch: refs/heads/master
Commit: 2a39400761afe1654201cb1e039cb3145e2df20e
Parents: 15447e1
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 10 14:43:07 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 12 13:27:37 2017 +0100
----------------------------------------------------------------------
.../entity/group/AbstractGroupImpl.java | 9 -
.../brooklyn/entity/group/DynamicGroupImpl.java | 8 -
.../core/effector/EffectorConcatenateTest.java | 106 +++++----
.../core/entity/EntitySetFromFlagTest.java | 81 +++----
.../brooklyn/core/entity/EntityTypeTest.java | 46 ++--
.../entity/OwnedChildrenDeprecatedTest.java | 215 +++++++++++++++++++
.../brooklyn/core/entity/OwnedChildrenTest.java | 160 ++++----------
.../core/test/entity/TestEntityImpl.java | 3 -
.../autoscaling/AutoScalerPolicyTest.java | 41 ++--
.../autoscaling/LocallyResizableEntity.java | 49 +----
.../autoscaling/LocallyResizableEntityImpl.java | 76 +++++++
.../policy/enricher/DeltaEnrichersTests.java | 59 +++--
.../enricher/RollingMeanEnricherTest.java | 29 +--
.../RollingTimeWindowMeanEnricherTest.java | 30 +--
.../testing/mocks/RestMockSimpleEntity.java | 19 --
.../entity/brooklynnode/BrooklynNodeImpl.java | 8 -
.../entity/java/VanillaJavaAppImpl.java | 14 +-
.../software/base/SoftwareProcessImpl.java | 13 --
.../base/SoftwareProcessEntityTest.java | 42 ++--
.../base/lifecycle/StartStopSshDriverTest.java | 26 ++-
.../apache/brooklyn/feed/jmx/JmxFeedTest.java | 47 ++--
21 files changed, 598 insertions(+), 483 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java
index a4bbf62..f1c1a6f 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java
@@ -21,7 +21,6 @@ package org.apache.brooklyn.entity.group;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.apache.brooklyn.api.entity.Entity;
@@ -63,14 +62,6 @@ public abstract class AbstractGroupImpl extends AbstractEntity implements Abstra
private Set<Entity> members = Sets.newLinkedHashSet();
- public AbstractGroupImpl() {
- }
-
- @Deprecated
- public AbstractGroupImpl(@SuppressWarnings("rawtypes") Map flags, Entity parent) {
- super(flags, parent);
- }
-
@Override
public void setManagementContext(ManagementContextInternal managementContext) {
super.setManagementContext(managementContext);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
index 7572430..0815d93 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
@@ -19,7 +19,6 @@
package org.apache.brooklyn.entity.group;
import java.util.Collection;
-import java.util.Map;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.mgmt.Task;
@@ -53,13 +52,6 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
private volatile MyEntitySetChangeListener setChangeListener = null;
- public DynamicGroupImpl() { }
-
- @Deprecated
- public DynamicGroupImpl(@SuppressWarnings("rawtypes") Map flags, Entity parent) {
- super(flags, parent);
- }
-
@Override
public void init() {
super.init();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/test/java/org/apache/brooklyn/core/effector/EffectorConcatenateTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/effector/EffectorConcatenateTest.java b/core/src/test/java/org/apache/brooklyn/core/effector/EffectorConcatenateTest.java
index 93692c6..a80839f 100644
--- a/core/src/test/java/org/apache/brooklyn/core/effector/EffectorConcatenateTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/effector/EffectorConcatenateTest.java
@@ -28,22 +28,21 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
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.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.effector.MethodEffector;
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.mgmt.BrooklynTaskTags;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestApplicationImpl;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.task.BasicExecutionContext;
import org.apache.brooklyn.util.core.task.Tasks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -51,25 +50,37 @@ import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
-public class EffectorConcatenateTest {
-
+public class EffectorConcatenateTest extends BrooklynAppUnitTestSupport {
private static final Logger log = LoggerFactory.getLogger(EffectorConcatenateTest.class);
private static final long TIMEOUT = 10*1000;
-
- public static class MyEntityImpl extends AbstractEntity {
+ @ImplementedBy(MyEntityImpl.class)
+ public static interface MyEntity extends Entity, EntityInternal {
public static MethodEffector<String> CONCATENATE = new MethodEffector<String>(MyEntityImpl.class, "concatenate");
public static MethodEffector<Void> WAIT_A_BIT = new MethodEffector<Void>(MyEntityImpl.class, "waitabit");
public static MethodEffector<Void> SPAWN_CHILD = new MethodEffector<Void>(MyEntityImpl.class, "spawnchild");
-
- public MyEntityImpl() {
- super();
- }
- public MyEntityImpl(Entity parent) {
- super(parent);
- }
-
+
+ @Effector(description="sample effector concatenating strings")
+ String concatenate(@EffectorParam(name="first", description="first argument") String first,
+ @EffectorParam(name="second", description="2nd arg") String second) throws Exception;
+
+ @Effector(description="sample effector doing some waiting")
+ void waitabit() throws Exception;
+
+ @Effector(description="sample effector that spawns a child task that waits a bit")
+ void spawnchild() throws Exception;
+
+ AtomicReference<Task<?>> getWaitingTask();
+
+ /** latch is .countDown'ed by the effector at the beginning of the "waiting" point */
+ CountDownLatch getNowWaitingLatch();
+
+ /** latch is await'ed on by the effector when it is in the "waiting" point */
+ CountDownLatch getContinueFromWaitingLatch();
+ }
+
+ public static class MyEntityImpl extends AbstractEntity implements MyEntity {
/** The "current task" representing the effector currently executing */
AtomicReference<Task<?>> waitingTask = new AtomicReference<Task<?>>();
@@ -78,14 +89,28 @@ public class EffectorConcatenateTest {
/** latch is await'ed on by the effector when it is in the "waiting" point */
CountDownLatch continueFromWaitingLatch = new CountDownLatch(1);
+
+ @Override
+ public AtomicReference<Task<?>> getWaitingTask() {
+ return waitingTask;
+ }
+
+ @Override
+ public CountDownLatch getNowWaitingLatch() {
+ return nowWaitingLatch;
+ }
- @Effector(description="sample effector concatenating strings")
- public String concatenate(@EffectorParam(name="first", description="first argument") String first,
- @EffectorParam(name="second", description="2nd arg") String second) throws Exception {
+ @Override
+ public CountDownLatch getContinueFromWaitingLatch() {
+ return continueFromWaitingLatch;
+ }
+
+ @Override
+ public String concatenate(String first, String second) throws Exception {
return first+second;
}
- @Effector(description="sample effector doing some waiting")
+ @Override
public void waitabit() throws Exception {
waitingTask.set(Tasks.current());
@@ -102,7 +127,7 @@ public class EffectorConcatenateTest {
}});
}
- @Effector(description="sample effector that spawns a child task that waits a bit")
+ @Override
public void spawnchild() throws Exception {
// spawn a child, then wait
BasicExecutionContext.getCurrentExecutionContext().submit(
@@ -121,29 +146,22 @@ public class EffectorConcatenateTest {
}
}
- private TestApplication app;
- private MyEntityImpl e;
+ private MyEntity entity;
@BeforeMethod(alwaysRun=true)
- public void setUp() {
- app = new TestApplicationImpl();
- e = new MyEntityImpl(app);
- Entities.startManagement(app);
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() {
- if (app != null) Entities.destroyAll(app.getManagementContext());
+ public void setUp() throws Exception {
+ super.setUp();
+ entity = app.addChild(EntitySpec.create(MyEntity.class));
}
@Test
public void testCanInvokeEffector() throws Exception {
// invocation map syntax
- Task<String> task = e.invoke(MyEntityImpl.CONCATENATE, ImmutableMap.of("first", "a", "second", "b"));
+ Task<String> task = entity.invoke(MyEntity.CONCATENATE, ImmutableMap.of("first", "a", "second", "b"));
assertEquals(task.get(TIMEOUT, TimeUnit.MILLISECONDS), "ab");
// method syntax
- assertEquals("xy", e.concatenate("x", "y"));
+ assertEquals("xy", entity.concatenate("x", "y"));
}
@Test
@@ -155,14 +173,14 @@ public class EffectorConcatenateTest {
public void run() {
try {
// Expect "wait a bit" to tell us it's blocking
- if (!e.nowWaitingLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+ if (!entity.getNowWaitingLatch().await(TIMEOUT, TimeUnit.MILLISECONDS)) {
result.set("took too long for waitabit to be waiting");
return;
}
// Expect "wait a bit" to have retrieved and set its task
try {
- Task<?> t = e.waitingTask.get();
+ Task<?> t = entity.getWaitingTask().get();
String status = t.getStatusDetail(true);
log.info("waitabit task says:\n"+status);
if (!status.contains("waitabit extra status details")) {
@@ -174,7 +192,7 @@ public class EffectorConcatenateTest {
return;
}
} finally {
- e.continueFromWaitingLatch.countDown();
+ entity.getContinueFromWaitingLatch().countDown();
}
} catch (Throwable t) {
log.warn("Failure: "+t, t);
@@ -183,7 +201,7 @@ public class EffectorConcatenateTest {
}});
bg.start();
- e.invoke(MyEntityImpl.WAIT_A_BIT, ImmutableMap.<String,Object>of())
+ entity.invoke(MyEntity.WAIT_A_BIT, ImmutableMap.<String,Object>of())
.get(TIMEOUT, TimeUnit.MILLISECONDS);
bg.join(TIMEOUT*2);
@@ -202,14 +220,14 @@ public class EffectorConcatenateTest {
public void run() {
try {
// Expect "spawned child" to tell us it's blocking
- if (!e.nowWaitingLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
+ if (!entity.getNowWaitingLatch().await(TIMEOUT, TimeUnit.MILLISECONDS)) {
result.set("took too long for spawnchild's sub-task to be waiting");
return;
}
// Expect spawned task to be have been tagged with entity
- ExecutionManager em = e.getManagementContext().getExecutionManager();
- Task<?> subtask = Iterables.find(BrooklynTaskTags.getTasksInEntityContext(em, e), new Predicate<Task<?>>() {
+ ExecutionManager em = entity.getManagementContext().getExecutionManager();
+ Task<?> subtask = Iterables.find(BrooklynTaskTags.getTasksInEntityContext(em, entity), new Predicate<Task<?>>() {
@Override
public boolean apply(Task<?> input) {
return "SpawnedChildName".equals(input.getDisplayName());
@@ -225,7 +243,7 @@ public class EffectorConcatenateTest {
return;
}
} finally {
- e.continueFromWaitingLatch.countDown();
+ entity.getContinueFromWaitingLatch().countDown();
}
} catch (Throwable t) {
log.warn("Failure: "+t, t);
@@ -234,7 +252,7 @@ public class EffectorConcatenateTest {
}});
bg.start();
- e.invoke(MyEntityImpl.SPAWN_CHILD, ImmutableMap.<String,Object>of())
+ entity.invoke(MyEntity.SPAWN_CHILD, ImmutableMap.<String,Object>of())
.get(TIMEOUT, TimeUnit.MILLISECONDS);
bg.join(TIMEOUT*2);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/test/java/org/apache/brooklyn/core/entity/EntitySetFromFlagTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntitySetFromFlagTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/EntitySetFromFlagTest.java
index c909893..7f5e8fd 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/EntitySetFromFlagTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntitySetFromFlagTest.java
@@ -23,54 +23,59 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.PortRange;
-import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.location.PortRanges;
-import org.testng.annotations.Test;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
-public class EntitySetFromFlagTest {
+public class EntitySetFromFlagTest extends BrooklynAppUnitTestSupport {
@Test
public void testSetFromFlagUsingFieldName() {
- MyEntity entity = new MyEntity(MutableMap.of("str1", "myval"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("str1", "myval"));
assertEquals(entity.str1, "myval");
}
@Test
public void testSetFromFlagUsingOverridenName() {
- MyEntity entity = new MyEntity(MutableMap.of("altStr2", "myval"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("altStr2", "myval"));
assertEquals(entity.str2, "myval");
}
@Test
public void testSetFromFlagWhenNoDefaultIsNull() {
- MyEntity entity = new MyEntity();
+ MyEntity entity = newDeproxiedEntity();
assertEquals(entity.str1, null);
}
@Test
public void testSetFromFlagUsesDefault() {
- MyEntity entity = new MyEntity();
+ MyEntity entity = newDeproxiedEntity();
assertEquals(entity.str3, "default str3");
}
@Test
public void testSetFromFlagOverridingDefault() {
- MyEntity entity = new MyEntity(MutableMap.of("str3", "overridden str3"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("str3", "overridden str3"));
assertEquals(entity.str3, "overridden str3");
}
@Test
public void testSetFromFlagCastsPrimitives() {
- MyEntity entity = new MyEntity(MutableMap.of("double1", 1f));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("double1", 1f));
assertEquals(entity.double1, 1d);
}
@Test
public void testSetFromFlagCastsDefault() {
- MyEntity entity = new MyEntity();
+ MyEntity entity = newDeproxiedEntity();
assertEquals(entity.byte1, (byte)1);
assertEquals(entity.short1, (short)2);
assertEquals(entity.int1, 3);
@@ -92,44 +97,60 @@ public class EntitySetFromFlagTest {
@Test
public void testSetFromFlagCoercesDefaultToPortRange() {
- MyEntity entity = new MyEntity();
+ MyEntity entity = newDeproxiedEntity();
assertEquals(entity.portRange1, PortRanges.fromInteger(1234));
}
@Test
public void testSetFromFlagCoercesStringValueToPortRange() {
- MyEntity entity = new MyEntity(MutableMap.of("portRange1", "1-3"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("portRange1", "1-3"));
assertEquals(entity.portRange1, new PortRanges.LinearPortRange(1, 3));
}
@Test
public void testSetFromFlagCoercesStringValueToInt() {
- MyEntity entity = new MyEntity(MutableMap.of("int1", "123"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("int1", "123"));
assertEquals(entity.int1, 123);
}
@Test
public void testSetIconUrl() {
- MyEntity entity = new MyEntity(MutableMap.of("iconUrl", "/img/myicon.gif"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("iconUrl", "/img/myicon.gif"));
assertEquals(entity.getIconUrl(), "/img/myicon.gif");
}
- @Test(expectedExceptions=IllegalArgumentException.class)
- public void testFailsFastOnInvalidCoercion() {;
- new MyEntity(MutableMap.of("int1", "thisisnotanint"));
+ @Test
+ public void testFailsFastOnInvalidCoercion() {
+ try {
+ newDeproxiedEntity(MutableMap.of("int1", "thisisnotanint"));
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception e) {
+ if (Exceptions.getFirstThrowableOfType(e, IllegalArgumentException.class) == null) {
+ throw e;
+ }
+ }
}
- // Fails because configure being called from inside constructor; so field is set after configure called
- @Test(enabled=false)
+ @Test
public void testSetFromFlagWithFieldThatIsExplicitySet() {
- MyEntity entity = new MyEntity(MutableMap.of("str4", "myval"));
+ MyEntity entity = newDeproxiedEntity(MutableMap.of("str4", "myval"));
assertEquals(entity.str4, "myval");
- MyEntity entity2 = new MyEntity();
+ MyEntity entity2 = newDeproxiedEntity();
assertEquals(entity2.str4, "explicit str4");
}
- private static class MyEntity extends AbstractEntity {
+ private MyEntity newDeproxiedEntity() {
+ return newDeproxiedEntity(ImmutableMap.of());
+ }
+
+ private MyEntity newDeproxiedEntity(Map<?, ?> config) {
+ Entity result = app.addChild(EntitySpec.create(Entity.class).impl(MyEntity.class)
+ .configure(config));
+ return (MyEntity) Entities.deproxy(result);
+ }
+
+ public static class MyEntity extends AbstractEntity {
@SetFromFlag(defaultVal="1234")
PortRange portRange1;
@@ -193,21 +214,5 @@ public class EntitySetFromFlagTest {
@SetFromFlag(defaultVal="true")
Boolean bool2;
-
- MyEntity() {
- super(MutableMap.of(), null);
- }
-
- MyEntity(Map flags) {
- super(flags, null);
- }
-
- MyEntity(Entity parent) {
- super(MutableMap.of(), parent);
- }
-
- MyEntity(Map flags, Entity parent) {
- super(flags, parent);
- }
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/test/java/org/apache/brooklyn/core/entity/EntityTypeTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntityTypeTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/EntityTypeTest.java
index aac3cca..e7cf727 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/EntityTypeTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntityTypeTest.java
@@ -47,14 +47,6 @@ import java.util.Set;
import javax.annotation.Nullable;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
@@ -69,6 +61,13 @@ import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.core.test.entity.TestEntityImpl;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableSet;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
public class EntityTypeTest extends BrooklynAppUnitTestSupport {
private static final AttributeSensor<String> TEST_SENSOR = Sensors.newStringSensor("test.sensor");
@@ -152,30 +151,25 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
@Test
public void testCustomSimpleName() throws Exception {
- class CustomTypeNamedEntity extends AbstractEntity {
- private final String typeName;
- @SuppressWarnings("deprecation")
- CustomTypeNamedEntity(Entity parent, String typeName) {
- super(parent);
- this.typeName = typeName;
- }
- @Override protected String getEntityTypeName() {
- return typeName;
- }
- }
-
- CustomTypeNamedEntity entity2 = new CustomTypeNamedEntity(app, "a.b.with space");
- Entities.manage(entity2);
+ CustomTypeNamedEntity.typeName = "a.b.with space";
+ Entity entity2 = app.addChild(EntitySpec.create(Entity.class).impl(CustomTypeNamedEntity.class));
assertEquals(entity2.getEntityType().getSimpleName(), "with_space");
- CustomTypeNamedEntity entity3 = new CustomTypeNamedEntity(app, "a.b.with$dollar");
- Entities.manage(entity3);
+ CustomTypeNamedEntity.typeName = "a.b.with$dollar";
+ Entity entity3 = app.addChild(EntitySpec.create(Entity.class).impl(CustomTypeNamedEntity.class));
assertEquals(entity3.getEntityType().getSimpleName(), "with_dollar");
- CustomTypeNamedEntity entity4 = new CustomTypeNamedEntity(app, "a.nothingafterdot.");
- Entities.manage(entity4);
+ CustomTypeNamedEntity.typeName = "a.nothingafterdot.";
+ Entity entity4 = app.addChild(EntitySpec.create(Entity.class).impl(CustomTypeNamedEntity.class));
assertEquals(entity4.getEntityType().getSimpleName(), "a.nothingafterdot.");
}
+ public static class CustomTypeNamedEntity extends AbstractEntity {
+ static volatile String typeName;
+
+ @Override protected String getEntityTypeName() {
+ return typeName;
+ }
+ }
@Test
public void testGetSensors() throws Exception{
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenDeprecatedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenDeprecatedTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenDeprecatedTest.java
new file mode 100644
index 0000000..a134b6c
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenDeprecatedTest.java
@@ -0,0 +1,215 @@
+/*
+ * 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.core.entity;
+
+import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+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.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class OwnedChildrenDeprecatedTest extends BrooklynAppUnitTestSupport {
+
+ // Tests that the deprecated "owner" still works
+ @Test
+ public void testSetOwnerInConstructorMap() {
+ Entity e = new AbstractEntity(MutableMap.of("owner", app)) {};
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ assertEquals(e.getApplication(), app);
+ }
+
+ // Tests that the deprecated constructor still works
+ @Test
+ public void testSetParentInConstructorArgument() {
+ Entity e = new AbstractEntity(app) {};
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ assertEquals(e.getApplication(), app);
+ }
+
+ // Tests with deprecated constructor usage
+ @Test
+ public void testSetParentWhenMatchesParentSetInConstructor() {
+ Entity e = new AbstractEntity(app) {};
+ e.setParent(app);
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ }
+
+ // Tests with deprecated constructor usage
+ @Test
+ public void testSetParentWhenDiffersFromParentSetInConstructor() {
+ Entity e = new AbstractEntity(app) {};
+ Entity e2 = new AbstractEntity() {};
+ try {
+ e.setParent(e2);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception uoe = Exceptions.getFirstThrowableOfType(ex, UnsupportedOperationException.class);
+ if (uoe == null || !uoe.toString().contains("Cannot change parent")) {
+ throw ex;
+ }
+ }
+ }
+
+ // Tests deprecated setParent still works - should be set through EntitySpec or addChild
+ @Test
+ public void testSetParentInSetterMethod() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ e.setParent(app);
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ assertEquals(e.getApplication(), app);
+ }
+
+ // Tests with deprecated setParent(Entity)
+ @Test
+ public void testSetParentWhenMatchesParentSetInSpec() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
+ e.setParent(app);
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ }
+
+ // Tests with deprecated setParent(Entity)
+ @Test
+ public void testSetParentWhenDiffersFromParentSetInSpec() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
+ Entity e2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
+ try {
+ e.setParent(e2);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception uoe = Exceptions.getFirstThrowableOfType(ex, UnsupportedOperationException.class);
+ if (uoe == null || !uoe.toString().contains("Cannot change parent")) {
+ throw ex;
+ }
+ }
+ }
+
+ // Tests deprecated addChild still works - users should instead set it through EntitySpec (or {@code addChild(EntitySpec)})
+ @Test
+ public void testAddChild() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ app.addChild(e);
+
+ assertEquals(e.getParent(), app);
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
+ assertEquals(e.getApplication(), app);
+ }
+
+
+
+ @Test(enabled = false) // FIXME fails currently
+ public void testRemoveChild() {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ app.removeChild(e);
+
+ assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of());
+ assertEquals(e.getParent(), null);
+ }
+
+ @Test
+ public void testParentalLoopForbiddenViaAddChild() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
+ try {
+ e2.addChild(e);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
+ if (cause == null || !cause.toString().contains("loop detected trying to add child")) {
+ throw ex;
+ }
+ }
+ assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
+ assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
+ assertEquals(e.getParent(), null);
+ assertEquals(e2.getParent(), e);
+ }
+
+ @Test
+ public void testParentalLoopForbiddenViaSetParent() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
+ try {
+ e.setParent(e2);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
+ if (cause == null || !cause.toString().contains("loop detected trying to set parent")) {
+ throw ex;
+ }
+ }
+ assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
+ assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
+ assertEquals(e.getParent(), null);
+ assertEquals(e2.getParent(), e);
+ }
+
+ @Test
+ public void testChildingOneselfForbidden() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ try {
+ e.addChild(e);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
+ if (cause == null || !cause.toString().contains("cannot own itself")) {
+ throw ex;
+ }
+ }
+
+ assertNull(e.getParent());
+ assertEquals(e.getChildren(), ImmutableList.of());
+ }
+
+ @Test
+ public void testParentingOneselfForbidden() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
+ try {
+ e.setParent(e);
+ Asserts.shouldHaveFailedPreviously();
+ } catch (Exception ex) {
+ Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class);
+ if (cause == null || !cause.toString().contains("cannot own itself")) {
+ throw ex;
+ }
+ }
+
+ assertNull(e.getParent());
+ assertEquals(e.getChildren(), ImmutableList.of());
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenTest.java
index dede9aa..f750f6d 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/OwnedChildrenTest.java
@@ -22,102 +22,62 @@ import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.entity.AbstractApplication;
-import org.apache.brooklyn.core.entity.AbstractEntity;
-import org.apache.brooklyn.core.entity.Entities;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
+import org.apache.brooklyn.api.entity.EntitySpec;
+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.test.Asserts;
+import org.apache.brooklyn.util.exceptions.Exceptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
-public class OwnedChildrenTest {
+public class OwnedChildrenTest extends BrooklynAppUnitTestSupport {
- private Application app;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() {
- app = new AbstractApplication() {};
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown(){
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
- // Tests that the deprecated "owner" still works
@Test
- public void testSetOwnerInConstructorMap() {
- Entity e = new AbstractEntity(app) {};
+ public void testAddChildUsingSpec() {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
assertEquals(e.getParent(), app);
- assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- assertEquals(e.getApplication(), app);
+ assertEquals(app.getChildren(), ImmutableList.of(e));
}
@Test
- public void testSetParentInConstructorMap() {
- Entity e = new AbstractEntity(app) {};
+ public void testSpecDeclaresParent() {
+ Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
assertEquals(e.getParent(), app);
assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- assertEquals(e.getApplication(), app);
}
@Test
- public void testSetParentInConstructorArgument() {
- Entity e = new AbstractEntity(app) {};
+ public void testAddChildWhenMatchesParentSetInSpec() {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class).parent(app));
assertEquals(e.getParent(), app);
assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- assertEquals(e.getApplication(), app);
}
@Test
- public void testSetParentInSetterMethod() {
- Entity e = new AbstractEntity() {};
- e.setParent(app);
-
- assertEquals(e.getParent(), app);
- assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- assertEquals(e.getApplication(), app);
- }
-
- @Test
- public void testAddChild() {
- Entity e = new AbstractEntity() {};
- app.addChild(e);
-
- assertEquals(e.getParent(), app);
- assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- assertEquals(e.getApplication(), app);
- }
-
- @Test
- public void testSetParentWhenMatchesParentSetInConstructor() {
- Entity e = new AbstractEntity(app) {};
- e.setParent(app);
-
- assertEquals(e.getParent(), app);
- assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
- }
-
- @Test(expectedExceptions = UnsupportedOperationException.class)
- public void testSetParentWhenDiffersFromParentSetInConstructor() {
- Entity e = new AbstractEntity(app) {};
- Entity e2 = new AbstractEntity() {};
- e.setParent(e2);
- fail();
+ public void testAddChildWhenDifferentParentSetInSpec() {
+ TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
+ try {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class).parent(app2));
+ Asserts.shouldHaveFailedPreviously("entity="+e);
+ } catch (Exception ex) {
+ Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalArgumentException.class);
+ if (cause == null || !cause.toString().contains("failed because spec has different parent")) {
+ throw ex;
+ }
+ }
}
@Test
public void testParentCanHaveMultipleChildren() {
- Entity e = new AbstractEntity(app) {};
- Entity e2 = new AbstractEntity(app) {};
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entity e2 = app.addChild(EntitySpec.create(TestEntity.class));
assertEquals(e.getParent(), app);
assertEquals(e2.getParent(), app);
@@ -126,9 +86,9 @@ public class OwnedChildrenTest {
@Test
public void testHierarchyOfOwners() {
- Entity e = new AbstractEntity(app) {};
- Entity e2 = new AbstractEntity(e) {};
- Entity e3 = new AbstractEntity(e2) {};
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
+ Entity e3 = e2.addChild(EntitySpec.create(TestEntity.class));
assertEquals(app.getParent(), null);
assertEquals(e.getParent(), app);
@@ -141,73 +101,43 @@ public class OwnedChildrenTest {
assertEqualsIgnoringOrder(e3.getChildren(), ImmutableList.of());
}
- @Test(enabled = false) // FIXME fails currently
- public void testRemoveChild() {
- Entity e = new AbstractEntity(app) {};
- app.removeChild(e);
+ @Test
+ public void testUnmanageEntityRemovedAsChild() {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entities.unmanage(e);
assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of());
assertEquals(e.getParent(), null);
}
@Test
- public void testParentalLoopForbiddenViaAddChild() {
- Entity e = new AbstractEntity() {};
- Entity e2 = new AbstractEntity(e) {};
- try {
- e2.addChild(e);
- fail();
- } catch (IllegalStateException ex) {
- // success
- }
+ public void testUnmanageParentRemovesChild() {
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entities.unmanage(app);
- assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
- assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
- assertEquals(e.getParent(), null);
- assertEquals(e2.getParent(), e);
- }
-
- @Test
- public void testParentalLoopForbiddenViaSetParent() {
- Entity e = new AbstractEntity() {};
- Entity e2 = new AbstractEntity(e) {};
- try {
- e.setParent(e2);
- fail();
- } catch (IllegalStateException ex) {
- ex.printStackTrace();
- // success
- }
- assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2));
- assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of());
- assertEquals(e.getParent(), null);
- assertEquals(e2.getParent(), e);
- }
-
- @Test(expectedExceptions = IllegalStateException.class)
- public void testParentingOneselfForbidden() {
- AbstractEntity e = new AbstractEntity() {};
- e.addChild(e);
- fail();
+ assertFalse(Entities.isManaged(app));
+ assertFalse(Entities.isManaged(e));
}
@Test
public void testIsAncestor() {
- AbstractEntity e = new AbstractEntity(app) {};
- AbstractEntity e2 = new AbstractEntity(e) {};
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
assertTrue(Entities.isAncestor(e2, app));
assertTrue(Entities.isAncestor(e2, e));
assertFalse(Entities.isAncestor(e2, e2));
+ assertFalse(Entities.isAncestor(e, e2));
}
@Test
public void testIsDescendant() {
- AbstractEntity e = new AbstractEntity(app) {};
- AbstractEntity e2 = new AbstractEntity(e) {};
+ Entity e = app.addChild(EntitySpec.create(TestEntity.class));
+ Entity e2 = e.addChild(EntitySpec.create(TestEntity.class));
assertTrue(Entities.isDescendant(app, e));
assertTrue(Entities.isDescendant(app, e2));
assertFalse(Entities.isDescendant(e2, e));
+ assertFalse(Entities.isDescendant(e2, e2));
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/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 b31caf2..2331b48 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
@@ -63,9 +63,6 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity {
public TestEntityImpl() {
super();
}
- public TestEntityImpl(Map properties) {
- this(properties, null);
- }
public TestEntityImpl(Entity parent) {
this(MutableMap.of(), parent);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
index bdeaf17..3342959 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyTest.java
@@ -38,6 +38,7 @@ import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.trait.Resizable;
import org.apache.brooklyn.core.sensor.BasicNotificationSensor;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.core.test.entity.TestCluster;
import org.apache.brooklyn.test.Asserts;
@@ -55,7 +56,7 @@ import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-public class AutoScalerPolicyTest {
+public class AutoScalerPolicyTest extends BrooklynAppUnitTestSupport {
private static final Logger log = LoggerFactory.getLogger(AutoScalerPolicyTest.class);
@@ -69,16 +70,15 @@ public class AutoScalerPolicyTest {
AutoScalerPolicy policy;
TestCluster cluster;
LocallyResizableEntity resizable;
- TestApplication app;
List<Integer> policyResizes = MutableList.of();
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
+ super.setUp();
log.info("resetting "+getClass().getSimpleName());
- app = TestApplication.Factory.newManagedInstanceForTests();
cluster = app.createAndManageChild(EntitySpec.create(TestCluster.class).configure(TestCluster.INITIAL_SIZE, 1));
- resizable = new LocallyResizableEntity(cluster, cluster);
- Entities.manage(resizable);
+ resizable = cluster.addChild(EntitySpec.create(LocallyResizableEntity.class)
+ .configure(LocallyResizableEntity.TEST_CLUSTER, cluster));
PolicySpec<AutoScalerPolicy> policySpec = PolicySpec.create(AutoScalerPolicy.class).configure(AutoScalerPolicy.RESIZE_OPERATOR, new ResizeOperator() {
@Override
public Integer resize(Entity entity, Integer desiredSize) {
@@ -93,11 +93,14 @@ public class AutoScalerPolicyTest {
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
- if (policy != null) policy.destroy();
- if (app != null) Entities.destroyAll(app.getManagementContext());
- cluster = null;
- resizable = null;
- policy = null;
+ try {
+ if (policy != null) policy.destroy();
+ } finally {
+ super.tearDown();
+ cluster = null;
+ resizable = null;
+ policy = null;
+ }
}
public void assertSizeEventually(Integer targetSize) {
@@ -236,7 +239,7 @@ public class AutoScalerPolicyTest {
@Test
public void testNeverShrinkHotPool() throws Exception {
- resizable.resizeSleepTime = 0;
+ resizable.setResizeSleepTime(0);
resizable.resize(2);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 0L, 2*10L, 2*20L));
@@ -247,7 +250,7 @@ public class AutoScalerPolicyTest {
@Test(groups="Integration")
public void testConcurrentShrinkShrink() throws Exception {
- resizable.resizeSleepTime = 250;
+ resizable.setResizeSleepTime(250);
resizable.resize(4);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L));
// would cause pool to shrink to 3
@@ -260,7 +263,7 @@ public class AutoScalerPolicyTest {
@Test(groups="Integration")
public void testConcurrentGrowGrow() throws Exception {
- resizable.resizeSleepTime = 250;
+ resizable.setResizeSleepTime(250);
resizable.resize(2);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 41L, 2*10L, 2*20L));
// would cause pool to grow to 3
@@ -273,7 +276,7 @@ public class AutoScalerPolicyTest {
@Test(groups="Integration")
public void testConcurrentGrowShrink() throws Exception {
- resizable.resizeSleepTime = 250;
+ resizable.setResizeSleepTime(250);
resizable.resize(2);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_HOT_SENSOR, message(2, 81L, 2*10L, 2*20L));
// would cause pool to grow to 5
@@ -286,7 +289,7 @@ public class AutoScalerPolicyTest {
@Test(groups="Integration")
public void testConcurrentShrinkGrow() throws Exception {
- resizable.resizeSleepTime = 250;
+ resizable.setResizeSleepTime(250);
resizable.resize(4);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 1L, 4*10L, 4*20L));
// would cause pool to shrink to 1
@@ -302,14 +305,14 @@ public class AutoScalerPolicyTest {
@Test(groups="WIP")
public void testRepeatedQueuedResizeTakesLatestValueRatherThanIntermediateValues() throws Exception {
// TODO is this too time sensitive? the resize takes only 250ms so if it finishes before the next emit we'd also see size=2
- resizable.resizeSleepTime = 500;
+ resizable.setResizeSleepTime(250);
resizable.resize(4);
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 30L, 4*10L, 4*20L)); // shrink to 3
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 20L, 4*10L, 4*20L)); // shrink to 2
resizable.sensors().emit(AutoScalerPolicy.DEFAULT_POOL_COLD_SENSOR, message(4, 10L, 4*10L, 4*20L)); // shrink to 1
Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), currentSizeAsserter(resizable, 1));
- assertEquals(resizable.sizes, ImmutableList.of(4, 3, 1));
+ assertEquals(resizable.getSizes(), ImmutableList.of(4, 3, 1));
}
@@ -381,7 +384,7 @@ public class AutoScalerPolicyTest {
assertEquals(resizable.getCurrentSize(), (Integer)1);
Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
@Override public void run() {
- assertEquals(resizable.sizes, ImmutableList.of(1));
+ assertEquals(resizable.getSizes(), ImmutableList.of(1));
}});
}
@@ -510,7 +513,7 @@ public class AutoScalerPolicyTest {
Asserts.succeedsContinually(MutableMap.of("duration", 2000L), new Runnable() {
@Override
public void run() {
- assertEquals(resizable.sizes, ImmutableList.of(2));
+ assertEquals(resizable.getSizes(), ImmutableList.of(2));
}});
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java
index 5550899..14698b4 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntity.java
@@ -21,52 +21,23 @@ package org.apache.brooklyn.policy.autoscaling;
import java.util.List;
import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.trait.Resizable;
-import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.test.entity.TestCluster;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-
/**
* Test class for providing a Resizable LocallyManagedEntity for policy testing
* It is hooked up to a TestCluster that can be used to make assertions against
*/
-public class LocallyResizableEntity extends AbstractEntity implements Resizable {
- List<Integer> sizes = Lists.newArrayList();
- TestCluster cluster;
- long resizeSleepTime = 0;
-
- public LocallyResizableEntity (TestCluster tc) {
- this(null, tc);
- }
- @SuppressWarnings("deprecation")
- public LocallyResizableEntity (Entity parent, TestCluster tc) {
- super(parent);
- this.cluster = tc;
- sensors().set(Startable.SERVICE_UP, true);
- }
-
- @Override
- public Integer resize(Integer newSize) {
- try {
- Thread.sleep(resizeSleepTime);
- sizes.add(newSize);
- return cluster.resize(newSize);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw Throwables.propagate(e);
- }
- }
+@ImplementedBy(LocallyResizableEntityImpl.class)
+public interface LocallyResizableEntity extends Entity, Resizable {
+ ConfigKey<TestCluster> TEST_CLUSTER = ConfigKeys.newConfigKey(
+ TestCluster.class,
+ "testCluster");
- @Override
- public Integer getCurrentSize() {
- return cluster.getCurrentSize();
- }
+ void setResizeSleepTime(long val);
- @Override
- public String toString() {
- return getDisplayName();
- }
+ List<Integer> getSizes();
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntityImpl.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntityImpl.java b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntityImpl.java
new file mode 100644
index 0000000..59144c4
--- /dev/null
+++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/LocallyResizableEntityImpl.java
@@ -0,0 +1,76 @@
+/*
+ * 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.policy.autoscaling;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.List;
+
+import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.test.entity.TestCluster;
+
+import com.google.common.base.Throwables;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+public class LocallyResizableEntityImpl extends AbstractEntity implements LocallyResizableEntity {
+ List<Integer> sizes = Lists.newArrayList();
+ TestCluster cluster;
+ long resizeSleepTime = 0;
+
+ @Override
+ public void init() {
+ super.init();
+ this.cluster = checkNotNull(config().get(TEST_CLUSTER), "testCluster");
+ sensors().set(Startable.SERVICE_UP, true);
+ }
+
+ @Override
+ public void setResizeSleepTime(long val) {
+ resizeSleepTime = val;
+ }
+
+ @Override
+ public List<Integer> getSizes() {
+ return ImmutableList.copyOf(sizes);
+ }
+
+ @Override
+ public Integer resize(Integer newSize) {
+ try {
+ Thread.sleep(resizeSleepTime);
+ sizes.add(newSize);
+ return cluster.resize(newSize);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ public Integer getCurrentSize() {
+ return cluster.getCurrentSize();
+ }
+
+ @Override
+ public String toString() {
+ return getDisplayName();
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
index 3722bcd..62cdef8 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
@@ -20,45 +20,35 @@ package org.apache.brooklyn.policy.enricher;
import static org.testng.Assert.assertEquals;
-import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.mgmt.SubscriptionContext;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.core.entity.AbstractApplication;
-import org.apache.brooklyn.core.entity.AbstractEntity;
-import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.base.Function;
-public class DeltaEnrichersTests {
+public class DeltaEnrichersTests extends BrooklynAppUnitTestSupport {
- AbstractApplication app;
-
- EntityLocal producer;
+ Entity producer;
Sensor<Integer> intSensor;
Sensor<Double> avgSensor;
SubscriptionContext subscription;
- @BeforeMethod
- public void before() {
- app = new AbstractApplication() {};
- producer = new AbstractEntity(app) {};
- producer.setParent(app);
- Entities.startManagement(app);
-
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ producer = app.addChild(EntitySpec.create(TestEntity.class));
intSensor = new BasicAttributeSensor<Integer>(Integer.class, "int sensor");
}
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
@Test
public void testDeltaEnricher() {
AttributeSensor<Integer> deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor");
@@ -83,15 +73,16 @@ public class DeltaEnrichersTests {
TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer, intSensor, deltaSensor);
producer.enrichers().add(delta);
- delta.onEvent(intSensor.newEvent(producer, 0), 0);
- assertEquals(producer.getAttribute(deltaSensor), null);
+ // Don't start with timestamp=0: that may be treated special
delta.onEvent(intSensor.newEvent(producer, 0), 1000);
+ assertEquals(producer.getAttribute(deltaSensor), null);
+ delta.onEvent(intSensor.newEvent(producer, 0), 2000);
assertEquals(producer.getAttribute(deltaSensor), 0d);
- delta.onEvent(intSensor.newEvent(producer, 1), 2000);
+ delta.onEvent(intSensor.newEvent(producer, 1), 3000);
assertEquals(producer.getAttribute(deltaSensor), 1d);
- delta.onEvent(intSensor.newEvent(producer, 3), 3000);
+ delta.onEvent(intSensor.newEvent(producer, 3), 4000);
assertEquals(producer.getAttribute(deltaSensor), 2d);
- delta.onEvent(intSensor.newEvent(producer, 8), 4000);
+ delta.onEvent(intSensor.newEvent(producer, 8), 5000);
assertEquals(producer.getAttribute(deltaSensor), 5d);
}
@@ -102,16 +93,16 @@ public class DeltaEnrichersTests {
TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer, intSensor, deltaSensor);
producer.enrichers().add(delta);
- delta.onEvent(intSensor.newEvent(producer, 0), 0);
- delta.onEvent(intSensor.newEvent(producer, 0), 2000);
+ delta.onEvent(intSensor.newEvent(producer, 0), 1000);
+ delta.onEvent(intSensor.newEvent(producer, 0), 3000);
assertEquals(producer.getAttribute(deltaSensor), 0d);
- delta.onEvent(intSensor.newEvent(producer, 3), 5000);
+ delta.onEvent(intSensor.newEvent(producer, 3), 6000);
assertEquals(producer.getAttribute(deltaSensor), 1d);
- delta.onEvent(intSensor.newEvent(producer, 7), 7000);
+ delta.onEvent(intSensor.newEvent(producer, 7), 8000);
assertEquals(producer.getAttribute(deltaSensor), 2d);
- delta.onEvent(intSensor.newEvent(producer, 12), 7500);
+ delta.onEvent(intSensor.newEvent(producer, 12), 8500);
assertEquals(producer.getAttribute(deltaSensor), 10d);
- delta.onEvent(intSensor.newEvent(producer, 15), 9500);
+ delta.onEvent(intSensor.newEvent(producer, 15), 10500);
assertEquals(producer.getAttribute(deltaSensor), 1.5d);
}
@@ -121,10 +112,10 @@ public class DeltaEnrichersTests {
TimeWeightedDeltaEnricher<Integer> delta = new TimeWeightedDeltaEnricher<Integer>(producer, intSensor, deltaSensor, 1000, new AddConstant(123d));
producer.enrichers().add(delta);
- delta.onEvent(intSensor.newEvent(producer, 0), 0);
delta.onEvent(intSensor.newEvent(producer, 0), 1000);
+ delta.onEvent(intSensor.newEvent(producer, 0), 2000);
assertEquals(producer.getAttribute(deltaSensor), 123+0d);
- delta.onEvent(intSensor.newEvent(producer, 1), 2000);
+ delta.onEvent(intSensor.newEvent(producer, 1), 3000);
assertEquals(producer.getAttribute(deltaSensor), 123+1d);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
index b8b6f15..4db1a6f 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
@@ -20,22 +20,19 @@ package org.apache.brooklyn.policy.enricher;
import static org.testng.Assert.assertEquals;
-import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.core.entity.AbstractApplication;
-import org.apache.brooklyn.core.entity.AbstractEntity;
-import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-public class RollingMeanEnricherTest {
+public class RollingMeanEnricherTest extends BrooklynAppUnitTestSupport {
- AbstractApplication app;
-
- EntityLocal producer;
+ Entity producer;
Sensor<Integer> intSensor;
AttributeSensor<Integer> deltaSensor;
@@ -43,11 +40,10 @@ public class RollingMeanEnricherTest {
RollingMeanEnricher<Integer> averager;
@BeforeMethod(alwaysRun=true)
- public void before() {
- app = new AbstractApplication() {};
- producer = new AbstractEntity(app) {};
- producer.setParent(app);
- Entities.startManagement(app);
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ producer = app.addChild(EntitySpec.create(TestEntity.class));
intSensor = new BasicAttributeSensor<Integer>(Integer.class, "int sensor");
deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor");
@@ -58,11 +54,6 @@ public class RollingMeanEnricherTest {
producer.enrichers().add(averager);
}
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
@Test
public void testDefaultAverage() {
assertEquals(averager.getAverage(), null);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
index 162833d..90854e7 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
@@ -20,24 +20,21 @@ package org.apache.brooklyn.policy.enricher;
import static org.testng.Assert.assertEquals;
-import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.core.entity.AbstractApplication;
-import org.apache.brooklyn.core.entity.AbstractEntity;
-import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.policy.enricher.RollingTimeWindowMeanEnricher.ConfidenceQualifiedNumber;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@SuppressWarnings("deprecation")
-public class RollingTimeWindowMeanEnricherTest {
+public class RollingTimeWindowMeanEnricherTest extends BrooklynAppUnitTestSupport {
- AbstractApplication app;
-
- EntityLocal producer;
+ Entity producer;
Sensor<Integer> intSensor;
AttributeSensor<Integer> deltaSensor;
@@ -48,11 +45,11 @@ public class RollingTimeWindowMeanEnricherTest {
private final long timePeriod = 1000;
- @BeforeMethod
- public void before() {
- app = new AbstractApplication() {};
- producer = new AbstractEntity(app) {};
- Entities.startManagement(app);
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ producer = app.addChild(EntitySpec.create(TestEntity.class));
intSensor = new BasicAttributeSensor<Integer>(Integer.class, "int sensor");
deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor");
@@ -63,11 +60,6 @@ public class RollingTimeWindowMeanEnricherTest {
producer.enrichers().add(averager);
}
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
@Test
public void testDefaultAverageWhenEmpty() {
average = averager.getAverage(0);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
index 36d3bf6..f1977a9 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimpleEntity.java
@@ -18,9 +18,6 @@
*/
package org.apache.brooklyn.rest.testing.mocks;
-import java.util.Map;
-
-import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.annotation.Effector;
@@ -39,22 +36,6 @@ public class RestMockSimpleEntity extends SoftwareProcessImpl {
private static final Logger log = LoggerFactory.getLogger(RestMockSimpleEntity.class);
- public RestMockSimpleEntity() {
- super();
- }
-
- public RestMockSimpleEntity(Entity parent) {
- super(parent);
- }
-
- public RestMockSimpleEntity(@SuppressWarnings("rawtypes") Map flags, Entity parent) {
- super(flags, parent);
- }
-
- public RestMockSimpleEntity(@SuppressWarnings("rawtypes") Map flags) {
- super(flags);
- }
-
@Override
protected void connectSensors() {
super.connectSensors();
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
index 128f909..54c81d1 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -119,14 +119,6 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl implements BrooklynNod
private HttpFeed httpFeed;
- public BrooklynNodeImpl() {
- super();
- }
-
- public BrooklynNodeImpl(Entity parent) {
- super(parent);
- }
-
@Override
public Class<?> getDriverInterface() {
return BrooklynNodeDriver.class;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/main/java/org/apache/brooklyn/entity/java/VanillaJavaAppImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/java/VanillaJavaAppImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/java/VanillaJavaAppImpl.java
index 6f73a4c..3609e73 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/java/VanillaJavaAppImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/java/VanillaJavaAppImpl.java
@@ -23,35 +23,25 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
-import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.entity.software.base.SoftwareProcessImpl;
import org.apache.brooklyn.feed.jmx.JmxFeed;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.annotations.VisibleForTesting;
-
public class VanillaJavaAppImpl extends SoftwareProcessImpl implements VanillaJavaApp {
+ private static final Logger log = LoggerFactory.getLogger(VanillaJavaApp.class);
+
static {
JavaAppUtils.init();
}
- private static final Logger log = LoggerFactory.getLogger(VanillaJavaApp.class);
-
@SetFromFlag
protected long jmxPollPeriod;
protected JmxFeed jmxFeed;
- public VanillaJavaAppImpl() {}
-
- @VisibleForTesting
- public VanillaJavaAppImpl(Map<?,?> properties, Entity parent) {
- super(properties, parent);
- }
-
@Override
public String getMainClass() { return getConfig(MAIN_CLASS); }
@Override
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
index 68b7955..89e49dd 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
@@ -89,19 +89,6 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft
protected boolean connectedSensors = false;
- public SoftwareProcessImpl() {
- super(MutableMap.of(), null);
- }
- public SoftwareProcessImpl(Entity parent) {
- this(MutableMap.of(), parent);
- }
- public SoftwareProcessImpl(Map properties) {
- this(properties, null);
- }
- public SoftwareProcessImpl(Map properties, Entity parent) {
- super(properties, parent);
- }
-
protected void setProvisioningLocation(MachineProvisioningLocation val) {
if (getAttribute(PROVISIONING_LOCATION) != null) throw new IllegalStateException("Cannot change provisioning location: existing="+getAttribute(PROVISIONING_LOCATION)+"; new="+val);
sensors().set(PROVISIONING_LOCATION, val);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityTest.java
index 3fa464c..ae3943b 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityTest.java
@@ -90,6 +90,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.common.reflect.TypeToken;
public class SoftwareProcessEntityTest extends BrooklynAppUnitTestSupport {
@@ -388,12 +389,8 @@ public class SoftwareProcessEntityTest extends BrooklynAppUnitTestSupport {
@Test
public void testReleaseEvenIfErrorDuringStart() throws Exception {
- MyServiceImpl entity = new MyServiceImpl(app) {
- @Override public Class<?> getDriverInterface() {
- return SimulatedFailOnStartDriver.class;
- }
- };
- Entities.manage(entity);
+ MyService entity = app.addChild(EntitySpec.create(MyServiceWithCustomDriver.class)
+ .configure(MyServiceWithCustomDriver.DRIVER_CLASS, SimulatedFailOnStartDriver.class));
try {
entity.start(ImmutableList.of(loc));
@@ -413,17 +410,12 @@ public class SoftwareProcessEntityTest extends BrooklynAppUnitTestSupport {
Entities.unmanage(entity);
}
- @SuppressWarnings("rawtypes")
- public void doTestReleaseEvenIfErrorDuringStop(final Class driver) throws Exception {
- MyServiceImpl entity = new MyServiceImpl(app) {
- @Override public Class<?> getDriverInterface() {
- return driver;
- }
- };
- Entities.manage(entity);
+ public void doTestReleaseEvenIfErrorDuringStop(final Class<? extends SimulatedDriver> driver) throws Exception {
+ MyService entity = app.addChild(EntitySpec.create(MyServiceWithCustomDriver.class)
+ .configure(MyServiceWithCustomDriver.DRIVER_CLASS, driver));
entity.start(ImmutableList.of(loc));
- Task<Void> t = entity.invoke(Startable.STOP);
+ Task<Void> t = entity.invoke(Startable.STOP, ImmutableMap.<String, Object>of());
t.blockUntilEnded();
assertFalse(t.isError(), "Expected parent to succeed, not fail with " + Tasks.getError(t));
@@ -634,9 +626,6 @@ public class SoftwareProcessEntityTest extends BrooklynAppUnitTestSupport {
}
public static class MyServiceImpl extends SoftwareProcessImpl implements MyService {
- public MyServiceImpl() {}
- public MyServiceImpl(Entity parent) { super(parent); }
-
@Override
protected void initEnrichers() {
// Don't add enrichers messing with the SERVICE_UP state - we are setting it manually
@@ -659,8 +648,21 @@ public class SoftwareProcessEntityTest extends BrooklynAppUnitTestSupport {
}
public static class MyServiceWithVersionImpl extends MyServiceImpl implements MyServiceWithVersion {
- public MyServiceWithVersionImpl() {}
- public MyServiceWithVersionImpl(Entity parent) { super(parent); }
+ }
+
+ @ImplementedBy(MyServiceWithCustomDriverImpl.class)
+ public interface MyServiceWithCustomDriver extends MyService {
+ @SuppressWarnings("serial")
+ ConfigKey<Class<? extends SimulatedDriver>> DRIVER_CLASS = ConfigKeys.newConfigKey(
+ new TypeToken<Class<? extends SimulatedDriver>>() {},
+ "driverClass");
+ }
+
+ public static class MyServiceWithCustomDriverImpl extends MyServiceImpl implements MyServiceWithCustomDriver {
+ @Override
+ public Class<?> getDriverInterface() {
+ return config().get(DRIVER_CLASS);
+ }
}
public static class SimulatedFailOnStartDriver extends SimulatedDriver {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java
index f18ccd6..a74bf04 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/lifecycle/StartStopSshDriverTest.java
@@ -31,13 +31,13 @@ import java.util.Map;
import java.util.Set;
import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestApplicationImpl;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.core.test.entity.TestEntityImpl;
import org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableSet;
@@ -47,7 +47,6 @@ import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool;
import org.apache.brooklyn.util.stream.StreamGobbler;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
@@ -55,7 +54,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-public class StartStopSshDriverTest {
+public class StartStopSshDriverTest extends BrooklynAppUnitTestSupport {
public class BasicStartStopSshDriver extends AbstractSoftwareProcessSshDriver {
public BasicStartStopSshDriver(EntityLocal entity, SshMachineLocation machine) {
@@ -82,15 +81,13 @@ public class StartStopSshDriverTest {
}
}
- private TestApplication app;
private TestEntity entity;
private SshMachineLocationWithSshTool sshMachineLocation;
private AbstractSoftwareProcessSshDriver driver;
@SuppressWarnings("rawtypes")
- protected static class SshMachineLocationWithSshTool extends SshMachineLocation {
+ public static class SshMachineLocationWithSshTool extends SshMachineLocation {
SshTool lastTool;
- public SshMachineLocationWithSshTool(Map flags) { super(flags); }
@Override
public SshTool connectSsh(Map args) {
@@ -101,11 +98,12 @@ public class StartStopSshDriverTest {
}
@BeforeMethod(alwaysRun = true)
- public void setUp() {
- app = new TestApplicationImpl();
- entity = new TestEntityImpl(app);
- Entities.startManagement(app);
- sshMachineLocation = new SshMachineLocationWithSshTool(ImmutableMap.of("address", "localhost"));
+ public void setUp() throws Exception {
+ super.setUp();
+ entity = app.addChild(EntitySpec.create(TestEntity.class));
+
+ sshMachineLocation = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocationWithSshTool.class)
+ .configure("address", "localhost"));
driver = new BasicStartStopSshDriver(entity, sshMachineLocation);
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a394007/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java b/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
index dc63361..6966a73 100644
--- a/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/feed/jmx/JmxFeedTest.java
@@ -42,6 +42,7 @@ import javax.management.openmbean.TabularType;
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.sensor.AttributeSensor;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
@@ -55,8 +56,8 @@ import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
import org.apache.brooklyn.core.sensor.BasicNotificationSensor;
import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestApplicationImpl;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.core.test.entity.TestEntityImpl;
import org.apache.brooklyn.entity.java.JmxAttributeSensor;
@@ -89,7 +90,7 @@ import com.google.common.collect.Lists;
* TODO tests of other JMX_AGENT_MODE are done in ActiveMqIntegrationTest;
* would be nice to promote some to live here
*/
-public class JmxFeedTest {
+public class JmxFeedTest extends BrooklynAppUnitTestSupport {
// FIXME Move out the JmxHelper tests into the JmxHelperTest class
@@ -101,7 +102,6 @@ public class JmxFeedTest {
private static final int SHORT_WAIT_MS = 250;
private JmxService jmxService;
- private TestApplication app;
private TestEntity entity;
private JmxFeed feed;
private JmxHelper jmxHelper;
@@ -133,11 +133,13 @@ public class JmxFeedTest {
}
@BeforeMethod(alwaysRun=true)
+ @Override
public void setUp() throws Exception {
+ super.setUp();
+
jmxObjectName = new ObjectName(objectName);
// Create an entity and configure it with the above JMX service
- app = TestApplication.Factory.newManagedInstanceForTests();
entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class).additionalInterfaces(UsesJmx.class));
app.start(ImmutableList.of(new SimulatedLocation()));
@@ -148,11 +150,14 @@ public class JmxFeedTest {
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
- if (feed != null) feed.stop();
- if (jmxHelper != null) jmxHelper.disconnect();
- if (jmxService != null) jmxService.shutdown();
- if (app != null) Entities.destroyAll(app.getManagementContext());
- feed = null;
+ try {
+ if (feed != null) feed.stop();
+ if (jmxHelper != null) jmxHelper.disconnect();
+ if (jmxService != null) jmxService.shutdown();
+ feed = null;
+ } finally {
+ super.tearDown();
+ }
}
@Test
@@ -391,9 +396,9 @@ public class JmxFeedTest {
// Test reproduces functionality used in Monterey, for Venue entity being told of requestActor
@Test
public void testSubscribeToJmxNotificationAndEmitCorrespondingNotificationSensor() throws Exception {
- TestApplication app2 = new TestApplicationImpl();
- final EntityWithEmitter entity = new EntityWithEmitter(app2);
- Entities.startManagement(app2);
+ final TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
+ final EntityWithEmitter entity = app2.addChild(EntitySpec.create(EntityWithEmitter.class));
+
try {
app2.start(ImmutableList.of(new SimulatedLocation()));
@@ -428,19 +433,13 @@ public class JmxFeedTest {
Entities.destroyAll(app2.getManagementContext());
}
}
-
- public static class EntityWithEmitter extends AbstractEntity {
+
+ @ImplementedBy(EntityWithEmitterImpl.class)
+ public static interface EntityWithEmitter extends Entity {
public static final BasicNotificationSensor<String> MY_NOTIF = new BasicNotificationSensor<String>(String.class, "test.myNotif", "My notif");
-
- public EntityWithEmitter(Entity owner) {
- super(owner);
- }
- public EntityWithEmitter(Map flags) {
- super(flags);
- }
- public EntityWithEmitter(Map flags, Entity owner) {
- super(flags, owner);
- }
+ }
+
+ public static class EntityWithEmitterImpl extends AbstractEntity implements EntityWithEmitter {
}
private Notification sendNotification(StandardEmitterMBean mbean, String type, long seq, Object userData) {