brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [03/18] brooklyn-server git commit: add more tests for the number of locations being managed
Date Fri, 18 Mar 2016 11:06:24 GMT
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 <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Mar 15 12:10:55 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
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<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
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<SshMachineLocation> loc = (FixedListMachineProvisioningLocation<SshMachineLocation>)
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));
+    }
+
 }


Mime
View raw message