brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/3] brooklyn-server git commit: Convert jclouds live-sanity tests to unit tests
Date Thu, 06 Oct 2016 11:50:37 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master fcb325a16 -> 6e3c27a35


Convert jclouds live-sanity tests to unit tests

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

Branch: refs/heads/master
Commit: 4210077b33344f63075c6f1524f408b9d9ce99cd
Parents: c2669da
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Oct 4 16:55:19 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Oct 6 11:06:02 2016 +0100

----------------------------------------------------------------------
 ...dsByonLocationResolverStubbedRebindTest.java |   5 +-
 .../JcloudsByonLocationResolverStubbedTest.java |  11 +-
 ...cloudsSshMachineLocationStubbedLiveTest.java | 127 ------------
 .../JcloudsSshMachineLocationStubbedTest.java   | 119 +++++++++++
 .../JcloudsPortForwardingStubbedLiveTest.java   | 200 ------------------
 .../JcloudsPortForwardingStubbedTest.java       | 202 +++++++++++++++++++
 6 files changed, 333 insertions(+), 331 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedRebindTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedRebindTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedRebindTest.java
index d4c7505..26da5e9 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedRebindTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedRebindTest.java
@@ -60,7 +60,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-public class JcloudsByonLocationResolverStubbedRebindTest extends AbstractJcloudsStubbedLiveTest
{
+public class JcloudsByonLocationResolverStubbedRebindTest extends AbstractJcloudsStubbedUnitTest
{
 
     private static final Logger LOG = LoggerFactory.getLogger(JcloudsByonLocationResolverStubbedRebindTest.class);
     
@@ -92,6 +92,8 @@ public class JcloudsByonLocationResolverStubbedRebindTest extends AbstractJcloud
         LOG.info("Test "+getClass()+" persisting to "+mementoDir);
         
         super.setUp();
+        
+        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of());
     }
 
     @AfterMethod(alwaysRun=true)
@@ -110,7 +112,6 @@ public class JcloudsByonLocationResolverStubbedRebindTest extends AbstractJcloud
         origManagementContext = null;
     }
 
