You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2014/06/01 22:15:38 UTC

[23/25] git commit: Adds PortAttributeSensorAndConfigKeyTest

Adds PortAttributeSensorAndConfigKeyTest


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

Branch: refs/heads/master
Commit: 94aecdb3812a9c931670cea7ef63688c47bb2d47
Parents: ba5e6f3
Author: Aled Sage <al...@gmail.com>
Authored: Fri May 30 19:45:48 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 30 19:46:16 2014 +0100

----------------------------------------------------------------------
 .../LocalhostMachineProvisioningLocation.java   |  1 +
 .../PortAttributeSensorAndConfigKeyTest.java    | 68 ++++++++++++++++++++
 2 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/94aecdb3/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java b/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
index 2a397b6..daf53fd 100644
--- a/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/LocalhostMachineProvisioningLocation.java
@@ -248,6 +248,7 @@ public class LocalhostMachineProvisioningLocation extends FixedListMachineProvis
             LOG.debug("localhost.obtainPort("+range+"), returning "+r);
             return r;
         }
+        @Override
         public void releasePort(int portNumber) {
             synchronized (portsObtained) {
                 portsObtained.remove((Object)portNumber);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/94aecdb3/software/base/src/test/java/brooklyn/event/basic/PortAttributeSensorAndConfigKeyTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/event/basic/PortAttributeSensorAndConfigKeyTest.java b/software/base/src/test/java/brooklyn/event/basic/PortAttributeSensorAndConfigKeyTest.java
new file mode 100644
index 0000000..a67e08c
--- /dev/null
+++ b/software/base/src/test/java/brooklyn/event/basic/PortAttributeSensorAndConfigKeyTest.java
@@ -0,0 +1,68 @@
+package brooklyn.event.basic;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppUnitTestSupport;
+import brooklyn.entity.basic.EmptySoftwareProcess;
+import brooklyn.entity.basic.EmptySoftwareProcessImpl;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.proxying.ImplementedBy;
+import brooklyn.location.Location;
+import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import brooklyn.location.basic.SshMachineLocation;
+
+import com.google.common.collect.ImmutableList;
+
+public class PortAttributeSensorAndConfigKeyTest extends BrooklynAppUnitTestSupport {
+
+    /*
+     * FIXME Fails because port is never released. Nothing calls PortSupplier.releasePort(int).
+     * The stacktrace below shows where it is obtained:
+     * 
+        Daemon Thread [brooklyn-execmanager-XwLLLdS4-5] (Suspended (breakpoint at line 244 in LocalhostMachineProvisioningLocation$LocalhostMachine))   
+            LocalhostMachineProvisioningLocation$LocalhostMachine.obtainPort(PortRange) line: 244   
+            PortAttributeSensorAndConfigKey.convertConfigToSensor(PortRange, Entity) line: 78   
+            PortAttributeSensorAndConfigKey.convertConfigToSensor(Object, Entity) line: 1   
+            PortAttributeSensorAndConfigKey(AttributeSensorAndConfigKey<ConfigType,SensorType>).getAsSensorValue(Entity) line: 93   
+            ConfigToAttributes.apply(EntityLocal, AttributeSensorAndConfigKey<?,T>) line: 28    
+            ConfigToAttributes.apply(EntityLocal) line: 17  
+            SoftwareProcessDriverLifecycleEffectorTasks(MachineLifecycleEffectorTasks).preStartCustom(MachineLocation) line: 343    
+            SoftwareProcessDriverLifecycleEffectorTasks.preStartCustom(MachineLocation) line: 69    
+            MachineLifecycleEffectorTasks$6.run() line: 283 
+     */
+    @Test(enabled=false, groups="Integration") // test is slow (for some reason - why?)
+    public void testStoppingEntityReleasesPortFromMachineForReuse() throws Exception {
+        LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) mgmt.getLocationRegistry().resolve("localhost");
+        SshMachineLocation machine = loc.obtain();
+        runStoppingEntityReleasesPortFromLocalhostForReuse(machine);
+    }
+
+    @Test(groups="Integration") // test is slow (for some reason - why?)
+    public void testStoppingEntityReleasesPortFromLocalhostProvisioningLocationForReuse() throws Exception {
+        LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) mgmt.getLocationRegistry().resolve("localhost");
+        runStoppingEntityReleasesPortFromLocalhostForReuse(loc);
+    }
+    
+    protected void runStoppingEntityReleasesPortFromLocalhostForReuse(Location loc) throws Exception {
+        MyEntity e1 = app.createAndManageChild(EntitySpec.create(MyEntity.class));
+        e1.start(ImmutableList.of(loc));
+        assertEquals(e1.getAttribute(MyEntity.MY_PORT), (Integer)47653);
+        
+        e1.stop();
+        Entities.unmanage(e1);
+        MyEntity e2 = app.createAndManageChild(EntitySpec.create(MyEntity.class));
+        e2.start(ImmutableList.of(loc));
+        assertEquals(e2.getAttribute(MyEntity.MY_PORT), (Integer)47653);
+    }
+
+    @ImplementedBy(MyEntityImpl.class)
+    public interface MyEntity extends EmptySoftwareProcess {
+        PortAttributeSensorAndConfigKey MY_PORT = new PortAttributeSensorAndConfigKey("myport", "", "47653");
+    }
+    
+    public static class MyEntityImpl extends EmptySoftwareProcessImpl implements MyEntity {
+    }        
+}