brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [4/6] brooklyn-server git commit: BROOKLYN-249: test JcloudsLocation external config
Date Wed, 06 Apr 2016 11:23:28 GMT
BROOKLYN-249: test JcloudsLocation external config


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

Branch: refs/heads/0.9.0
Commit: bc5c1bbf19ed70504f526913d4ee85e0dffe8e45
Parents: 148e6d7
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Apr 5 18:05:43 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Apr 6 11:25:37 2016 +0100

----------------------------------------------------------------------
 camp/camp-brooklyn/pom.xml                      | 13 ++++
 .../core/mgmt/rebind/RebindTestFixture.java     | 11 ++++
 .../byon/ByonLocationResolverRebindTest.java    | 69 ++++++++++++++++++++
 .../jclouds/AbstractJcloudsLiveTest.java        |  2 +-
 .../location/jclouds/JcloudsRebindStubTest.java | 34 +++++++---
 5 files changed, 118 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bc5c1bbf/camp/camp-brooklyn/pom.xml
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/pom.xml b/camp/camp-brooklyn/pom.xml
index 9723d5b..c7eb31f 100644
--- a/camp/camp-brooklyn/pom.xml
+++ b/camp/camp-brooklyn/pom.xml
@@ -140,6 +140,19 @@
         </dependency>
         <dependency>
             <groupId>org.apache.brooklyn</groupId>
+            <artifactId>brooklyn-locations-jclouds</artifactId>
+            <version>${project.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <!-- jsr311 excluded from jclouds; see jclouds module's pom for further comments.
-->
+            <groupId>javax.ws.rs</groupId>
+            <artifactId>javax.ws.rs-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.brooklyn</groupId>
             <artifactId>brooklyn-test-support</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bc5c1bbf/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index f43042f..8bbd04d 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -39,6 +39,7 @@ import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityFunctions;
 import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
@@ -86,12 +87,21 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
         LOG.info("Test "+getClass()+" persisting to "+mementoDir);
     }
 
+    protected BrooklynProperties createBrooklynProperties() {
+        if (useLiveManagementContext()) {
+            return BrooklynProperties.Factory.newDefault();
+        } else {
+            return BrooklynProperties.Factory.newEmpty();
+        }
+    }
+
     /** @return A started management context */
     protected LocalManagementContext createOrigManagementContext() {
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .persistPeriodMillis(getPersistPeriodMillis())
                 .forLive(useLiveManagementContext())
                 .emptyCatalog(useEmptyCatalog())
+                .properties(createBrooklynProperties())
                 .buildStarted();
     }
 
