You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/06/30 22:49:16 UTC
[1/2] git commit: Fixes
DynamicGroupTest.testGroupAddsAndRemovesManagedAndUnmanagedEntitiesExactlyOnce
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 79c8c404e -> 60a55767c
Fixes DynamicGroupTest.testGroupAddsAndRemovesManagedAndUnmanagedEntitiesExactlyOnce
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b992f79d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b992f79d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b992f79d
Branch: refs/heads/master
Commit: b992f79d1ae2a5b5bb645fd071ec323e6b6420e6
Parents: 1809b36
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon Jun 30 19:07:58 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Mon Jun 30 19:07:58 2014 +0100
----------------------------------------------------------------------
.../brooklyn/entity/basic/DynamicGroupTest.java | 55 +++++++++++++-------
1 file changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b992f79d/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java b/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java
index cd3ebdd..10a576e 100644
--- a/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DynamicGroupTest.java
@@ -29,11 +29,13 @@ import brooklyn.test.entity.TestApplication;
import brooklyn.test.entity.TestEntity;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.time.Duration;
import brooklyn.util.time.Time;
import com.google.common.base.Predicate;
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.collect.Sets;
@@ -219,19 +221,20 @@ public class DynamicGroupTest {
public void testGroupAddsAndRemovesManagedAndUnmanagedEntitiesExactlyOnce() throws Exception {
final int NUM_CYCLES = 100;
group.setEntityFilter(Predicates.instanceOf(TestEntity.class));
- final Set<TestEntity> entitiesNotified = Sets.newLinkedHashSet();
- final AtomicInteger notificationCount = new AtomicInteger(0);
+
+ final Set<TestEntity> entitiesNotified = Sets.newConcurrentHashSet();
+ final AtomicInteger addedNotifications = new AtomicInteger(0);
+ final AtomicInteger removedNotifications = new AtomicInteger(0);
final List<Exception> exceptions = new CopyOnWriteArrayList<Exception>();
app.subscribe(group, DynamicGroup.MEMBER_ADDED, new SensorEventListener<Entity>() {
public void onEvent(SensorEvent<Entity> event) {
try {
- LOG.debug("Notified of member added: member={}, thread={}", event.getValue(), Thread.currentThread().getName());
- Entity source = event.getSource();
- Object val = event.getValue();
+ TestEntity val = (TestEntity) event.getValue();
+ LOG.debug("Notified of member added: member={}, thread={}", val.getId(), Thread.currentThread().getName());
assertEquals(group, event.getSource());
- assertTrue(entitiesNotified.add((TestEntity)val));
- notificationCount.incrementAndGet();
+ assertTrue(entitiesNotified.add(val));
+ addedNotifications.incrementAndGet();
} catch (Throwable t) {
LOG.error("Error on event $event", t);
exceptions.add(new Exception("Error on event $event", t));
@@ -241,37 +244,49 @@ public class DynamicGroupTest {
app.subscribe(group, DynamicGroup.MEMBER_REMOVED, new SensorEventListener<Entity>() {
public void onEvent(SensorEvent<Entity> event) {
try {
- LOG.debug("Notified of member removed: member={}, thread={}", event.getValue(), Thread.currentThread().getName());
- Entity source = event.getSource();
- Object val = event.getValue();
+ TestEntity val = (TestEntity) event.getValue();
+ LOG.debug("Notified of member removed: member={}, thread={}", val.getId(), Thread.currentThread().getName());
assertEquals(group, event.getSource());
assertTrue(entitiesNotified.remove(val));
- notificationCount.incrementAndGet();
+ removedNotifications.incrementAndGet();
} catch (Throwable t) {
LOG.error("Error on event $event", t);
exceptions.add(new Exception("Error on event $event", t));
}
- }});
+ }
+ });
for (int i = 0; i < NUM_CYCLES; i++) {
- final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+ final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).id("entity-" + i));
+ LOG.debug("Created: entity {}", i);
Asserts.succeedsEventually(new Runnable() {
public void run() {
- entitiesNotified.contains(entity);
- }});
+ assertTrue(entitiesNotified.contains(entity));
+ }
+ });
+ LOG.debug("Contained in entitiesNotified: entity {}", i);
Entities.unmanage(entity);
+ LOG.debug("Unmanaged: entity {}", i);
}
- Asserts.succeedsEventually(new Runnable() {
+ Asserts.succeedsEventually(ImmutableMap.of("timeout", Duration.of(10, TimeUnit.SECONDS)), new Runnable() {
public void run() {
- assertTrue(notificationCount.get() == (NUM_CYCLES*2) || exceptions.size() > 0);
- }});
+ int added = addedNotifications.get(),
+ removed = removedNotifications.get(),
+ notifications = added + removed;
+ assertTrue(notifications == (NUM_CYCLES * 2) || exceptions.size() > 0,
+ "addedNotifications=" + added +
+ ", removedNotifications=" + removed +
+ ", cycles=" + NUM_CYCLES * 2 +
+ ", exceptions.size=" + exceptions.size());
+ }
+ });
- if (exceptions.size() > 0) {
+ if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
- assertEquals(notificationCount.get(), NUM_CYCLES*2);
+ assertEquals(removedNotifications.get() + addedNotifications.get(), NUM_CYCLES*2);
}
// The entityAdded/entityRemoved is now async for when member-entity is managed/unmanaged,
[2/2] git commit: This closes #32
Posted by al...@apache.org.
This closes #32
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/60a55767
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/60a55767
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/60a55767
Branch: refs/heads/master
Commit: 60a55767ce472931f4cdd6106e24d054c38409bc
Parents: 79c8c40 b992f79
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jun 30 21:49:02 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jun 30 21:49:02 2014 +0100
----------------------------------------------------------------------
.../brooklyn/entity/basic/DynamicGroupTest.java | 55 +++++++++++++-------
1 file changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------