fix ordering of catalog lookup, and tidy naming of tests for rebind with catalog upgrades
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b539605f Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b539605f Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b539605f Branch: refs/heads/master Commit: b539605ff4b1ad313812fef81fe326de8478e31e Parents: 305df9c Author: Alex Heneveld <[email protected]> Authored: Mon Oct 30 15:56:58 2017 +0000 Committer: Alex Heneveld <[email protected]> Committed: Mon Oct 30 15:56:58 2017 +0000 ---------------------------------------------------------------------- .../core/typereg/BasicBrooklynTypeRegistry.java | 7 ++- .../BrooklynLauncherRebindCatalogOsgiTest.java | 52 +++++++++++++------- 2 files changed, 40 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b539605f/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java index 46d3400..dd0b4b9 100644 --- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java +++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java @@ -43,6 +43,7 @@ import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder; import org.apache.brooklyn.core.catalog.internal.CatalogUtils; import org.apache.brooklyn.core.mgmt.ha.OsgiManager; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.core.typereg.RegisteredTypes.RegisteredTypeNameThenBestFirstComparator; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.collections.MutableSet; @@ -50,6 +51,7 @@ import org.apache.brooklyn.util.concurrent.Locks; import org.apache.brooklyn.util.exceptions.Exceptions; import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.osgi.VersionedName; +import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator; import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator; import org.apache.brooklyn.util.text.BrooklynVersionSyntax; import org.apache.brooklyn.util.text.Identifiers; @@ -93,9 +95,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry { private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? super RegisteredType> filter) { // TODO optimisation? make indexes and look up? + Ordering<RegisteredType> typeOrder = Ordering.from(RegisteredTypeNameThenBestFirstComparator.INSTANCE); return Locks.withLock(localRegistryLock.readLock(), () -> localRegisteredTypesAndContainingBundles.values().stream(). - flatMap(m -> m.values().stream()).filter(filter::apply).collect(Collectors.toList()) ); + flatMap(m -> { return typeOrder.sortedCopy(m.values()).stream(); }).filter(filter::apply).collect(Collectors.toList()) ); } private Maybe<RegisteredType> getExactWithoutLegacyCatalog(String symbolicName, String version, RegisteredTypeLoadingContext constraint) { @@ -109,7 +112,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry { if (m.isEmpty()) return null; if (m.size()==1) return m.values().iterator().next(); // get the highest version of first alphabetical - to have a canonical order - return m.get( Ordering.from(VersionedNameStringComparator.INSTANCE).max(m.keySet()) ); + return m.get( Ordering.from(VersionedNameStringComparator.INSTANCE).min(m.keySet()) ); } @SuppressWarnings("deprecation") http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b539605f/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 b2e4484..e925b33 100644 --- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java +++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java @@ -416,7 +416,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo } @Test - public void testRebindUpgradesBundleWithSameItems() throws Exception { + public void testRestartWithNewBundleWithSameItemsReplacesItems() throws Exception { Set<VersionedName> bundleItems = ImmutableSet.of(VersionedName.fromString("one:1.0.0")); String bundleBom = createCatalogYaml(ImmutableList.of(), bundleItems); @@ -431,13 +431,30 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo startupAssertions = () -> { assertCatalogConsistsOfIds(launcherLast, bundleItems); assertManagedBundle(launcherLast, bundleNameV1, bundleItems); + + String bundleVersionSupplyingType = getBundleSupplyingFirstType(bundleItems); + if (launcherT2==null) { + Assert.assertEquals(bundleVersionSupplyingType, "1.0.0"); + + } else { + assertManagedBundle(launcherLast, bundleNameV2, bundleItems); + getBundleSupplyingFirstType(bundleItems); + Assert.assertEquals(bundleVersionSupplyingType, "2.0.0"); + } }; startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath())); startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath())); + assertManagedBundle(launcherLast, bundleNameV2, bundleItems); + promoteT2IfStandby(); + } + + protected String getBundleSupplyingFirstType(Set<VersionedName> bundleItems) { + return VersionedName.fromString( launcherLast.getManagementContext().getTypeRegistry().get( + bundleItems.iterator().next().toString() ).getContainingBundle() ).getVersionString(); } @Test - public void testRebindUpgradesBundleWithNewerItems() throws Exception { + public void testRestartWithNewBundleWithNewItemsAddsItems() throws Exception { Set<VersionedName> bundleItemsV1 = ImmutableSet.of(VersionedName.fromString("one:1.0.0")); String bundleBomV1 = createCatalogYaml(ImmutableList.of(), bundleItemsV1); VersionedName bundleNameV1 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog", "1.0.0"); @@ -450,17 +467,20 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo File bundleFileV2 = newTmpBundle(ImmutableMap.of(BasicBrooklynCatalog.CATALOG_BOM, bundleBomV2.getBytes(StandardCharsets.UTF_8)), bundleNameV2); File initialBomFileV2 = newTmpFile(createCatalogYaml(ImmutableList.of(bundleFileV2.toURI()), ImmutableList.of())); - startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath())); - - assertCatalogConsistsOfIds(launcherLast, bundleItemsV1); - assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1); - // above for T1 should become the following for T2 startupAssertions = () -> { - assertCatalogConsistsOfIds(launcherLast, Iterables.concat(bundleItemsV1, bundleItemsV2)); assertManagedBundle(launcherLast, bundleNameV1, bundleItemsV1); - assertManagedBundle(launcherLast, bundleNameV2, bundleItemsV2); + Assert.assertEquals(getBundleSupplyingFirstType(bundleItemsV1), "1.0.0"); + if (launcherT2==null) { + assertCatalogConsistsOfIds(launcherLast, bundleItemsV1); + + } else { + assertCatalogConsistsOfIds(launcherLast, Iterables.concat(bundleItemsV1, bundleItemsV2)); + + assertManagedBundle(launcherLast, bundleNameV2, bundleItemsV2); + Assert.assertEquals(getBundleSupplyingFirstType(bundleItemsV2), "2.0.0"); + } }; - + startT1(newLauncherForTests(initialBomFileV1.getAbsolutePath())); startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath())); promoteT2IfStandby(); } @@ -584,13 +604,11 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo } } - // TODO tests: - // TODO remove on hot standby promotion (above), succeed and failing - // TODO deploy blueprint with old item after upgrade - // TODO rebind upgrade item deployed - // TODO rebind upgrade spec item in deployment - // TODO deploy mention of old item after upgrade - // TODO upgrade on hot standby and promotion + // TODO removed item in deployment fails - rebind and upgrade uses new item + // TODO removed item in deployment upgrades - rebind and upgrade uses new item + // TODO removed item in spec fails + // TODO removed item in spec upgrades + // TODO removed item deployed after rebind protected void assertPersistedBundleListingEqualsEventually(BrooklynLauncher launcher, Set<VersionedName> bundles) { Asserts.succeedsEventually(new Runnable() {
