brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/2] brooklyn-server git commit: BROOKLYN-284: fix deadlock in entity initialisation
Date Mon, 30 May 2016 14:28:04 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 5626d1d91 -> 0b7071cff


BROOKLYN-284: fix deadlock in entity initialisation

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8339fc60
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8339fc60
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8339fc60

Branch: refs/heads/master
Commit: 8339fc6061cff7f654970be5ecefc56d19827197
Parents: 4162971
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri May 27 21:29:13 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Sat May 28 14:19:27 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/core/entity/AbstractEntity.java      |  5 ++++-
 .../brooklyn/core/entity/EntityTypeTest.java      | 18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8339fc60/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index bde505c..62a4bf8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -1580,7 +1580,10 @@ public abstract class AbstractEntity extends AbstractBrooklynObject
implements E
     }
     
     @Override
-    public synchronized ExecutionContext getExecutionContext() {
+    public ExecutionContext getExecutionContext() {
+        // NB May 2016 - removed synch keyword above due to deadlock (see https://issues.apache.org/jira/browse/BROOKLYN-284).
+        // As with getManagementContext(), it also synchs in ManagementSupport.getExecutionContext();
+        // no apparent reason why it was here also.
         return getManagementSupport().getExecutionContext();
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8339fc60/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 641f97b2..c6e3936 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
@@ -264,7 +264,7 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
     }
     
     // Previously EntityDynamicType's constructor when passed `entity` during the entity's
construction (!)
-    // would pass this to EntityDynamicType.findEffectors, which would do log.warn in some
cirumstances,
+    // would pass this to EntityDynamicType.findEffectors, which would do log.warn in some
circumstances,
     // with entity.toString as part of the log message. But if the toString called getConfig()
this would 
     // fail because we were still in the middle of constructing the entity.entityType!
     @Test
@@ -272,7 +272,21 @@ public class EntityTypeTest extends BrooklynAppUnitTestSupport {
         entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(EntityWithToStringAccessingConfig.class));
         entity.toString();
     }
-    
+
+    /**
+     * Previously this deadlocked when calling toString() during entity initialisation (but
only if the config key
+     * had a value - this would trigger a call by EntityConfigMap.getConfig() to getExecutionContext).
+     * 
+     * See https://issues.apache.org/jira/browse/BROOKLYN-284
+     */
+    @Test
+    public void testEntityDoesNotCallToStringDuringConstruction() throws Exception {
+        entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                .impl(EntityWithToStringAccessingConfig.class)
+                .configure(TestEntity.CONF_NAME, "myval"));
+        entity.toString();
+    }
+
     public static class EntityWithToStringAccessingConfig extends TestEntityImpl {
         
         // to cause warning to be logged: non-static constant


Mime
View raw message