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 2017/10/28 10:03:00 UTC

[6/7] brooklyn-server git commit: Make testPersistsSingleCopyOfInitialCatalogOnHotStandbyPromotion more robust

Make testPersistsSingleCopyOfInitialCatalogOnHotStandbyPromotion more robust


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

Branch: refs/heads/master
Commit: 8a2d51eadac445d24e4b3b05b55b6c0478d0a058
Parents: 03f254f
Author: Aled Sage <al...@gmail.com>
Authored: Fri Oct 27 16:54:45 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Oct 27 20:44:54 2017 +0100

----------------------------------------------------------------------
 .../BrooklynLauncherRebindCatalogOsgiTest.java  | 25 ++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8a2d51ea/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
index e953c8d..e9c7a07 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -26,6 +26,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -33,6 +34,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
 import org.apache.brooklyn.api.objs.BrooklynObjectType;
+import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
 import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
@@ -42,6 +44,7 @@ import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.core.osgi.Osgis;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.exceptions.ReferenceWithError;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
@@ -527,6 +530,8 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
 
         // Second launcher goes into hot-standby, and will thus rebind periodically.
         // When we terminate the first launcher, it will be promoted to master automatically.
+        // However, we'll say state="master" before we've fully initialised, so need to use
+        // assert-eventually.
         BrooklynLauncher launcher2 = newLauncherForTests(initialBomFile.getAbsolutePath())
                 .highAvailabilityMode(HighAvailabilityMode.HOT_STANDBY);
         launcher2.start();
@@ -534,9 +539,25 @@ public class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBrooklynLaunc
         
         launcher.terminate();
         assertMasterEventually(launcher2);
-        String bundlePersistenceId2 = findManagedBundle(launcher2, bundleName).getId();
+        assertPersistedBundleListingEqualsEventually(launcher2, ImmutableSet.of(bundleName));
         launcher2.terminate();
-        assertEquals(getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE), ImmutableSet.of(bundlePersistenceId2));
+    }
+    
+    private void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) {
+        Asserts.succeedsEventually(new Runnable() {
+            @Override public void run() {
+                try {
+                    Set<String> expected = new LinkedHashSet<>();
+                    for (VersionedName bundle : bundles) {
+                        String bundleUid = findManagedBundle(launcher, bundle).getId();
+                        expected.add(bundleUid);
+                    }
+                    Set<String> persisted = getPersistenceListing(BrooklynObjectType.MANAGED_BUNDLE); 
+                    assertEquals(persisted, expected);
+                } catch (Exception e) {
+                    throw Exceptions.propagate(e);
+                }
+            }});
     }
 
     private void assertHotStandbyEventually(BrooklynLauncher launcher) {