brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/3] incubator-brooklyn git commit: jclouds port forwarding: add testReleaseVmDoesNotImpactOtherVms
Date Tue, 27 Jan 2015 13:13:57 GMT
jclouds port forwarding: add testReleaseVmDoesNotImpactOtherVms

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

Branch: refs/heads/master
Commit: e1b35c5062885397713e4b27ca2294ee4d51e7be
Parents: 02d77d5
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Jan 27 13:12:04 2015 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Jan 27 13:12:04 2015 +0000

----------------------------------------------------------------------
 .../JcloudsPortForwardingStubbedLiveTest.java   | 59 +++++++++++++++++---
 1 file changed, 51 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e1b35c50/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
b/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
index f562ebf..fa1cb90 100644
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
+++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/networking/JcloudsPortForwardingStubbedLiveTest.java
@@ -62,31 +62,40 @@ public class JcloudsPortForwardingStubbedLiveTest extends AbstractJcloudsStubbed
     private static final Logger LOG = LoggerFactory.getLogger(JcloudsPortForwardingStubbedLiveTest.class);
 
     static class RecordingJcloudsPortForwarderExtension implements JcloudsPortForwarderExtension
{
-        int nextPublicPort = 12345;
+        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));
-            return HostAndPort.fromParts("1.2.3.4", nextPublicPort++);
+            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 NodeCreator newNodeCreator() {
         return new NodeCreator() {
+            int nextIpSuffix = 2;
             @Override
             protected NodeMetadata newNode(String group, Template template) {
+                int ipSuffix = nextIpSuffix++;
                 NodeMetadata result = new NodeMetadataBuilder()
-                        .id("myid")
+                        .id("myid-"+ipSuffix)
                         .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
                         .loginPort(22)
                         .status(Status.RUNNING)
-                        .publicAddresses(ImmutableList.of("173.194.32.123"))
-                        .privateAddresses(ImmutableList.of("172.168.10.11"))
+                        .publicAddresses(ImmutableList.of("173.194.32."+ipSuffix))
+                        .privateAddresses(ImmutableList.of("172.168.10."+ipSuffix))
                         .build();
                 return result;
             }
@@ -95,7 +104,8 @@ public class JcloudsPortForwardingStubbedLiveTest extends AbstractJcloudsStubbed
 
     @Test(groups = {"Live", "Live-sanity"})
     protected void testPortForwardingCallsForwarder() throws Exception {
-        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension();
+        PortForwardManager pfm = new PortForwardManagerImpl();
+        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
         
         JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
                 JcloudsLocation.USE_PORT_FORWARDING, true,
@@ -125,8 +135,7 @@ public class JcloudsPortForwardingStubbedLiveTest extends AbstractJcloudsStubbed
     @Test(groups = {"Live", "Live-sanity"})
     protected void testDeregistersWithPortForwardManagerOnRelease() throws Exception {
         PortForwardManager pfm = new PortForwardManagerImpl();
-        
-        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension();
+        RecordingJcloudsPortForwarderExtension portForwarder = new RecordingJcloudsPortForwarderExtension(pfm);
         
         JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.<ConfigKey<?>,Object>of(
                 JcloudsLocation.PORT_FORWARDER, portForwarder,
@@ -151,4 +160,38 @@ public class JcloudsPortForwardingStubbedLiveTest extends AbstractJcloudsStubbed
         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 = nodeCreator.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