You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/08/19 23:21:12 UTC
[38/62] [abbrv] incubator-brooklyn git commit: rename core’s o.a.b.location to o.a.b.core.location
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
index 47118e8..42c7d90 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java
@@ -36,6 +36,10 @@ import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.entity.EntityPredicates;
import org.apache.brooklyn.core.entity.trait.FailingEntity;
+import org.apache.brooklyn.core.location.SimulatedLocation;
+import org.apache.brooklyn.core.location.cloud.AbstractAvailabilityZoneExtension;
+import org.apache.brooklyn.core.location.cloud.AvailabilityZoneExtension;
+import org.apache.brooklyn.core.location.internal.LocationInternal;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.DynamicCluster;
@@ -44,10 +48,6 @@ import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.time.Duration;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.cloud.AbstractAvailabilityZoneExtension;
-import org.apache.brooklyn.location.cloud.AvailabilityZoneExtension;
-import org.apache.brooklyn.location.core.SimulatedLocation;
-import org.apache.brooklyn.location.core.internal.LocationInternal;
import com.google.common.base.Predicate;
import com.google.common.base.Ticker;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
index 254fd03..0c18820 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
@@ -40,12 +40,12 @@ import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.factory.EntityFactory;
import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.location.PortRanges;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.BlockingEntity;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.stock.BasicEntity;
-import org.apache.brooklyn.location.core.PortRanges;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.test.TestUtils;
import org.apache.brooklyn.util.collections.MutableList;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java
index 0783db4..f783b49 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java
@@ -36,6 +36,7 @@ import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.core.test.entity.TestEntity;
@@ -46,7 +47,6 @@ import org.apache.brooklyn.test.Asserts;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
index efc93ef..c54bb3a 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.DynamicRegionsFabric;
@@ -34,7 +35,6 @@ import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java
index 1ad81e6..cae461f 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java
@@ -27,6 +27,7 @@ import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.RecordingSensorEventListener;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.BasicGroup;
@@ -37,8 +38,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import org.apache.brooklyn.location.core.SimulatedLocation;
-
public class GroupTest extends BrooklynAppUnitTestSupport {
private BasicGroup group;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java
index 88e2a36..0741170 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java
@@ -33,6 +33,7 @@ import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.AbstractMembershipTrackingPolicy;
@@ -41,7 +42,6 @@ import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java
index adcb5f8..ff48f85 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java
@@ -24,12 +24,12 @@ import static org.testng.Assert.assertFalse;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.QuarantineGroup;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.collect.ImmutableList;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
index 738ecfd..7f6cbb3 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategyTest.java
@@ -24,13 +24,13 @@ import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.zoneaware.BalancingNodePlacementStrategy;
import org.apache.brooklyn.test.Asserts;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.LinkedHashMultimap;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
index 451ec1b..75966a0 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/zoneaware/ProportionalZoneFailureDetectorTest.java
@@ -26,13 +26,13 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.group.zoneaware.ProportionalZoneFailureDetector;
import org.apache.brooklyn.util.time.Duration;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.base.Ticker;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java b/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
index e88695c..1746777 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
@@ -35,6 +35,8 @@ import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.RecordingSensorEventListener;
import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
+import org.apache.brooklyn.core.location.SimulatedLocation;
+import org.apache.brooklyn.core.location.Locations.LocationsFilter;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.core.test.entity.TestEntity;
@@ -50,9 +52,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import org.apache.brooklyn.location.core.SimulatedLocation;
-import org.apache.brooklyn.location.core.Locations.LocationsFilter;
-
public class BasicStartableTest {
private ManagementContext managementContext;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/entity/stock/DataEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/stock/DataEntityTest.java b/core/src/test/java/org/apache/brooklyn/entity/stock/DataEntityTest.java
index e64a353..f2c4a23 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/stock/DataEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/stock/DataEntityTest.java
@@ -29,6 +29,7 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.location.SimulatedLocation;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.entity.stock.DataEntity;
@@ -39,7 +40,6 @@ import org.apache.brooklyn.util.collections.MutableMap;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.location.core.SimulatedLocation;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/access/BrooklynAccessUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/access/BrooklynAccessUtilsTest.java b/core/src/test/java/org/apache/brooklyn/location/access/BrooklynAccessUtilsTest.java
deleted file mode 100644
index 7889ad7..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/access/BrooklynAccessUtilsTest.java
+++ /dev/null
@@ -1,137 +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.access;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.fail;
-
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.location.core.SupportsPortForwarding;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-import org.apache.brooklyn.util.net.Cidr;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.net.HostAndPort;
-
-public class BrooklynAccessUtilsTest extends BrooklynAppUnitTestSupport {
-
- protected PortForwardManager pfm;
- private TestEntity entity;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- pfm = (PortForwardManager) mgmt.getLocationRegistry().resolve("portForwardManager(scope=global)");
- }
-
- @Test
- public void testBrooklynAccessibleAddressFindsPreexistingMapping() throws Exception {
- final int privatePort = 8080;
- final String publicNatIp = "1.2.3.4";
- final int publicNatPort = 12000;
-
- SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure(SshMachineLocation.TCP_PORT_MAPPINGS, ImmutableMap.of(privatePort, publicNatIp+":"+publicNatPort)));
- entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
- .configure(BrooklynAccessUtils.PORT_FORWARDING_MANAGER, pfm)
- .location(machine));
-
- assertEquals(BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, privatePort), HostAndPort.fromParts(publicNatIp, publicNatPort));
- }
-
- @Test
- public void testBrooklynAccessibleAddressUsesPrivateHostPortIfNoMapping() throws Exception {
- final String privateIp = "127.1.2.3";
- final int privatePort = 8080;
-
- SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
- entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
- .configure(BrooklynAccessUtils.PORT_FORWARDING_MANAGER, pfm)
- .location(machine));
- entity.setAttribute(Attributes.HOSTNAME, privateIp);
-
- assertEquals(BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, privatePort), HostAndPort.fromParts(privateIp, privatePort));
- }
-
- @Test
- public void testBrooklynAccessibleAddressFailsIfNoMappingAndNoHostname() throws Exception {
- final int privatePort = 8080;
-
- SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
- entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
- .configure(BrooklynAccessUtils.PORT_FORWARDING_MANAGER, pfm)
- .location(machine));
-
- try {
- BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, privatePort);
- fail();
- } catch (IllegalStateException e) {
- if (!e.toString().contains("no host.name")) throw e;
- // success
- }
- }
-
- @Test
- public void testBrooklynAccessibleAddressRequestsNewPortForwarding() throws Exception {
- final int privatePort = 8080;
-
- RecordingSupportsPortForwarding machine = mgmt.getLocationManager().createLocation(LocationSpec.create(RecordingSupportsPortForwarding.class));
- entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
- .configure(BrooklynAccessUtils.PORT_FORWARDING_MANAGER, pfm)
- .configure(BrooklynAccessUtils.MANAGEMENT_ACCESS_CIDR, Cidr.UNIVERSAL)
- .location(machine));
-
- HostAndPort result = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, privatePort);
- HostAndPort portForwarded = machine.mappings.get(privatePort);
- assertNotNull(portForwarded);
- assertEquals(result, portForwarded);
- }
-
- @SuppressWarnings("serial") // TODO location should not be serializable; will be changed in future release
- public static class RecordingSupportsPortForwarding extends SshMachineLocation implements SupportsPortForwarding {
- protected final String publicIp = "1.2.3.4";
- protected final Map<Integer, HostAndPort> mappings = Maps.newConcurrentMap();
- private final AtomicInteger nextPort = new AtomicInteger(12000);
-
-
- @Override
- public HostAndPort getSocketEndpointFor(Cidr accessor, int privatePort) {
- HostAndPort result = mappings.get(privatePort);
- if (result == null) {
- int publicPort = nextPort.getAndIncrement();
- result = HostAndPort.fromParts(publicIp, publicPort);
- mappings.put(privatePort, result);
- }
- return result;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerLocationResolverTest.java b/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerLocationResolverTest.java
deleted file mode 100644
index 165af22..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerLocationResolverTest.java
+++ /dev/null
@@ -1,82 +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.access;
-
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class PortForwardManagerLocationResolverTest {
-
- private LocalManagementContext managementContext;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- managementContext = LocalManagementContextForTests.newInstance();
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (managementContext != null) Entities.destroyAll(managementContext);
- }
-
- @Test
- public void testReturnsSameInstanceBasedOnScope() {
- Location global1 = resolve("portForwardManager()"); // defaults to global
- Location global2 = resolve("portForwardManager()");
- Location global3 = resolve("portForwardManager(scope=global)");
- assertSame(global1, global2);
- assertSame(global1, global3);
-
- Location a1 = resolve("portForwardManager(scope=a)");
- Location a2 = resolve("portForwardManager(scope=a)");
- assertSame(a1, a2);
- assertNotSame(global1, a1);
-
- Location b1 = resolve("portForwardManager(scope=b)");
- assertNotSame(global1, b1);
- assertNotSame(a1, b1);
- }
-
- private Location resolve(String val) {
- Location l = managementContext.getLocationRegistry().resolve(val);
- Assert.assertNotNull(l);
- return l;
- }
-
- private void assertSame(Location loc1, Location loc2) {
- Assert.assertNotNull(loc1);
- Assert.assertTrue(loc1 instanceof PortForwardManager, "loc1="+loc1);
- Assert.assertSame(loc1, loc2);
- }
-
- private void assertNotSame(Location loc1, Location loc2) {
- Assert.assertNotNull(loc1);
- Assert.assertNotNull(loc2);
- Assert.assertTrue(loc1 instanceof PortForwardManager, "loc1="+loc1);
- Assert.assertTrue(loc2 instanceof PortForwardManager, "loc2="+loc2);
- Assert.assertNotSame(loc1, loc2);
- Assert.assertNotEquals(((PortForwardManager)loc1).getId(), ((PortForwardManager)loc2).getId());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerRebindTest.java b/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerRebindTest.java
deleted file mode 100644
index 58308f4..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerRebindTest.java
+++ /dev/null
@@ -1,194 +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.access;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-
-import java.io.File;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ha.MementoCopyMode;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.config.ConfigKeys;
-import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
-import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
-import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
-import org.apache.brooklyn.core.mgmt.rebind.RebindOptions;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
-import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.core.test.entity.TestEntityImpl;
-import org.apache.brooklyn.sensor.core.Sensors;
-import org.apache.brooklyn.util.net.Networking;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.text.Identifiers;
-import org.apache.brooklyn.util.time.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-import com.google.common.net.HostAndPort;
-
-public class PortForwardManagerRebindTest extends RebindTestFixtureWithApp {
-
- private static final Logger log = LoggerFactory.getLogger(PortForwardManagerRebindTest.class);
-
- private String machineAddress = "1.2.3.4";
- private SshMachineLocation origSimulatedMachine;
-
- @Override
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- super.setUp();
-
- origSimulatedMachine = origManagementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", Networking.getInetAddressWithFixedName(machineAddress))
- .configure("port", 1234)
- .configure("user", "myuser"));
- }
-
- @Test
- public void testAssociationPreservedOnRebind() throws Exception {
- String publicIpId = "5.6.7.8";
- String publicAddress = "5.6.7.8";
-
- TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntity.class));
- PortForwardManager origPortForwardManager = origEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- // We first wait for persisted, to ensure that it is the PortForwardManager.onChanged that is causing persistence.
- RebindTestUtils.waitForPersisted(origApp);
- origPortForwardManager.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), origSimulatedMachine, 80);
-
- newApp = rebind();
-
- // After rebind, confirm that lookups still work
- TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));
- Location newSimulatedMachine = newApp.getManagementContext().getLocationManager().getLocation(origSimulatedMachine.getId());
- PortForwardManager newPortForwardManager = newEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- assertEquals(newPortForwardManager.lookup(newSimulatedMachine, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertEquals(newPortForwardManager.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
- }
-
- @Test
- public void testAssociationPreservedOnStateExport() throws Exception {
- String publicIpId = "5.6.7.8";
- String publicAddress = "5.6.7.8";
-
- TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntity.class));
- PortForwardManager origPortForwardManager = origEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- origPortForwardManager.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), origSimulatedMachine, 80);
-
- String label = origManagementContext.getManagementNodeId()+"-"+Time.makeDateSimpleStampString();
- PersistenceObjectStore targetStore = BrooklynPersistenceUtils.newPersistenceObjectStore(origManagementContext, null,
- "tmp/web-persistence-"+label+"-"+Identifiers.makeRandomId(4));
- File dir = ((FileBasedObjectStore)targetStore).getBaseDir();
- // only register the parent dir because that will prevent leaks for the random ID
- Os.deleteOnExitEmptyParentsUpTo(dir.getParentFile(), dir.getParentFile());
- BrooklynPersistenceUtils.writeMemento(origManagementContext, targetStore, MementoCopyMode.LOCAL);
-
- RebindTestUtils.waitForPersisted(origApp);
- log.info("Using manual export dir "+dir+" for rebind instead of "+mementoDir);
- newApp = rebind(RebindOptions.create().mementoDir(dir));
-
- // After rebind, confirm that lookups still work
- TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));
- Location newSimulatedMachine = newApp.getManagementContext().getLocationManager().getLocation(origSimulatedMachine.getId());
- PortForwardManager newPortForwardManager = newEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- assertEquals(newPortForwardManager.lookup(newSimulatedMachine, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertEquals(newPortForwardManager.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
-
- // delete the dir here, to be more likely not to leak it on failure
- newManagementContext.getRebindManager().stop();
- Os.deleteRecursively(dir);
- }
-
- @Test
- public void testAssociationPreservedOnRebindLegacy() throws Exception {
- String publicIpId = "5.6.7.8";
- String publicAddress = "5.6.7.8";
-
- TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntity.class));
- PortForwardManager origPortForwardManager = origEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- // We first wait for persisted, to ensure that it is the PortForwardManager.onChanged that is causing persistence.
- RebindTestUtils.waitForPersisted(origApp);
- origPortForwardManager.recordPublicIpHostname(publicIpId, publicAddress);
- origPortForwardManager.acquirePublicPortExplicit(publicIpId, 40080);
- origPortForwardManager.associate(publicIpId, 40080, origSimulatedMachine, 80);
-
- newApp = rebind();
-
- // After rebind, confirm that lookups still work
- TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));
- Location newSimulatedMachine = newApp.getManagementContext().getLocationManager().getLocation(origSimulatedMachine.getId());
- PortForwardManager newPortForwardManager = newEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- assertEquals(newPortForwardManager.getPublicIpHostname(publicIpId), publicAddress);
- assertEquals(newPortForwardManager.lookup(newSimulatedMachine, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertEquals(newPortForwardManager.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
- }
-
- @Test
- public void testAcquirePortCounterPreservedOnRebindLegacy() throws Exception {
- String publicIpId = "5.6.7.8";
-
- TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntity.class));
- PortForwardManager origPortForwardManager = origEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- // We first wait for persisted, to ensure that it is the PortForwardManager.onChanged that is causing persistence.
- RebindTestUtils.waitForPersisted(origApp);
- int acquiredPort = origPortForwardManager.acquirePublicPort(publicIpId);
-
- newApp = rebind();
-
- // After rebind, confirm that lookups still work
- TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));
- PortForwardManager newPortForwardManager = newEntity.getConfig(MyEntity.PORT_FORWARD_MANAGER);
-
- int acquiredPort2 = newPortForwardManager.acquirePublicPort(publicIpId);
- assertNotEquals(acquiredPort, acquiredPort2);
- }
-
- public static class MyEntity extends TestEntityImpl {
- public static final ConfigKey<PortForwardManager> PORT_FORWARD_MANAGER = ConfigKeys.newConfigKey(PortForwardManager.class, "myentity.portForwardManager");
- public static final AttributeSensor<PortForwardManager> PORT_FORWARD_MANAGER_LIVE = Sensors.newSensor(PortForwardManager.class, "myentity.portForwardManager.live");
-
- @Override
- public void init() {
- super.init();
-
- if (getConfig(PORT_FORWARD_MANAGER) == null) {
- PortForwardManager pfm = (PortForwardManager) getManagementContext().getLocationRegistry().resolve("portForwardManager(scope=global)");
- setAttribute(PORT_FORWARD_MANAGER_LIVE, pfm);
- setConfig(PORT_FORWARD_MANAGER, pfm);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerTest.java b/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerTest.java
deleted file mode 100644
index 4a7274b..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/access/PortForwardManagerTest.java
+++ /dev/null
@@ -1,192 +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.access;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNull;
-
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.brooklyn.util.net.Networking;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-
-import com.google.common.base.Predicate;
-import com.google.common.net.HostAndPort;
-
-public class PortForwardManagerTest extends BrooklynAppUnitTestSupport {
-
- private static final Logger log = LoggerFactory.getLogger(PortForwardManagerTest.class);
-
- private Map<HostAndPort, HostAndPort> portMapping;
- private SshMachineLocation machine1;
- private SshMachineLocation machine2;
- private PortForwardManager pfm;
-
- @Override
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- super.setUp();
-
- pfm = (PortForwardManager) mgmt.getLocationRegistry().resolve("portForwardManager(scope=global)");
-
- machine1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", Networking.getInetAddressWithFixedName("1.2.3.4"))
- .configure("port", 1234)
- .configure("user", "myuser"));
- machine2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", Networking.getInetAddressWithFixedName("1.2.3.5"))
- .configure("port", 1234)
- .configure("user", "myuser"));
- }
-
- @Test
- public void testAssociateWithLocation() throws Exception {
- String publicIpId = "myipid";
- String publicAddress = "5.6.7.8";
-
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), machine1, 80);
-
- assertEquals(pfm.lookup(machine1, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertEquals(pfm.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
- }
-
- @Test
- public void testAssociateWithoutLocation() throws Exception {
- String publicIpId = "myipid";
- String publicAddress = "5.6.7.8";
-
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), 80);
-
- assertEquals(pfm.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertNull(pfm.lookup(machine1, 80));
- }
-
- @Test
- public void testAcquirePortDoesNotReturnDuplicate() throws Exception {
- String publicIpId = "myipid";
-
- int port1 = pfm.acquirePublicPort(publicIpId);
- int port2 = pfm.acquirePublicPort(publicIpId);
- assertNotEquals(port1, port2);
- }
-
- @Test
- public void testAcquirePortRespectsStartingPortNumber() throws Exception {
- BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
- props.put(PortForwardManager.PORT_FORWARD_MANAGER_STARTING_PORT, 1234);
- LocalManagementContextForTests mgmt2 = new LocalManagementContextForTests(props);
- try {
- PortForwardManager pfm2 = (PortForwardManager) mgmt2.getLocationRegistry().resolve("portForwardManager(scope=global)");
- int port = pfm2.acquirePublicPort("myipid");
- assertEquals(port, 1234);
- } finally {
- Entities.destroyAll(mgmt2);
- }
- }
-
- @Test
- public void testForgetPortMapping() throws Exception {
- String publicIpId = "myipid";
- String publicAddress = "5.6.7.8";
-
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), machine1, 80);
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40081), machine1, 81);
- pfm.forgetPortMapping(publicIpId, 40080);
-
- assertNull(pfm.lookup(publicIpId, 80));
- assertNull(pfm.lookup(machine1, 80));
- assertEquals(pfm.lookup(publicIpId, 81), HostAndPort.fromParts(publicAddress, 40081));
- assertEquals(pfm.lookup(publicIpId, 81), HostAndPort.fromParts(publicAddress, 40081));
- }
-
- @Test
- public void testForgetPortMappingsOfMachine() throws Exception {
- String publicIpId = "myipid";
- String publicIpId2 = "myipid2";
- String publicAddress = "5.6.7.8";
-
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40080), machine1, 80);
- pfm.associate(publicIpId, HostAndPort.fromParts(publicAddress, 40081), machine1, 81);
- pfm.associate(publicIpId2, HostAndPort.fromParts(publicAddress, 40082), machine2, 80);
- pfm.forgetPortMappings(machine1);
-
- assertNull(pfm.lookup(machine1, 80));
- assertNull(pfm.lookup(machine1, 81));
- assertNull(pfm.lookup(publicIpId, 80));
- assertEquals(pfm.lookup(machine2, 80), HostAndPort.fromParts(publicAddress, 40082));
- }
-
- @Test
- public void testAssociateLegacy() throws Exception {
- String publicIpId = "myipid";
- String publicAddress = "5.6.7.8";
-
- pfm.acquirePublicPortExplicit(publicIpId, 40080);
- pfm.recordPublicIpHostname(publicIpId, publicAddress);
- pfm.associate(publicIpId, 40080, machine1, 80);
-
- assertEquals(pfm.lookup(publicIpId, 80), HostAndPort.fromParts(publicAddress, 40080));
- assertEquals(pfm.lookup(machine1, 80), HostAndPort.fromParts(publicAddress, 40080));
- }
-
- @Test
- public void testAssociationListeners() throws Exception {
- final AtomicInteger associationCreatedCount = new AtomicInteger(0);
- final AtomicInteger associationDeletedCount = new AtomicInteger(0);
-
- final String publicIpId = "myipid";
- final String anotherIpId = "anotherIpId";
-
- pfm.addAssociationListener(new PortForwardManager.AssociationListener() {
- @Override
- public void onAssociationCreated(PortForwardManager.AssociationMetadata metadata) {
- associationCreatedCount.incrementAndGet();
- }
-
- @Override
- public void onAssociationDeleted(PortForwardManager.AssociationMetadata metadata) {
- associationDeletedCount.incrementAndGet();
- }
- }, new Predicate<PortForwardManager.AssociationMetadata>() {
- @Override
- public boolean apply(PortForwardManager.AssociationMetadata metadata) {
- return publicIpId.equals(metadata.getPublicIpId());
- }
- });
-
- pfm.associate(publicIpId, HostAndPort.fromParts(publicIpId, 40080), machine1, 80);
- pfm.associate(anotherIpId, HostAndPort.fromParts(anotherIpId, 40081), machine1, 80);
- pfm.forgetPortMapping(publicIpId, 40080);
- pfm.forgetPortMapping(anotherIpId, 40081);
-
- assertEquals(associationCreatedCount.get(), 1);
- assertEquals(associationDeletedCount.get(), 1);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
index 5ea58fc..8e4e71a 100644
--- a/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
@@ -36,13 +36,13 @@ import org.apache.brooklyn.api.location.NoMachinesAvailableException;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.location.BasicLocationRegistry;
+import org.apache.brooklyn.core.location.LocationConfigKeys;
+import org.apache.brooklyn.core.location.NamedLocationResolver;
+import org.apache.brooklyn.core.location.internal.LocationInternal;
import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
-import org.apache.brooklyn.location.core.BasicLocationRegistry;
-import org.apache.brooklyn.location.core.LocationConfigKeys;
-import org.apache.brooklyn.location.core.NamedLocationResolver;
-import org.apache.brooklyn.location.core.internal.LocationInternal;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
import org.apache.brooklyn.test.Asserts;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationRebindTest.java b/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationRebindTest.java
index c8dd237..b6a78bd 100644
--- a/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationRebindTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationRebindTest.java
@@ -29,10 +29,10 @@ import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.location.LocationConfigKeys;
import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
import org.apache.brooklyn.core.test.entity.TestApplication;
import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
-import org.apache.brooklyn.location.core.LocationConfigKeys;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.os.Os;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationTest.java
index a272084..43d5c6e 100644
--- a/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/byon/FixedListMachineProvisioningLocationTest.java
@@ -34,11 +34,11 @@ import org.apache.brooklyn.api.location.NoMachinesAvailableException;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.location.RecordingMachineLocationCustomizer;
+import org.apache.brooklyn.core.location.RecordingMachineLocationCustomizer.Call;
import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
-import org.apache.brooklyn.location.core.RecordingMachineLocationCustomizer;
-import org.apache.brooklyn.location.core.RecordingMachineLocationCustomizer.Call;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.collections.MutableMap;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/cloud/CloudMachineNamerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/cloud/CloudMachineNamerTest.java b/core/src/test/java/org/apache/brooklyn/location/cloud/CloudMachineNamerTest.java
deleted file mode 100644
index 9294e27..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/cloud/CloudMachineNamerTest.java
+++ /dev/null
@@ -1,160 +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.cloud;
-
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.location.cloud.names.AbstractCloudMachineNamer;
-import org.apache.brooklyn.location.cloud.names.CloudMachineNamer;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.text.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.location.cloud.names.BasicCloudMachineNamer;
-public class CloudMachineNamerTest {
-
- private static final Logger log = LoggerFactory.getLogger(CloudMachineNamerTest.class);
-
- private TestApplication app;
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
- @Test
- public void testGenerateGroupIdWithEntity() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
-
- String result = new BasicCloudMachineNamer().generateNewGroupId(cfg);
-
- log.info("test entity child group id gives: "+result);
- // e.g. brooklyn-alex-tistapp-uube-testent-xisg-rwad
- Assert.assertTrue(result.length() <= 60);
-
- String user = Strings.maxlen(System.getProperty("user.name"), 4).toLowerCase();
- Assert.assertTrue(result.indexOf(user) >= 0);
- Assert.assertTrue(result.indexOf("-tistapp-") >= 0);
- Assert.assertTrue(result.indexOf("-testent-") >= 0);
- Assert.assertTrue(result.indexOf("-"+Strings.maxlen(app.getId(), 4).toLowerCase()) >= 0);
- Assert.assertTrue(result.indexOf("-"+Strings.maxlen(child.getId(), 4).toLowerCase()) >= 0);
- }
-
- @Test
- public void testGenerateNewMachineName() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- BasicCloudMachineNamer namer = new BasicCloudMachineNamer();
-
- String result = namer.generateNewMachineUniqueName(cfg);
- Assert.assertTrue(result.length() <= namer.getMaxNameLength(cfg));
- String user = Strings.maxlen(System.getProperty("user.name"), 4).toLowerCase();
- Assert.assertTrue(result.indexOf(user) >= 0);
- Assert.assertTrue(result.indexOf("-tistapp-") >= 0);
- Assert.assertTrue(result.indexOf("-testent-") >= 0);
- Assert.assertTrue(result.indexOf("-"+Strings.maxlen(app.getId(), 4).toLowerCase()) >= 0);
- Assert.assertTrue(result.indexOf("-"+Strings.maxlen(child.getId(), 4).toLowerCase()) >= 0);
- }
-
- @Test
- public void testGenerateNewMachineUniqueNameFromGroupId() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- CloudMachineNamer namer = new BasicCloudMachineNamer();
-
- String groupId = namer.generateNewGroupId(cfg);
- String result = namer.generateNewMachineUniqueNameFromGroupId(cfg, groupId);
- Assert.assertTrue(result.startsWith(groupId));
- Assert.assertTrue(result.length() == groupId.length() + 5);
- }
-
- @Test
- public void testLengthMaxPermittedForMachineName() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- BasicCloudMachineNamer namer = new BasicCloudMachineNamer();
- namer.setDefaultMachineNameMaxLength(10);
- String result = namer.generateNewMachineUniqueName(cfg);
- Assert.assertEquals(result.length(), 10);
- }
-
- @Test
- public void testLengthReservedForNameInGroup() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TistApp"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- BasicCloudMachineNamer namer = new BasicCloudMachineNamer();
- namer.setDefaultMachineNameMaxLength(20);
- namer.setDefaultMachineNameSeparatorAndSaltLength(":I", 5);
- String groupId = namer.generateNewGroupId(cfg);
- Assert.assertEquals(13, groupId.length(), "groupId="+groupId);
- String machineId = namer.generateNewMachineUniqueNameFromGroupId(cfg, groupId);
- Assert.assertEquals(20, machineId.length(), "machineId="+machineId);
- // separator is not sanitized -- caller should know what they are doing there!
- Assert.assertTrue(machineId.startsWith(groupId+"-i"), "machineId="+machineId);
- }
-
- @Test
- public void testSanitizesNewMachineName() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("T_%$()\r\n\t[]*.!App"), LocalManagementContextForTests.newInstance());
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("ent"));
-
- ConfigBag cfg = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- CloudMachineNamer namer = new BasicCloudMachineNamer();
-
- String result = namer.generateNewMachineUniqueName(cfg);
- assertTrue(result.indexOf("t-ap") >= 0, "result="+result);
- for (int c : "_%$()\r\n\t[]*.!".getBytes()) {
- assertFalse(result.contains(new String(new char [] {(char)c})), "result="+result);
- }
- }
-
- @Test
- public void testSanitize() {
- Assert.assertEquals(AbstractCloudMachineNamer.sanitize(
- "me & you like alphanumeric but not _ or !!! or dots...dots...dots %$()\r\n\t[]*etc"),
- "me-you-like-alphanumeric-but-not-or-or-dots-dots-dots-etc");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/cloud/CustomMachineNamerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/cloud/CustomMachineNamerTest.java b/core/src/test/java/org/apache/brooklyn/location/cloud/CustomMachineNamerTest.java
deleted file mode 100644
index 3ca0358..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/cloud/CustomMachineNamerTest.java
+++ /dev/null
@@ -1,78 +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.cloud;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.location.cloud.names.CustomMachineNamer;
-
-import com.google.common.collect.ImmutableMap;
-
-public class CustomMachineNamerTest {
-
- private TestApplication app;
- private TestEntity child;
- private ConfigBag config;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() {
- app = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class).displayName("TestApp"), LocalManagementContextForTests.newInstance());
- child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt"));
- config = new ConfigBag()
- .configure(CloudLocationConfig.CALLER_CONTEXT, child);
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
- @Test
- public void testMachineNameNoConfig() {
- config.configure(CloudLocationConfig.CALLER_CONTEXT, child);
- Assert.assertEquals(new CustomMachineNamer().generateNewMachineUniqueName(config), "TestEnt");
- }
-
- @Test
- public void testMachineNameWithConfig() {
- child.setSequenceValue(999);
- config.configure(CustomMachineNamer.MACHINE_NAME_TEMPLATE, "number${entity.sequenceValue}");
- Assert.assertEquals(new CustomMachineNamer().generateNewMachineUniqueName(config), "number999");
- }
-
- @Test
- public void testMachineNameWithExtraSubstitutions() {
- config.configure(CustomMachineNamer.MACHINE_NAME_TEMPLATE, "foo-${fooName}-bar-${barName}-baz-${bazName.substitution}")
- .configure(CustomMachineNamer.EXTRA_SUBSTITUTIONS, ImmutableMap.of("fooName", "foo", "barName", "bar", "bazName", this));
- Assert.assertEquals(new CustomMachineNamer().generateNewMachineUniqueName(config), "foo-foo-bar-bar-baz-baz");
- }
-
- public String getSubstitution() {
- return "baz";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/core/AbstractLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/core/AbstractLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/core/AbstractLocationTest.java
deleted file mode 100644
index c3e8554..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/core/AbstractLocationTest.java
+++ /dev/null
@@ -1,185 +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.core;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.location.core.AbstractLocation;
-import org.apache.brooklyn.location.core.internal.LocationInternal;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.collections.MutableSet;
-import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-public class AbstractLocationTest {
-
- public static class ConcreteLocation extends AbstractLocation {
- private static final long serialVersionUID = 3954199300889119970L;
- @SetFromFlag(defaultVal="mydefault")
- String myfield;
-
- public ConcreteLocation() {
- super();
- }
-
- public ConcreteLocation(Map<?,?> properties) {
- super(properties);
- }
- }
-
- private ManagementContext mgmt;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- mgmt = LocalManagementContextForTests.newInstance();
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown(){
- if (mgmt!=null) Entities.destroyAll(mgmt);
- }
-
- private ConcreteLocation createConcrete() {
- return createConcrete(MutableMap.<String,Object>of());
- }
- private ConcreteLocation createConcrete(Map<String,?> flags) {
- return createConcrete(null, flags);
- }
- @SuppressWarnings("deprecation")
- private ConcreteLocation createConcrete(String id, Map<String,?> flags) {
- return mgmt.getLocationManager().createLocation( LocationSpec.create(ConcreteLocation.class).id(id).configure(flags) );
- }
-
- @Test
- public void testEqualsUsesId() {
- Location l1 = createConcrete("1", MutableMap.of("name", "bob"));
- Location l1b = new ConcreteLocation(ImmutableMap.of("id", 1));
- Location l2 = createConcrete("2", MutableMap.of("name", "frank"));
- assertEquals(l1, l1b);
- assertNotEquals(l1, l2);
- }
-
- @Test
- public void nullNameAndParentLocationIsAcceptable() {
- Location location = createConcrete(MutableMap.of("name", null, "parentLocation", null));
- assertEquals(location.getDisplayName(), null);
- assertEquals(location.getParent(), null);
- }
-
- @Test
- public void testSettingParentLocation() {
- Location location = createConcrete();
- Location locationSub = createConcrete();
- locationSub.setParent(location);
-
- assertEquals(ImmutableList.copyOf(location.getChildren()), ImmutableList.of(locationSub));
- assertEquals(locationSub.getParent(), location);
- }
-
- @Test
- public void testClearingParentLocation() {
- Location location = createConcrete();
- Location locationSub = createConcrete();
- locationSub.setParent(location);
-
- locationSub.setParent(null);
- assertEquals(ImmutableList.copyOf(location.getChildren()), Collections.emptyList());
- assertEquals(locationSub.getParent(), null);
- }
-
- @Test
- public void testContainsLocation() {
- Location location = createConcrete();
- Location locationSub = createConcrete();
- locationSub.setParent(location);
-
- assertTrue(location.containsLocation(location));
- assertTrue(location.containsLocation(locationSub));
- assertFalse(locationSub.containsLocation(location));
- }
-
-
- @Test
- public void queryingNameReturnsNameGivenInConstructor() {
- String name = "Outer Mongolia";
- Location location = createConcrete(MutableMap.of("name", "Outer Mongolia"));
- assertEquals(location.getDisplayName(), name);;
- }
-
- @Test
- public void constructorParentLocationReturnsExpectedLocation() {
- Location parent = createConcrete(MutableMap.of("name", "Middle Earth"));
- Location child = createConcrete(MutableMap.of("name", "The Shire", "parentLocation", parent));
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void setParentLocationReturnsExpectedLocation() {
- Location parent = createConcrete(MutableMap.of("name", "Middle Earth"));
- Location child = createConcrete(MutableMap.of("name", "The Shire"));
- child.setParent(parent);
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void testAddChildToParentLocationReturnsExpectedLocation() {
- ConcreteLocation parent = createConcrete();
- Location child = createConcrete();
- parent.addChild(child);
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void testFieldSetFromFlag() {
- ConcreteLocation loc = createConcrete(MutableMap.of("myfield", "myval"));
- assertEquals(loc.myfield, "myval");
- }
-
- @Test
- public void testFieldSetFromFlagUsesDefault() {
- ConcreteLocation loc = createConcrete();
- assertEquals(loc.myfield, "mydefault");
- }
-
- @Test
- public void testLocationTags() throws Exception {
- LocationInternal loc = mgmt.getLocationManager().createLocation(LocationSpec.create(ConcreteLocation.class).tag("x"));
- assertEquals(loc.tags().getTags(), MutableSet.of("x"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/core/AggregatingMachineProvisioningLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/core/AggregatingMachineProvisioningLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/core/AggregatingMachineProvisioningLocationTest.java
deleted file mode 100644
index 0e2a4d4..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/core/AggregatingMachineProvisioningLocationTest.java
+++ /dev/null
@@ -1,117 +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.core;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-import java.util.Map;
-
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.location.MachineProvisioningLocation;
-import org.apache.brooklyn.api.location.NoMachinesAvailableException;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
-import org.apache.brooklyn.location.core.AggregatingMachineProvisioningLocation;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation.LocalhostMachine;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-public class AggregatingMachineProvisioningLocationTest {
-
-
- private LocalManagementContext managementContext;
- private AggregatingMachineProvisioningLocation<LocalhostMachine> aggregator;
- private LocalhostMachine machine1a;
- private LocalhostMachine machine1b;
- private LocalhostMachine machine2a;
- private LocalhostMachine machine2b;
- private MachineProvisioningLocation<LocalhostMachine> provisioner1;
- private MachineProvisioningLocation<LocalhostMachine> provisioner2;
-
- @BeforeMethod(alwaysRun=true)
- @SuppressWarnings("unchecked")
- public void setUp() {
- managementContext = new LocalManagementContextForTests();
- machine1a = newLocation(LocalhostMachine.class, "1a");
- machine1b = newLocation(LocalhostMachine.class, "1b");
- machine2a = newLocation(LocalhostMachine.class, "2a");
- machine2b = newLocation(LocalhostMachine.class, "2b");
- provisioner1 = newLocation(FixedListMachineProvisioningLocation.class, ImmutableMap.of("machines", ImmutableList.of(machine1a, machine1b)));
- provisioner2 = newLocation(FixedListMachineProvisioningLocation.class, ImmutableMap.of("machines", ImmutableList.of(machine2a, machine2b)));
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() {
- if (managementContext != null) Entities.destroyAll(managementContext);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testObtainAndRelease() throws Exception {
- aggregator = newLocation(AggregatingMachineProvisioningLocation.class, ImmutableMap.of("provisioners", ImmutableList.of(provisioner1, provisioner2)));
- assertEquals(aggregator.obtain(), machine1a);
- assertEquals(aggregator.obtain(), machine2a);
- assertEquals(aggregator.obtain(), machine1b);
- assertEquals(aggregator.obtain(), machine2b);
-
- try {
- aggregator.obtain();
- fail();
- } catch (NoMachinesAvailableException e) {
- // success
- }
-
- aggregator.release(machine2b);
- assertEquals(aggregator.obtain(), machine2b);
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testReleaseWhenNotHeldThrows() throws Exception {
- aggregator = newLocation(AggregatingMachineProvisioningLocation.class, ImmutableMap.of("provisioners", ImmutableList.of(provisioner1, provisioner2)));
- try {
- aggregator.release(machine1a);
- fail();
- } catch (IllegalStateException e) {
- if (!e.toString().contains("machine is not currently allocated")) throw e;
- }
- }
-
- private <T extends Location> T newLocation(Class<T> clazz, String displayName) {
- return newLocation(clazz, displayName, ImmutableMap.of());
- }
-
- private <T extends Location> T newLocation(Class<T> clazz, Map<?,?> config) {
- return newLocation(clazz, "mydisplayname", config);
- }
-
- private <T extends Location> T newLocation(Class<T> clazz, String displayName, Map<?,?> config) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(clazz)
- .displayName(displayName)
- .configure(config));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/538324e1/core/src/test/java/org/apache/brooklyn/location/core/LegacyAbstractLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/core/LegacyAbstractLocationTest.java b/core/src/test/java/org/apache/brooklyn/location/core/LegacyAbstractLocationTest.java
deleted file mode 100644
index d5d5ae7..0000000
--- a/core/src/test/java/org/apache/brooklyn/location/core/LegacyAbstractLocationTest.java
+++ /dev/null
@@ -1,151 +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.core;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.brooklyn.location.core.AbstractLocation;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-
-public class LegacyAbstractLocationTest {
-
- private static class ConcreteLocation extends AbstractLocation {
- @SetFromFlag(defaultVal="mydefault")
- String myfield;
-
- public ConcreteLocation() {
- super();
- }
-
- public ConcreteLocation(Map properties) {
- super(properties);
- }
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown(){
- // nothing to tear down; did not create a management context
- }
-
- @Test
- public void testEquals() {
- AbstractLocation l1 = new ConcreteLocation(MutableMap.of("id", "1", "name", "bob"));
- AbstractLocation l2 = new ConcreteLocation(MutableMap.of("id", "1", "name", "frank"));
- AbstractLocation l3 = new ConcreteLocation(MutableMap.of("id", "2", "name", "frank"));
- assertEquals(l1, l2);
- assertNotEquals(l2, l3);
- }
-
- @Test
- public void nullNameAndParentLocationIsAcceptable() {
- AbstractLocation location = new ConcreteLocation(MutableMap.of("name", null, "parentLocation", null));
- assertEquals(location.getDisplayName(), null);
- assertEquals(location.getParent(), null);
- }
-
- @Test
- public void testSettingParentLocation() {
- AbstractLocation location = new ConcreteLocation();
- AbstractLocation locationSub = new ConcreteLocation();
- locationSub.setParent(location);
-
- assertEquals(ImmutableList.copyOf(location.getChildren()), ImmutableList.of(locationSub));
- assertEquals(locationSub.getParent(), location);
- }
-
- @Test
- public void testClearingParentLocation() {
- AbstractLocation location = new ConcreteLocation();
- AbstractLocation locationSub = new ConcreteLocation();
- locationSub.setParent(location);
-
- locationSub.setParent(null);
- assertEquals(ImmutableList.copyOf(location.getChildren()), Collections.emptyList());
- assertEquals(locationSub.getParent(), null);
- }
-
- @Test
- public void testContainsLocation() {
- AbstractLocation location = new ConcreteLocation();
- AbstractLocation locationSub = new ConcreteLocation();
- locationSub.setParent(location);
-
- assertTrue(location.containsLocation(location));
- assertTrue(location.containsLocation(locationSub));
- assertFalse(locationSub.containsLocation(location));
- }
-
-
- @Test
- public void queryingNameReturnsNameGivenInConstructor() {
- String name = "Outer Mongolia";
- AbstractLocation location = new ConcreteLocation(MutableMap.of("name", "Outer Mongolia"));
- assertEquals(location.getDisplayName(), name);;
- }
-
- @Test
- public void constructorParentLocationReturnsExpectedLocation() {
- AbstractLocation parent = new ConcreteLocation(MutableMap.of("name", "Middle Earth"));
- AbstractLocation child = new ConcreteLocation(MutableMap.of("name", "The Shire", "parentLocation", parent));
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void setParentLocationReturnsExpectedLocation() {
- AbstractLocation parent = new ConcreteLocation(MutableMap.of("name", "Middle Earth"));
- AbstractLocation child = new ConcreteLocation(MutableMap.of("name", "The Shire"));
- child.setParent(parent);
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void testAddChildToParentLocationReturnsExpectedLocation() {
- AbstractLocation parent = new ConcreteLocation(MutableMap.of("id", "1"));
- AbstractLocation child = new ConcreteLocation(MutableMap.of("id", "2"));
- parent.addChild(child);
- assertEquals(child.getParent(), parent);
- assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child));
- }
-
- @Test
- public void testFieldSetFromFlag() {
- ConcreteLocation loc = new ConcreteLocation(MutableMap.of("myfield", "myval"));
- assertEquals(loc.myfield, "myval");
- }
-
- @Test
- public void testFieldSetFromFlagUsesDefault() {
- ConcreteLocation loc = new ConcreteLocation();
- assertEquals(loc.myfield, "mydefault");
- }
-
-}