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


The following commit(s) were added to refs/heads/master by this push:
     new 341b48f  tidy blueprint test / launcher startup process
341b48f is described below

commit 341b48fe03ec07fcc6b7814904aec3b32457b69c
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Jul 30 12:24:35 2021 +0100

    tidy blueprint test / launcher startup process
    
    persistence was started in two places, now be more forgiving
---
 .../brooklyn/launcher/common/BasicLauncher.java    | 12 +++++-
 .../camp/BrooklynCampPlatformLauncher.java         | 17 ++++++--
 .../brooklyn/launcher/BrooklynViewerLauncher.java  | 15 ++++++-
 .../launcher/blueprints/AbstractBlueprintTest.java | 49 +++++++++++++++++-----
 .../launcher/blueprints/SimpleBlueprintTest.java   | 35 ++++++++++++++++
 5 files changed, 110 insertions(+), 18 deletions(-)

diff --git 
a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java
 
b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java
index 71648a1..bb70594 100644
--- 
a/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java
+++ 
b/launcher-common/src/main/java/org/apache/brooklyn/launcher/common/BasicLauncher.java
@@ -512,8 +512,16 @@ public class BasicLauncher<T extends BasicLauncher<T>> {
 
     protected void handlePersistence() {
         try {
-            initPersistence();
-            startPersistence();
+            if (managementContext.getRebindManager().getPersister()!=null) {
+                LOG.debug("Persister already initialized by mgmt context; 
skipping from launcher");
+                // call below will fail if persister already set eg by 
RebindTestUtils
+                if (!(((RebindManagerImpl) 
managementContext.getRebindManager()).isPersistenceRunning())) {
+                    throw new IllegalStateException("Persistence was 
initialized but not running, prior to launcher");
+                }
+            } else {
+                initPersistence();
+                startPersistence();
+            }
         } catch (Exception e) {
             handleSubsystemStartupError(ignorePersistenceErrors, 
"persistence", e);
         }
diff --git 
a/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
 
b/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
index 9c50562..a983087 100644
--- 
a/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
+++ 
b/launcher/src/main/java/org/apache/brooklyn/launcher/camp/BrooklynCampPlatformLauncher.java
@@ -40,25 +40,34 @@ public class BrooklynCampPlatformLauncher extends 
BrooklynCampPlatformLauncherAb
     public BrooklynCampPlatformLauncher launch() {
         assert platform == null;
 
-        mgmt = newManagementContext();
+        mgmt = getManagementContextForLauncher();
         
         // We created the management context, so we are responsible for 
terminating it
         BrooklynShutdownHooks.invokeTerminateOnShutdown(mgmt);
 
-        brooklynLauncher = 
BrooklynLauncher.newInstance().managementContext(mgmt).start();
+        brooklynLauncher = getBrooklynLauncherStarted(mgmt);
         platform = new BrooklynCampPlatform(
                 PlatformRootSummary.builder().name("Brooklyn CAMP 
Platform").build(),
-                mgmt).setConfigKeyAtManagmentContext();
+                mgmt)
+                .setConfigKeyAtManagmentContext();
         
         campServer = new CampServer(getCampPlatform(), "").start();
         
         return this;
     }
-    
+
+    protected BrooklynLauncher getBrooklynLauncherStarted(ManagementContext 
mgmt) {
+        return BrooklynLauncher.newInstance().managementContext(mgmt).start();
+    }
+
     protected ManagementContext newManagementContext() {
         return new LocalManagementContext();
     }
 
+    protected ManagementContext getManagementContextForLauncher() {
+        return newManagementContext();
+    }
+
     public static void main(String[] args) {
         new BrooklynCampPlatformLauncher().launch();
     }
diff --git 
a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
 
b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
index 8672916..a06a0de 100644
--- 
a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
+++ 
b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynViewerLauncher.java
@@ -67,15 +67,26 @@ public class BrooklynViewerLauncher extends 
BrooklynLauncher {
         if (started) throw new IllegalStateException("Cannot start() or 
launch() multiple times");
         started = true;
 
+        startViewer();
+
+        return this;
+    }
+
+    protected void startViewer() {
         if (getManagementContext() == null || 
!getManagementContext().isRunning()) {
             throw new IllegalStateException("Management context must be set, 
and running");
         }
-        
+
         startingUp();
         markStartupComplete();
-        
+
         initBrooklynNode();
+    }
 
+    public BrooklynLauncher startBrooklynAndViewer() {
+        super.start();
+        startViewer();
         return this;
     }
+
 }
diff --git 
a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
 
b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
index ef3c0e7..23a3e94 100644
--- 
a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
+++ 
b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/AbstractBlueprintTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.launcher.blueprints;
 
+import java.util.function.Consumer;
+import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import static org.testng.Assert.assertNotEquals;
 import static org.testng.Assert.assertTrue;
 
@@ -65,7 +67,7 @@ public abstract class AbstractBlueprintTest {
     
     protected ManagementContext mgmt;
     protected SimpleYamlLauncherForTests launcher;
-    protected BrooklynLauncher viewer;
+    protected BrooklynViewerLauncher viewer;
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
@@ -78,15 +80,26 @@ public abstract class AbstractBlueprintTest {
             protected BrooklynCampPlatformLauncherAbstract 
newPlatformLauncher() {
                 return new BrooklynCampPlatformLauncher() {
                     @Override
-                    protected ManagementContext newManagementContext() {
+                    protected ManagementContext 
getManagementContextForLauncher() {
                         return AbstractBlueprintTest.this.mgmt;
                     }
+
+                    @Override
+                    protected BrooklynLauncher 
getBrooklynLauncherStarted(ManagementContext mgmt) {
+                        if (viewer!=null) {
+                            throw new IllegalStateException("Viewer already 
running");
+                        }
+                        viewer = BrooklynViewerLauncher.newInstance();
+                        viewer.managementContext(mgmt);
+
+                        // other persistence options come from mgmt console 
but launcher needs to know this:
+                        viewer.persistMode(PersistMode.AUTO);
+
+                        return viewer.startBrooklynAndViewer();
+                    }
                 };
             }
         };
-        viewer = BrooklynViewerLauncher.newInstance()
-                .managementContext(mgmt)
-                .start();
     }
 
     @AfterMethod(alwaysRun=true)
@@ -141,13 +154,29 @@ public abstract class AbstractBlueprintTest {
         }
     }
     
-    protected void runTest(String yamlFile) throws Exception {
-        final Application app = launcher.launchAppYaml(yamlFile);
-        
-        assertNoFires(app);
+    protected Application runTest(String yamlFile) throws Exception {
+        return runTestOnFile(yamlFile);
+    }
+
+    protected Application runTestOnFile(String yamlFile) throws Exception {
+        return runTest(launcher.launchAppYaml(yamlFile));
+    }
+
+    protected Application runTestOnBlueprint(String blueprint) throws 
Exception {
+        return runTest(launcher.launchAppYaml(new StringReader(blueprint)));
+    }
+
+    protected Application runTest(Application app) throws Exception {
+        return runTest(app, this::assertNoFires);
+    }
+
+    protected Application runTest(Application app, Consumer<Application> 
check) throws Exception {
+        check.accept(app);
         
         Application newApp = rebind();
-        assertNoFires(newApp);
+        check.accept(newApp);
+
+        return app;
     }
     
     protected void runTest(Reader yaml) throws Exception {
diff --git 
a/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
 
b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
new file mode 100644
index 0000000..0ac668c
--- /dev/null
+++ 
b/launcher/src/test/java/org/apache/brooklyn/launcher/blueprints/SimpleBlueprintTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.launcher.blueprints;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.core.entity.Dumper;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.testng.annotations.Test;
+
+public class SimpleBlueprintTest extends AbstractBlueprintTest {
+
+    // only Live because it starts a server
+    @Test(groups={"Live"})
+    public void testBasicEntity() throws Exception {
+        Application app = runTestOnBlueprint("services: [ { type: " + 
BasicEntity.class.getName() + " } ]");
+        Dumper.dumpInfo(app);
+    }
+
+}

Reply via email to