You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2015/06/23 14:26:28 UTC
[12/16] incubator-brooklyn git commit: Ignore entity.addFeed(...)
call with same feed object
Ignore entity.addFeed(...) call with same feed object
Adding the same feed object a second time would stop it, ignore the call instead. Adding the same object twice is very common when FEATURE_FEED_REGISTRATION_PROPERTY is enabled, because blueprints already add it manually.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b3c9e71e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b3c9e71e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b3c9e71e
Branch: refs/heads/master
Commit: b3c9e71e8c3bc162c5ad09bd5353e7e4fa3e0788
Parents: 79cb98c
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Mon Jun 22 18:54:04 2015 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Jun 23 14:00:27 2015 +0300
----------------------------------------------------------------------
.../brooklyn/entity/basic/AbstractEntity.java | 14 +++++++--
.../event/feed/function/FunctionFeedTest.java | 33 ++++++++++++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b3c9e71e/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
index 27311a1..507900a 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
@@ -84,7 +84,6 @@ import brooklyn.policy.PolicySpec;
import brooklyn.policy.basic.AbstractEntityAdjunct;
import brooklyn.policy.basic.AbstractEntityAdjunct.AdjunctTagSupport;
import brooklyn.policy.basic.AbstractPolicy;
-import brooklyn.util.BrooklynLanguageExtensions;
import brooklyn.util.collections.MutableList;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.collections.MutableSet;
@@ -1509,6 +1508,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
/**
* Convenience, which calls {@link EntityInternal#feeds()} and {@link FeedSupport#addFeed(Feed)}.
*/
+ @Override
public <T extends Feed> T addFeed(T feed) {
return feeds().addFeed(feed);
}
@@ -1534,8 +1534,16 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
public <T extends Feed> T addFeed(T feed) {
Feed old = findApparentlyEqualAndWarnIfNotSameUniqueTag(feeds, feed);
if (old != null) {
- LOG.debug("Removing "+old+" when adding "+feed+" to "+this);
- removeFeed(old);
+ if (old == feed) {
+ if (!BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY)) {
+ LOG.debug("Feed " + feed + " already added, not adding a second time.");
+ } // else expected to be added a second time through addFeed, ignore
+ return feed;
+ } else {
+ // Different feed object with (seemingly) same functionality, remove previous one, will stop it.
+ LOG.debug("Removing "+old+" when adding "+feed+" to "+this);
+ removeFeed(old);
+ }
}
CatalogUtils.setCatalogItemIdOnAddition(AbstractEntity.this, feed);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b3c9e71e/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java b/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
index 1b67b8b..468239b 100644
--- a/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
+++ b/core/src/test/java/brooklyn/event/feed/function/FunctionFeedTest.java
@@ -19,6 +19,7 @@
package brooklyn.event.feed.function;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import java.util.List;
@@ -98,6 +99,7 @@ public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
.build();
Asserts.succeedsEventually(new Runnable() {
+ @Override
public void run() {
Integer val = entity.getAttribute(SENSOR_INT);
assertTrue(val != null && val > 2, "val=" + val);
@@ -128,6 +130,15 @@ public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
}
@Test
+ public void testFeedDeDupeIgnoresSameObject() throws Exception {
+ testPollsFunctionRepeatedlyToSetAttribute();
+ entity.addFeed(feed);
+ assertFeedIsPolling();
+ entity.addFeed(feed);
+ assertFeedIsPollingContinuously();
+ }
+
+ @Test
public void testCallsOnSuccessWithResultOfCallable() throws Exception {
feed = FunctionFeed.builder()
.entity(entity)
@@ -153,6 +164,7 @@ public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
.build();
Asserts.succeedsEventually(new Runnable() {
+ @Override
public void run() {
String val = entity.getAttribute(SENSOR_STRING);
assertTrue(val != null && val.contains(errMsg), "val=" + val);
@@ -217,6 +229,7 @@ public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
.build();
Asserts.succeedsEventually(new Runnable() {
+ @Override
public void run() {
assertEquals(ints.subList(0, 2), ImmutableList.of(0, 1));
assertTrue(strings.size()>=2, "wrong strings list: "+strings);
@@ -248,6 +261,26 @@ public class FunctionFeedTest extends BrooklynAppUnitTestSupport {
.onFailureOrException(Functions.<Integer>constant(null));
}
+
+ private void assertFeedIsPolling() {
+ final Integer val = entity.getAttribute(SENSOR_INT);
+ Asserts.succeedsEventually(new Runnable() {
+ @Override
+ public void run() {
+ assertNotEquals(val, entity.getAttribute(SENSOR_INT));
+ }
+ });
+ }
+
+ private void assertFeedIsPollingContinuously() {
+ Asserts.succeedsContinually(new Runnable() {
+ @Override
+ public void run() {
+ assertFeedIsPolling();
+ }
+ });
+ }
+
private static class IncrementingCallable implements Callable<Integer> {
private final AtomicInteger next = new AtomicInteger(0);