@@ -106,6 +116,7 @@ public abstract class RebindTestFixture<T extends StartableApplication>
{
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .forLive(useLiveManagementContext())
                 .emptyCatalog(useEmptyCatalog())
+                .properties(createBrooklynProperties())
                 .buildUnstarted();
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bc5c1bbf/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverRebindTest.java
b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverRebindTest.java
new file mode 100644
index 0000000..9f3b3a3
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverRebindTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.location.byon;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.location.MachineProvisioningLocation;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class ByonLocationResolverRebindTest extends RebindTestFixtureWithApp {
+
+    @Test
+    public void testRebindByon() throws Exception {
+        String spec = "byon(hosts=\"1.1.1.1\")";
+        MachineProvisioningLocation<MachineLocation> provisioner = resolve(spec);
+        
+        rebind();
+        
+        @SuppressWarnings("unchecked")
+        MachineProvisioningLocation<MachineLocation> newProvisioner = (MachineProvisioningLocation<MachineLocation>)
mgmt().getLocationManager().getLocation(provisioner.getId());
+        MachineLocation newLocation = newProvisioner.obtain(ImmutableMap.of());
+        assertTrue(newLocation instanceof SshMachineLocation, "Expected location to be SshMachineLocation,
found " + newLocation);
+    }
+
+    @Test
+    public void testRebindWhenOnlyByonLocationSpec() throws Exception {
+        int before = mgmt().getLocationManager().getLocations().size();
+        String spec = "byon(hosts=\"1.1.1.1\")";
+        getLocationSpec(spec);
+        
+        rebind();
+
+        int after = mgmt().getLocationManager().getLocations().size();
+        assertEquals(after, before);
+    }
+
+    @SuppressWarnings("unchecked")
+    private LocationSpec<FixedListMachineProvisioningLocation<MachineLocation>>
getLocationSpec(String val) {
+        return (LocationSpec<FixedListMachineProvisioningLocation<MachineLocation>>)
mgmt().getLocationRegistry().getLocationSpec(val).get();
+    }
+
+    @SuppressWarnings("unchecked")
+    private FixedListMachineProvisioningLocation<MachineLocation> resolve(String val)
{
+        return (FixedListMachineProvisioningLocation<MachineLocation>) mgmt().getLocationRegistry().getLocationManaged(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bc5c1bbf/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
index 7723a01..4313c43 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
@@ -112,7 +112,7 @@ public class AbstractJcloudsLiveTest {
         return LocalManagementContextForTests.builder(true).useDefaultProperties().build();
     }
     
-    protected static void stripBrooklynProperties(BrooklynProperties props) {
+    public static void stripBrooklynProperties(BrooklynProperties props) {
         // remove all location properties except for identity and credential
         // (so key, scripts, etc settings don't interfere with tests) 
         for (String key : ImmutableSet.copyOf(props.asMapWithStringKeys().keySet())) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bc5c1bbf/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubTest.java
index 1d33bc5..b89e1b2 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubTest.java
@@ -74,10 +74,15 @@ import com.google.common.collect.Multimaps;
 public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
 
     // TODO Duplication of AbstractJcloudsLiveTest, because we're subclassing RebindTestFixture
instead.
+    
+    // TODO The ByonComputeServiceRegistry extends ComputeServiceRegistryImpl, which means
when it  
+    // is serialized it will try to serialize the cachedComputeServices. That will try to
serialize 
+    // threads and all sorts!
 
     private static final Logger LOG = LoggerFactory.getLogger(JcloudsRebindStubTest.class);
 
-    public static final String SOFTLAYER_LOCATION_SPEC = "jclouds:" + AbstractJcloudsLiveTest.SOFTLAYER_PROVIDER;
+    public static final String PROVIDER = AbstractJcloudsLiveTest.SOFTLAYER_PROVIDER;
+    public static final String SOFTLAYER_LOCATION_SPEC = "jclouds:" + PROVIDER;
     public static final String SOFTLAYER_IMAGE_ID = "UBUNTU_14_64";
     
     protected List<ManagementContext> mgmts;
@@ -89,10 +94,6 @@ public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
         super.setUp();
         mgmts = Lists.newCopyOnWriteArrayList(ImmutableList.<ManagementContext>of(origManagementContext));
         machines = Multimaps.synchronizedMultimap(ArrayListMultimap.<ManagementContext,
JcloudsSshMachineLocation>create());
-        
-        // Don't let any defaults from brooklyn.properties (except credentials) interfere
with test
-        brooklynProperties = origManagementContext.getBrooklynProperties();
-        AbstractJcloudsLiveTest.stripBrooklynProperties(brooklynProperties);
     }
 
     @AfterMethod(alwaysRun=true)
@@ -120,6 +121,14 @@ public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
     }
 
     @Override
+    protected BrooklynProperties createBrooklynProperties() {
+        // Don't let any defaults from brooklyn.properties (except credentials) interfere
with test
+        BrooklynProperties result = super.createBrooklynProperties();
+        AbstractJcloudsLiveTest.stripBrooklynProperties(result);
+        return result;
+    }
+    
+    @Override
     protected boolean useLiveManagementContext() {
         return true;
     }
@@ -130,7 +139,7 @@ public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
         mgmts.add(newManagementContext);
         return result;
     }
-    
+
     @Test(groups={"Live", "Live-sanity"})
     public void testRebind() throws Exception {
         LocationImpl locImpl = new LocationImpl(
@@ -181,10 +190,8 @@ public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
                 "myHostname");
         
         ByonComputeServiceRegistry computeServiceRegistry = new ByonComputeServiceRegistry(node);
-        JcloudsLocation origJcloudsLoc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged("jclouds:softlayer",
ImmutableMap.of(
-                JcloudsLocation.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry,
-                JcloudsLocation.WAIT_FOR_SSHABLE, false,
-                JcloudsLocation.USE_JCLOUDS_SSH_INIT, false));
+
+        JcloudsLocation origJcloudsLoc = newJcloudsLocation(computeServiceRegistry);
     
         JcloudsSshMachineLocation origMachine = (JcloudsSshMachineLocation) origJcloudsLoc.obtain(ImmutableMap.of("imageId",
SOFTLAYER_IMAGE_ID));
         
@@ -211,6 +218,13 @@ public class JcloudsRebindStubTest extends RebindTestFixtureWithApp {
         assertEquals(newJcloudsLoc.getProvider(), origJcloudsLoc.getProvider());
     }
     
+    protected JcloudsLocation newJcloudsLocation(ComputeServiceRegistry computeServiceRegistry)
throws Exception {
+        return (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged("jclouds:softlayer",
ImmutableMap.of(
+                JcloudsLocation.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry, 
+                JcloudsLocation.WAIT_FOR_SSHABLE, false,
+                JcloudsLocation.USE_JCLOUDS_SSH_INIT, false));
+    }
+    
     protected static class ByonComputeServiceRegistry extends ComputeServiceRegistryImpl
implements ComputeServiceRegistry {
         private final NodeMetadata node;
 


Mime
View raw message