Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2DC1F18CAA for ; Fri, 18 Mar 2016 11:06:23 +0000 (UTC) Received: (qmail 15160 invoked by uid 500); 18 Mar 2016 11:06:23 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 15124 invoked by uid 500); 18 Mar 2016 11:06:23 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 15077 invoked by uid 99); 18 Mar 2016 11:06:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Mar 2016 11:06:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DBCA8DFD5B; Fri, 18 Mar 2016 11:06:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heneveld@apache.org To: commits@brooklyn.apache.org Date: Fri, 18 Mar 2016 11:06:24 -0000 Message-Id: <0e198e6301ff46c189f2656041a6d445@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/18] brooklyn-server git commit: add more tests for the number of locations being managed add more tests for the number of locations being managed including a failing test for the case where a blueprint added to catalog includes a location Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/40fd76d8 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/40fd76d8 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/40fd76d8 Branch: refs/heads/master Commit: 40fd76d8124b4f570082f72d3c576b2db05dedf1 Parents: bcf4d9b Author: Alex Heneveld Authored: Tue Mar 15 12:10:55 2016 +0000 Committer: Alex Heneveld Committed: Tue Mar 15 12:10:55 2016 +0000 ---------------------------------------------------------------------- .../camp/brooklyn/LocationsYamlTest.java | 2 +- .../catalog/CatalogYamlLocationTest.java | 64 ++++++++++++++++++++ .../core/location/LocationManagementTest.java | 37 +++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40fd76d8/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java ---------------------------------------------------------------------- diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java index 371a477..f1efd33 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java @@ -281,5 +281,5 @@ public class LocationsYamlTest extends AbstractYamlTest { protected Logger getLogger() { return log; } - + } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40fd76d8/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java ---------------------------------------------------------------------- diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java index f792d65..cd1e917 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java @@ -36,8 +36,11 @@ import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; import org.apache.brooklyn.core.typereg.RegisteredTypePredicates; import org.apache.brooklyn.core.typereg.RegisteredTypes; +import org.apache.brooklyn.entity.stock.BasicEntity; import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; +import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.test.support.TestResourceUnavailableException; +import org.apache.brooklyn.util.collections.CollectionFunctionals; import org.apache.brooklyn.util.text.StringFunctions; import org.testng.Assert; import org.testng.annotations.AfterMethod; @@ -250,4 +253,65 @@ public class CatalogYamlLocationTest extends AbstractYamlTest { return Iterables.size(mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION)); } + @Test + public void testManagedLocationsCreateAndCleanup() { + assertLocationRegistryCount(0); + assertLocationManagerInstancesCount(0); + assertCatalogCount(0); + + String symbolicName = "lh1"; + addCatalogLocation(symbolicName, LOCALHOST_LOCATION_TYPE, null); + + assertLocationRegistryCount(1); + assertCatalogCount(1); + assertLocationManagerInstancesCount(0); + + Location loc = mgmt().getLocationRegistry().resolve("lh1"); + + assertLocationRegistryCount(1); + assertCatalogCount(1); + assertLocationManagerInstancesCount(1); + + mgmt().getLocationManager().unmanage(loc); + + + assertLocationRegistryCount(1); + assertCatalogCount(1); + assertLocationManagerInstancesCount(0); + + deleteCatalogEntity("lh1"); + + assertLocationRegistryCount(0); + assertCatalogCount(0); + assertLocationManagerInstancesCount(0); + } + + private void assertLocationRegistryCount(int size) { + Asserts.assertThat(mgmt().getLocationRegistry().getDefinedLocations().keySet(), CollectionFunctionals.sizeEquals(size)); + } + private void assertLocationManagerInstancesCount(int size) { + Asserts.assertThat(mgmt().getLocationManager().getLocations(), CollectionFunctionals.sizeEquals(size)); + } + private void assertCatalogCount(int size) { + Asserts.assertThat(mgmt().getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(size)); + } + + @Test + public void testLocationPartOfBlueprintDoesntLeak() { + String symbolicName = "my.catalog.app.id.load"; + addCatalogItems( + "brooklyn.catalog:", + " id: " + symbolicName, + " version: " + TEST_VERSION, + " item:", + " type: "+ BasicEntity.class.getName(), + " location:", + " jclouds:aws-ec2: { identity: ignore, credential: ignore }" + ); + + assertLocationRegistryCount(0); + assertCatalogCount(1); + assertLocationManagerInstancesCount(0); + } + } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/40fd76d8/core/src/test/java/org/apache/brooklyn/core/location/LocationManagementTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/location/LocationManagementTest.java b/core/src/test/java/org/apache/brooklyn/core/location/LocationManagementTest.java index d2929ca..91b8da4 100644 --- a/core/src/test/java/org/apache/brooklyn/core/location/LocationManagementTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/location/LocationManagementTest.java @@ -24,11 +24,14 @@ import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; +import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.LocationManager; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation; import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.test.Asserts; +import org.apache.brooklyn.util.collections.CollectionFunctionals; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -58,6 +61,7 @@ public class LocationManagementTest extends BrooklynAppUnitTestSupport { @Test public void testCreateLocationUsingResolver() { String spec = "byon:(hosts=\"1.1.1.1\")"; + @SuppressWarnings("unchecked") FixedListMachineProvisioningLocation loc = (FixedListMachineProvisioningLocation) mgmt.getLocationRegistry().resolve(spec); SshMachineLocation machine = Iterables.getOnlyElement(loc.getAllMachines()); @@ -68,6 +72,7 @@ public class LocationManagementTest extends BrooklynAppUnitTestSupport { @Test public void testChildrenOfManagedLocationAutoManaged() { String spec = "byon:(hosts=\"1.1.1.1\")"; + @SuppressWarnings("unchecked") FixedListMachineProvisioningLocation loc = (FixedListMachineProvisioningLocation) mgmt.getLocationRegistry().resolve(spec); SshMachineLocation machine = new SshMachineLocation(ImmutableMap.of("address", "1.2.3.4")); @@ -79,4 +84,36 @@ public class LocationManagementTest extends BrooklynAppUnitTestSupport { assertNull(locationManager.getLocation(machine.getId())); assertFalse(machine.isManaged()); } + + @Test + public void testManagedLocationsSimpleCreateAndCleanup() { + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); + Location loc = mgmt.getLocationRegistry().resolve("localhost"); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); + mgmt.getLocationManager().unmanage(loc); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); + } + + @Test + public void testManagedLocationsNamedCreateAndCleanup() { + Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations().keySet(), CollectionFunctionals.sizeEquals(0)); + Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); + + mgmt.getLocationRegistry().updateDefinedLocation( new BasicLocationDefinition("lh1", "localhost", null) ); + + Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations().keySet(), CollectionFunctionals.sizeEquals(1)); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); + // currently such defined locations do NOT appear in catalog -- see CatalogYamlLocationTest + Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); + + Location loc = mgmt.getLocationRegistry().resolve("lh1"); + Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations().keySet(), CollectionFunctionals.sizeEquals(1)); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); + + mgmt.getLocationManager().unmanage(loc); + Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations().keySet(), CollectionFunctionals.sizeEquals(1)); + Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); + } + }