-    @Override
     protected NodeCreator newNodeCreator() {
         return new NodeCreatorForRebinding();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedTest.java
index 45cd0d1..e70db2c 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsByonLocationResolverStubbedTest.java
@@ -41,6 +41,7 @@ import org.jclouds.compute.domain.Template;
 import org.jclouds.domain.LoginCredentials;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Predicate;
@@ -49,7 +50,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-public class JcloudsByonLocationResolverStubbedTest extends AbstractJcloudsStubbedLiveTest
{
+public class JcloudsByonLocationResolverStubbedTest extends AbstractJcloudsStubbedUnitTest
{
 
     @SuppressWarnings("unused")
     private static final Logger log = LoggerFactory.getLogger(JcloudsByonLocationResolverStubbedTest.class);
@@ -57,6 +58,13 @@ public class JcloudsByonLocationResolverStubbedTest extends AbstractJcloudsStubb
     private final String nodeId = "mynodeid";
     private final String nodePublicAddress = "173.194.32.123";
     private final String nodePrivateAddress = "172.168.10.11";
+
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of());
+    }
     
     protected LocalManagementContext newManagementContext() {
         // This really is stubbed; no live access to the cloud
@@ -68,7 +76,6 @@ public class JcloudsByonLocationResolverStubbedTest extends AbstractJcloudsStubb
 
     }
 
-    @Override
     protected NodeCreator newNodeCreator() {
         return new AbstractNodeCreator() {
             @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedLiveTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedLiveTest.java
deleted file mode 100644
index be29cdc..0000000
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedLiveTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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.jclouds;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
-import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.NodeCreator;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
-import org.apache.brooklyn.util.core.internal.ssh.SshTool;
-import org.apache.brooklyn.util.core.internal.winrm.WinRmTool;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.domain.LoginCredentials;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class JcloudsSshMachineLocationStubbedLiveTest extends AbstractJcloudsStubbedLiveTest
{
-
-    @SuppressWarnings("unused")
-    private static final Logger log = LoggerFactory.getLogger(JcloudsImageChoiceStubbedLiveTest.class);
-    
-    private List<String> privateAddresses;
-    private List<String> publicAddresses;
-
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        privateAddresses = ImmutableList.of("172.168.10.11");
-        publicAddresses = ImmutableList.of("173.194.32.123");
-        super.setUp();
-    }
-    
-    @Override
-    protected NodeCreator newNodeCreator() {
-        return new AbstractNodeCreator() {
-            @Override protected NodeMetadata newNode(String group, Template template) {
-                NodeMetadata result = new NodeMetadataBuilder()
-                        .id("myid")
-                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
-                        .loginPort(22)
-                        .status(Status.RUNNING)
-                        .publicAddresses(publicAddresses)
-                        .privateAddresses(privateAddresses)
-                        .build();
-                return result;
-            }
-        };
-    }
-
-    protected Map<Object, Object> jcloudsLocationConfig(Map<Object, Object> defaults)
{
-        return ImmutableMap.<Object, Object>builder()
-                .putAll(defaults)
-                .put(JcloudsLocationConfig.IMAGE_ID, "CENTOS_5_64")
-                .build();
-    }
-
-    @Test(groups={"Live", "Live-sanity"})
-    public void testWithNoPrivateAddress() throws Exception {
-        privateAddresses = ImmutableList.of();
-        JcloudsSshMachineLocation machine = obtainMachine();
-        assertEquals(machine.getPrivateAddresses(), ImmutableSet.of());
-        assertEquals(machine.getPrivateAddress(), Optional.absent());
-        assertEquals(machine.getSubnetIp(), publicAddresses.get(0));
-        assertEquals(machine.getSubnetHostname(), publicAddresses.get(0));
-    }
-    
-    @Test(groups={"Live", "Live-sanity"})
-    public void testWithPrivateAddress() throws Exception {
-        JcloudsSshMachineLocation machine = obtainMachine();
-        assertEquals(machine.getPrivateAddresses(), privateAddresses);
-        assertEquals(machine.getPrivateAddress(), Optional.of(privateAddresses.get(0)));
-        assertEquals(machine.getSubnetIp(), privateAddresses.get(0));
-        assertEquals(machine.getSubnetHostname(), privateAddresses.get(0));
-    }
-    
-    @Test(groups={"Live", "Live-sanity"})
-    public void testSshConfigPassedToMachine() throws Exception {
-        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of(
-                SshMachineLocation.LOCAL_TEMP_DIR.getName(), "/my/local/temp/dir",
-                SshMachineLocation.LOG_PREFIX.getName(), "myLogPrefix",
-                SshTool.PROP_SSH_TRIES, 123));
-        assertEquals(machine.config().get(SshMachineLocation.LOCAL_TEMP_DIR), "/my/local/temp/dir");
-        assertEquals(machine.config().get(SshMachineLocation.LOG_PREFIX), "myLogPrefix");
-        assertEquals(machine.config().get(SshTool.PROP_SSH_TRIES), Integer.valueOf(123));
-    }
-    
-    @Test(groups={"Live", "Live-sanity"})
-    public void testWinrmConfigPassedToMachine() throws Exception {
-        JcloudsWinRmMachineLocation machine = obtainWinrmMachine(ImmutableMap.of(
-                JcloudsLocation.OS_FAMILY_OVERRIDE.getName(), OsFamily.WINDOWS,
-                JcloudsLocation.WAIT_FOR_WINRM_AVAILABLE.getName(), "false",
-                WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES.getName(), 123,
-                WinRmTool.PROP_EXEC_TRIES.getName(), 456));
-        assertEquals(machine.config().get(WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES),
Integer.valueOf(123));
-        assertEquals(machine.config().get(WinRmTool.PROP_EXEC_TRIES), Integer.valueOf(456));
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedTest.java
new file mode 100644
index 0000000..30fd0d3
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedTest.java
@@ -0,0 +1,119 @@
+/*
+ * 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.jclouds;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
+import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.NodeCreator;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.core.internal.ssh.SshTool;
+import org.apache.brooklyn.util.core.internal.winrm.WinRmTool;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadata.Status;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.domain.LoginCredentials;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+public class JcloudsSshMachineLocationStubbedTest extends AbstractJcloudsStubbedUnitTest
{
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(JcloudsImageChoiceStubbedLiveTest.class);
+    
+    private List<String> privateAddresses;
+    private List<String> publicAddresses;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        super.setUp();
+        privateAddresses = ImmutableList.of("172.168.10.11");
+        publicAddresses = ImmutableList.of("173.194.32.123");
+        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of());
+    }
+    
+    protected NodeCreator newNodeCreator() {
+        return new AbstractNodeCreator() {
+            @Override protected NodeMetadata newNode(String group, Template template) {
+                NodeMetadata result = new NodeMetadataBuilder()
+                        .id("myid")
+                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
+                        .loginPort(22)
+                        .status(Status.RUNNING)
+                        .publicAddresses(publicAddresses)
+                        .privateAddresses(privateAddresses)
+                        .build();
+                return result;
+            }
+        };
+    }
+
+    @Test
+    public void testWithNoPrivateAddress() throws Exception {
+        privateAddresses = ImmutableList.of();
+        JcloudsSshMachineLocation machine = obtainMachine();
+        assertEquals(machine.getPrivateAddresses(), ImmutableSet.of());
+        assertEquals(machine.getPrivateAddress(), Optional.absent());
+        assertEquals(machine.getSubnetIp(), publicAddresses.get(0));
+        assertEquals(machine.getSubnetHostname(), publicAddresses.get(0));
+    }
+    
+    @Test
+    public void testWithPrivateAddress() throws Exception {
+        JcloudsSshMachineLocation machine = obtainMachine();
+        assertEquals(machine.getPrivateAddresses(), privateAddresses);
+        assertEquals(machine.getPrivateAddress(), Optional.of(privateAddresses.get(0)));
+        assertEquals(machine.getSubnetIp(), privateAddresses.get(0));
+        assertEquals(machine.getSubnetHostname(), privateAddresses.get(0));
+    }
+    
+    @Test
+    public void testSshConfigPassedToMachine() throws Exception {
+        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of(
+                SshMachineLocation.LOCAL_TEMP_DIR.getName(), "/my/local/temp/dir",
+                SshMachineLocation.LOG_PREFIX.getName(), "myLogPrefix",
+                SshTool.PROP_SSH_TRIES, 123));
+        assertEquals(machine.config().get(SshMachineLocation.LOCAL_TEMP_DIR), "/my/local/temp/dir");
+        assertEquals(machine.config().get(SshMachineLocation.LOG_PREFIX), "myLogPrefix");
+        assertEquals(machine.config().get(SshTool.PROP_SSH_TRIES), Integer.valueOf(123));
+    }
+    
+    @Test
+    public void testWinrmConfigPassedToMachine() throws Exception {
+        JcloudsWinRmMachineLocation machine = obtainWinrmMachine(ImmutableMap.of(
+                JcloudsLocation.OS_FAMILY_OVERRIDE.getName(), OsFamily.WINDOWS,
+//                JcloudsLocation.WAIT_FOR_WINRM_AVAILABLE.getName(), "false",
+                WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES.getName(), 123,
+                WinRmTool.PROP_EXEC_TRIES.getName(), 456));
+        assertEquals(machine.config().get(WinRmMachineLocation.COPY_FILE_CHUNK_SIZE_BYTES),
Integer.valueOf(123));
+        assertEquals(machine.config().get(WinRmTool.PROP_EXEC_TRIES), Integer.valueOf(456));
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
deleted file mode 100644
index 9783acf..0000000
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.jclouds.networking;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import java.util.List;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.location.access.PortForwardManager;
-import org.apache.brooklyn.core.location.access.PortForwardManagerImpl;
-import org.apache.brooklyn.location.jclouds.AbstractJcloudsStubbedLiveTest;
-import org.apache.brooklyn.location.jclouds.JcloudsLocation;
-import org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation;
-import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
-import org.apache.brooklyn.util.net.Cidr;
-import org.apache.brooklyn.util.net.Protocol;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.domain.LoginCredentials;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.net.HostAndPort;
-
-/**
- * The VM creation is stubbed out, but it still requires live access (i.e. real account credentials)
- * to generate the template etc.
- * 
- * We supply a ComputeServiceRegistry that delegates to the real instance for everything
except
- * VM creation and deletion. For those operations, it delegates to a NodeCreator that 
- * returns a dummy NodeMetadata, recording all calls made to it.
- */
-public class JcloudsPortForwardingStubbedLiveTest extends AbstractJcloudsStubbedLiveTest
{
-
-    @SuppressWarnings("unused")
-    private static final Logger LOG = LoggerFactory.getLogger(JcloudsPortForwardingStubbedLiveTest.class);
-
-    static class RecordingJcloudsPortForwarderExtension implements JcloudsPortForwarderExtension
{
-        final PortForwardManager pfm;
-        final List<List<Object>> opens = Lists.newCopyOnWriteArrayList();
-        final List<List<Object>> closes = Lists.newCopyOnWriteArrayList();
-        int nextPublicPort = 12345;
-        
-        RecordingJcloudsPortForwarderExtension(PortForwardManager pfm) {
-            this.pfm = pfm;
-        }
-        @Override public HostAndPort openPortForwarding(NodeMetadata node, int targetPort,
Optional<Integer> optionalPublicPort, Protocol protocol, Cidr accessingCidr) {
-            opens.add(ImmutableList.of(node, targetPort, optionalPublicPort, protocol, accessingCidr));
-            HostAndPort result = HostAndPort.fromParts("1.2.3.4", nextPublicPort++);
-            pfm.associate(node.getId(), result, targetPort);
-            return result;
-        }
-        @Override public void closePortForwarding(NodeMetadata node, int targetPort, HostAndPort
publicHostAndPort, Protocol protocol) {
-            closes.add(ImmutableList.of(node, targetPort, publicHostAndPort, protocol));
-            pfm.forgetPortMapping(node.getId(), publicHostAndPort.getPort());
-        }
-    }
-
-    @Override
-    protected AbstractNodeCreator newNodeCreator() {
-        return new AbstractNodeCreator() {
-            int nextIpSuffix = 2;
-            @Override
-            protected NodeMetadata newNode(String group, Template template) {
-                int ipSuffix = nextIpSuffix++;
-                NodeMetadata result = new NodeMetadataBuilder()
-                        .id("myid-"+ipSuffix)
-                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
-                        .loginPort(22)
-                        .status(Status.RUNNING)
-                        .publicAddresses(ImmutableList.of("173.194.32."+ipSuffix))
-                        .privateAddresses(ImmutableList.of("172.168.10."+ipSuffix))
-                        .build();
-                return result;
-            }
-        };
-    }
-
-    protected AbstractNodeCreator getNodeCreator() {
-        return (AbstractNodeCreator) nodeCreator;
-    }
-
-    @Test(groups = {"Live", "Live-sanity"})
-    protected void testPortForwardingCallsForwarder() throws Exception {
-        PortForwardManager pfm = new PortForwardManagerImpl();
-        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
-        
-        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
-                JcloudsLocation.USE_PORT_FORWARDING, true,
-                JcloudsLocation.PORT_FORWARDER, portForwarder));
-        
-        NodeMetadata created = getNodeCreator().created.get(0);
-        assertEquals(getNodeCreator().created.size(), 1, "created="+getNodeCreator().created+";
machine="+machine);
-        assertEquals(machine.getNode(), created);
-        assertEquals(portForwarder.opens.size(), 1, "opens="+portForwarder.opens+"; machine="+machine);
-        assertEquals(portForwarder.opens.get(0).get(0), created);
-        assertEquals(portForwarder.opens.get(0).get(1), 22);
-        assertEquals(portForwarder.opens.get(0).get(3), Protocol.TCP);
-        assertEquals(portForwarder.opens.get(0).get(4), Cidr.UNIVERSAL);
-        assertEquals(machine.getSshHostAndPort(), HostAndPort.fromParts("1.2.3.4", 12345));
-        
-        releaseMachine(machine);
-        String destroyed = getNodeCreator().destroyed.get(0);
-        assertEquals(getNodeCreator().destroyed.size(), 1, "destroyed="+getNodeCreator().destroyed+";
machine="+machine);
-        assertEquals(destroyed, created.getId());
-        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine="+machine);
-        assertEquals(portForwarder.closes.get(0).get(0), created);
-        assertEquals(portForwarder.closes.get(0).get(1), 22);
-        assertEquals(portForwarder.closes.get(0).get(2), HostAndPort.fromParts("1.2.3.4",
12345));
-        assertEquals(portForwarder.closes.get(0).get(3), Protocol.TCP);
-    }
-    
-    @Test(groups = {"Live", "Live-sanity"})
-    protected void testDeregistersWithPortForwardManagerOnRelease() throws Exception {
-        PortForwardManager pfm = new PortForwardManagerImpl();
-        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
-        
-        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
-                JcloudsLocation.PORT_FORWARDER, portForwarder,
-                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
-        
-        // Add an association for this machine - expect that to be deleted when the machine
is released.
-        HostAndPort publicHostAndPort = HostAndPort.fromParts("1.2.3.4", 1234);
-        pfm.associate("mypublicip", publicHostAndPort, machine, 80);
-        assertEquals(pfm.lookup(machine, 80), publicHostAndPort);
-        assertEquals(pfm.lookup("mypublicip", 80), publicHostAndPort);
-
-        // Release
-        releaseMachine(machine);
-        
-        // Expect to have been cleared from PortForwardManager's records
-        assertNull(pfm.lookup(machine, 80));
-        assertNull(pfm.lookup("mypublicip", 80));
-        
-        // And for port-forwarding to have been closed
-        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine="+machine);
-        assertEquals(portForwarder.closes.get(0).get(1), 80);
-        assertEquals(portForwarder.closes.get(0).get(2), HostAndPort.fromParts("1.2.3.4",
1234));
-        assertEquals(portForwarder.closes.get(0).get(3), Protocol.TCP);
-    }
-    
-    @Test(groups = {"Live", "Live-sanity"})
-    protected void testReleaseVmDoesNotImpactOtherVms() throws Exception {
-        PortForwardManager pfm = new PortForwardManagerImpl();
-        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
-        
-        JcloudsSshMachineLocation machine1 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
-                JcloudsLocation.USE_PORT_FORWARDING, true,
-                JcloudsLocation.PORT_FORWARDER, portForwarder,
-                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
-        
-        JcloudsSshMachineLocation machine2 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
-                JcloudsLocation.USE_PORT_FORWARDING, true,
-                JcloudsLocation.PORT_FORWARDER, portForwarder,
-                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
-        
-        NodeMetadata node1 = getNodeCreator().created.get(0);
-
-        // Add an association for machine2 - expect that not to be touched when machine1
is released.
-        HostAndPort publicHostAndPort = HostAndPort.fromParts("1.2.3.4", 1234);
-        pfm.associate("mypublicip", publicHostAndPort, machine2, 80);
-
-        // Release machine1
-        releaseMachine(machine1);
-        
-        // Expect machine2 to still be registered
-        assertEquals(pfm.lookup(machine2, 80), publicHostAndPort);
-        assertEquals(pfm.lookup("mypublicip", 80), publicHostAndPort);
-        
-        // And no calls to "close" for machine2; just for machine1's port 22
-        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine1="+machine1);
-        assertEquals(portForwarder.closes.get(0).get(0), node1);
-        assertEquals(portForwarder.closes.get(0).get(1), 22);
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4210077b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedTest.java
new file mode 100644
index 0000000..4ca6765
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedTest.java
@@ -0,0 +1,202 @@
+/*
+ * 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.jclouds.networking;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.util.List;
+
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.location.access.PortForwardManager;
+import org.apache.brooklyn.core.location.access.PortForwardManagerImpl;
+import org.apache.brooklyn.location.jclouds.AbstractJcloudsStubbedUnitTest;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation;
+import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
+import org.apache.brooklyn.util.net.Cidr;
+import org.apache.brooklyn.util.net.Protocol;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadata.Status;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.domain.LoginCredentials;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+
+/**
+ * Confirm that port-forwarding is registered and configured correctly.
+ */
+public class JcloudsPortForwardingStubbedTest extends AbstractJcloudsStubbedUnitTest {
+
+    @SuppressWarnings("unused")
+    private static final Logger LOG = LoggerFactory.getLogger(JcloudsPortForwardingStubbedTest.class);
+
+    static class RecordingJcloudsPortForwarderExtension implements JcloudsPortForwarderExtension
{
+        final PortForwardManager pfm;
+        final List<List<Object>> opens = Lists.newCopyOnWriteArrayList();
+        final List<List<Object>> closes = Lists.newCopyOnWriteArrayList();
+        int nextPublicPort = 12345;
+        
+        RecordingJcloudsPortForwarderExtension(PortForwardManager pfm) {
+            this.pfm = pfm;
+        }
+        @Override public HostAndPort openPortForwarding(NodeMetadata node, int targetPort,
Optional<Integer> optionalPublicPort, Protocol protocol, Cidr accessingCidr) {
+            opens.add(ImmutableList.of(node, targetPort, optionalPublicPort, protocol, accessingCidr));
+            HostAndPort result = HostAndPort.fromParts("1.2.3.4", nextPublicPort++);
+            pfm.associate(node.getId(), result, targetPort);
+            return result;
+        }
+        @Override public void closePortForwarding(NodeMetadata node, int targetPort, HostAndPort
publicHostAndPort, Protocol protocol) {
+            closes.add(ImmutableList.of(node, targetPort, publicHostAndPort, protocol));
+            pfm.forgetPortMapping(node.getId(), publicHostAndPort.getPort());
+        }
+    }
+
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of());
+    }
+    
+    protected AbstractNodeCreator newNodeCreator() {
+        return new AbstractNodeCreator() {
+            int nextIpSuffix = 2;
+            @Override
+            protected NodeMetadata newNode(String group, Template template) {
+                int ipSuffix = nextIpSuffix++;
+                NodeMetadata result = new NodeMetadataBuilder()
+                        .id("myid-"+ipSuffix)
+                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
+                        .loginPort(22)
+                        .status(Status.RUNNING)
+                        .publicAddresses(ImmutableList.of("173.194.32."+ipSuffix))
+                        .privateAddresses(ImmutableList.of("172.168.10."+ipSuffix))
+                        .build();
+                return result;
+            }
+        };
+    }
+
+    protected AbstractNodeCreator getNodeCreator() {
+        return (AbstractNodeCreator) nodeCreator;
+    }
+
+    @Test
+    public void testPortForwardingCallsForwarder() throws Exception {
+        PortForwardManager pfm = new PortForwardManagerImpl();
+        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
+        
+        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
+                JcloudsLocation.USE_PORT_FORWARDING, true,
+                JcloudsLocation.PORT_FORWARDER, portForwarder));
+        
+        NodeMetadata created = getNodeCreator().created.get(0);
+        assertEquals(getNodeCreator().created.size(), 1, "created="+getNodeCreator().created+";
machine="+machine);
+        assertEquals(machine.getOptionalNode().get(), created);
+        assertEquals(portForwarder.opens.size(), 1, "opens="+portForwarder.opens+"; machine="+machine);
+        assertEquals(portForwarder.opens.get(0).get(0), created);
+        assertEquals(portForwarder.opens.get(0).get(1), 22);
+        assertEquals(portForwarder.opens.get(0).get(3), Protocol.TCP);
+        assertEquals(portForwarder.opens.get(0).get(4), Cidr.UNIVERSAL);
+        assertEquals(machine.getSshHostAndPort(), HostAndPort.fromParts("1.2.3.4", 12345));
+        
+        releaseMachine(machine);
+        String destroyed = getNodeCreator().destroyed.get(0);
+        assertEquals(getNodeCreator().destroyed.size(), 1, "destroyed="+getNodeCreator().destroyed+";
machine="+machine);
+        assertEquals(destroyed, created.getId());
+        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine="+machine);
+        assertEquals(portForwarder.closes.get(0).get(0), created);
+        assertEquals(portForwarder.closes.get(0).get(1), 22);
+        assertEquals(portForwarder.closes.get(0).get(2), HostAndPort.fromParts("1.2.3.4",
12345));
+        assertEquals(portForwarder.closes.get(0).get(3), Protocol.TCP);
+    }
+    
+    @Test
+    public void testDeregistersWithPortForwardManagerOnRelease() throws Exception {
+        PortForwardManager pfm = new PortForwardManagerImpl();
+        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
+        
+        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
+                JcloudsLocation.PORT_FORWARDER, portForwarder,
+                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
+        
+        // Add an association for this machine - expect that to be deleted when the machine
is released.
+        HostAndPort publicHostAndPort = HostAndPort.fromParts("1.2.3.4", 1234);
+        pfm.associate("mypublicip", publicHostAndPort, machine, 80);
+        assertEquals(pfm.lookup(machine, 80), publicHostAndPort);
+        assertEquals(pfm.lookup("mypublicip", 80), publicHostAndPort);
+
+        // Release
+        releaseMachine(machine);
+        
+        // Expect to have been cleared from PortForwardManager's records
+        assertNull(pfm.lookup(machine, 80));
+        assertNull(pfm.lookup("mypublicip", 80));
+        
+        // And for port-forwarding to have been closed
+        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine="+machine);
+        assertEquals(portForwarder.closes.get(0).get(1), 80);
+        assertEquals(portForwarder.closes.get(0).get(2), HostAndPort.fromParts("1.2.3.4",
1234));
+        assertEquals(portForwarder.closes.get(0).get(3), Protocol.TCP);
+    }
+    
+    @Test
+    public void testReleaseVmDoesNotImpactOtherVms() throws Exception {
+        PortForwardManager pfm = new PortForwardManagerImpl();
+        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
+        
+        JcloudsSshMachineLocation machine1 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
+                JcloudsLocation.USE_PORT_FORWARDING, true,
+                JcloudsLocation.PORT_FORWARDER, portForwarder,
+                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
+        
+        JcloudsSshMachineLocation machine2 = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
+                JcloudsLocation.USE_PORT_FORWARDING, true,
+                JcloudsLocation.PORT_FORWARDER, portForwarder,
+                JcloudsLocation.PORT_FORWARDING_MANAGER, pfm));
+        
+        NodeMetadata node1 = getNodeCreator().created.get(0);
+
+        // Add an association for machine2 - expect that not to be touched when machine1
is released.
+        HostAndPort publicHostAndPort = HostAndPort.fromParts("1.2.3.4", 1234);
+        pfm.associate("mypublicip", publicHostAndPort, machine2, 80);
+
+        // Release machine1
+        releaseMachine(machine1);
+        
+        // Expect machine2 to still be registered
+        assertEquals(pfm.lookup(machine2, 80), publicHostAndPort);
+        assertEquals(pfm.lookup("mypublicip", 80), publicHostAndPort);
+        
+        // And no calls to "close" for machine2; just for machine1's port 22
+        assertEquals(portForwarder.closes.size(), 1, "closes="+portForwarder.closes+"; machine1="+machine1);
+        assertEquals(portForwarder.closes.get(0).get(0), node1);
+        assertEquals(portForwarder.closes.get(0).get(1), 22);
+    }
+}


Mime
View raw message