You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2020/10/01 23:16:13 UTC

[brooklyn-server] 03/10: fix remaining tests for OSGi

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 5b4e67064b96f26ebb32dc7d0c8bc42ca3519b11
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Thu Oct 1 16:01:56 2020 +0100

    fix remaining tests for OSGi
    
    ensure constraints passed including when resolving
---
 .../brooklyn/catalog/CatalogYamlEntityTest.java     |  6 ++----
 .../core/catalog/internal/BasicBrooklynCatalog.java | 21 ++++++++++++++++-----
 .../core/typereg/RegisteredTypeLoadingContexts.java | 11 ++++++++++-
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
index 12edf35..6f52053 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
@@ -368,7 +368,6 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
     public void testLaunchApplicationChildLoopCatalogIdFails() throws Exception {
         String referrerSymbolicName = "my.catalog.app.id.child.referring";
         try {
-            // TODO only fails if using 'services', because that forces plan parsing; should fail in all cases
             addCatalogItems(
                     "brooklyn.catalog:",
                     "  id: " + referrerSymbolicName,
@@ -386,11 +385,10 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
         }
     }
 
-    @Test(groups="WIP")
-    public void testLaunchApplicationChildLoopCatalogIdFailsWithNewSyntax() throws Exception {
+    @Test
+    public void testLaunchApplicationChildLoopCatalogIdFailsWithTypeSyntax() throws Exception {
         String referrerSymbolicName = "my.catalog.app.id.child.referring";
         try {
-            // TODO previous test using 'services' fails nicely, but this doesn't; it throws an SO exception, doesn't see the cyclic dependency
             addCatalogItems(
                     "brooklyn.catalog:",
                     "  id: " + referrerSymbolicName,
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index ea8efab..d1d75c9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -740,7 +740,8 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         }
 
         PlanInterpreterInferringType planInterpreter = new PlanInterpreterInferringType(id, item, sourceYaml, itemType, format,
-                (containingBundle instanceof CatalogBundle ? ((CatalogBundle)containingBundle) : null), libraryBundles, resultLegacyFormat).resolve();
+                (containingBundle instanceof CatalogBundle ? ((CatalogBundle)containingBundle) : null), libraryBundles,
+                null, resultLegacyFormat).resolve();
         Exception resolutionError = null;
         if (!planInterpreter.isResolved()) {
             // don't throw yet, we may be able to add it in an unresolved state
@@ -1216,7 +1217,8 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         final CatalogBundle containingBundle;
         final Collection<CatalogBundle> libraryBundles;
         final List<CatalogItemDtoAbstract<?, ?>> itemsDefinedSoFar;
-        
+        RegisteredTypeLoadingContext constraint;
+
         CatalogItemType catalogItemType;
         String planYaml;
         boolean resolved = false;
@@ -1225,11 +1227,14 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         List<Exception> transformerErrors = MutableList.of();
 
         public PlanInterpreterInferringType(@Nullable String itemId, Object itemDefinitionParsedToStringOrMap, String itemYaml, @Nullable CatalogItemType optionalCiType, @Nullable String format,
-                                            CatalogBundle containingBundle, Collection<CatalogBundle> libraryBundles, List<CatalogItemDtoAbstract<?,?>> itemsDefinedSoFar) {
+                                            CatalogBundle containingBundle, Collection<CatalogBundle> libraryBundles,
+                                            RegisteredTypeLoadingContext constraint, List<CatalogItemDtoAbstract<?,?>> itemsDefinedSoFar) {
             // ID is useful to prevent recursive references (possibly only supported for entities?)
             this.itemId = itemId;
             this.containingBundle = containingBundle;
 
+            this.constraint = constraint;
+
             if (itemDefinitionParsedToStringOrMap instanceof String) {
                 if (((String)itemDefinitionParsedToStringOrMap).trim().indexOf("\n")<0) {
                     // if just a one-line string supplied, treat at type unless it parses as a map
@@ -1345,8 +1350,14 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                     }
                 }
 
+                if (constraint==null) {
+                    constraint = RegisteredTypeLoadingContexts.loaderAlreadyEncountered(loader, null, itemId);
+                } else {
+                    constraint = RegisteredTypeLoadingContexts.withLoader(constraint, loader);
+                    constraint = RegisteredTypeLoadingContexts.withEncounteredItem(constraint, itemId);
+                }
+
                 Object t = null;
-                RegisteredTypeLoadingContext constraint = RegisteredTypeLoadingContexts.loader(loader);
                 if (catalogItemType == CatalogItemType.BEAN || suspicionOfABean) {
                     try {
                         t = mgmt.getTypeRegistry().createBeanFromPlan(format, itemYaml, constraint, null);
@@ -1854,7 +1865,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             }
             String format = typeToValidate.getPlan().getPlanFormat();
             PlanInterpreterInferringType guesser = new PlanInterpreterInferringType(typeToValidate.getSymbolicName(), Iterables.getOnlyElement( Yamls.parseAll(yaml) ),
-                yaml, itemType, format, bundle, CatalogItemDtoAbstract.parseLibraries( typeToValidate.getLibraries() ), null);
+                yaml, itemType, format, bundle, CatalogItemDtoAbstract.parseLibraries( typeToValidate.getLibraries() ), constraint, null);
             guesser.resolve();
             guesserErrors.addAll(guesser.getErrors());
             
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
index 7eab626..b7a485d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeLoadingContexts.java
@@ -229,11 +229,20 @@ public class RegisteredTypeLoadingContexts {
         result.loader = loader;
         return result;
     }
-    
+
     public static RegisteredTypeLoadingContext withLoader(RegisteredTypeLoadingContext constraint, BrooklynClassLoadingContext loader) {
         BasicRegisteredTypeLoadingContext result = new BasicRegisteredTypeLoadingContext(constraint);
         result.loader = loader;
         return result;
     }
 
+    public static RegisteredTypeLoadingContext withEncounteredItem(RegisteredTypeLoadingContext constraint, String itemId) {
+        if (constraint.getAlreadyEncounteredTypes().contains(itemId)) {
+            return constraint;
+        }
+        BasicRegisteredTypeLoadingContext result = new BasicRegisteredTypeLoadingContext(constraint);
+        result.encounteredTypes = ImmutableSet.<String>builder().addAll(constraint.getAlreadyEncounteredTypes()).add(itemId).build();
+        return result;
+    }
+
 }