brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] brooklyn-server git commit: BROOKLYN-599: fix getApplication()
Date Thu, 06 Sep 2018 09:40:57 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 7c3f49187 -> 6dafb3fae


BROOKLYN-599: fix getApplication()


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

Branch: refs/heads/master
Commit: 25de68863a98b8c66450e134ff758240b110e13b
Parents: 7c3f491
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Sep 6 10:02:47 2018 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Sep 6 10:04:45 2018 +0100

----------------------------------------------------------------------
 .../brooklyn/core/entity/AbstractEntity.java    |  2 +-
 .../brooklyn/core/mgmt/DeployFailureTest.java   | 69 ++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/25de6886/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 53630d9..fa7cecd 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
@@ -743,7 +743,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements
E
     @Override
     public Application getApplication() {
         if (application != null) return application;
-        Entity parent = getParent();
+        Entity parent = this.parent.get();
         Application app = (parent != null) ? parent.getApplication() : null;
         if (app != null) {
             if (getManagementSupport().isFullyManaged())

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/25de6886/core/src/test/java/org/apache/brooklyn/core/mgmt/DeployFailureTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/DeployFailureTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/DeployFailureTest.java
new file mode 100644
index 0000000..f5a1de5
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/DeployFailureTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mgmt;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.mgmt.internal.LocalEntityManager;
+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.stock.BasicApplication;
+import org.apache.brooklyn.test.Asserts;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class DeployFailureTest extends BrooklynAppUnitTestSupport {
+
+    private LocalEntityManager entityManager;
+    
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        entityManager = (LocalEntityManager) mgmt.getEntityManager();
+    }
+    
+    @Test
+    public void testFailedGetParent() throws Exception {
+        entityManager.getAllEntitiesInApplication(app);
+
+        try {
+            mgmt.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)
+                    .child(EntitySpec.create(TestEntity.class)
+                            .impl(TestEntityFailingGetParentImpl.class)));
+            Asserts.shouldHaveFailedPreviously();
+        } catch (ClassCastException e) {
+            Asserts.expectedFailureContains(e, "cannot be cast", "WrongParentEntity");
+        }
+
+        // This should continue to work, after the failed entity-deploy above
+        // See https://issues.apache.org/jira/browse/BROOKLYN-599
+        entityManager.getAllEntitiesInApplication(app);
+    }
+
+    public static class TestEntityFailingGetParentImpl extends TestEntityImpl {
+        private static interface WrongParentEntity extends Entity {}
+        
+        @Override
+        public WrongParentEntity getParent() {
+            return (WrongParentEntity) super.getParent();
+        }
+    }
+}


Mime
View raw message