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/12 17:55:29 UTC
[11/35] incubator-brooklyn git commit: [BROOKLYN-162] package rename
to org.apache.brooklyn: software/webapp
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java b/software/webapp/src/test/java/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
deleted file mode 100644
index d26f1a9..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/dns/AbstractGeoDnsServiceTest.java
+++ /dev/null
@@ -1,320 +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 brooklyn.entity.dns;
-
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.brooklyn.management.ManagementContext;
-import org.apache.brooklyn.test.EntityTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.ConfigKeys;
-import brooklyn.entity.basic.DynamicGroup;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.group.DynamicFabric;
-import brooklyn.entity.group.DynamicRegionsFabric;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.proxying.ImplementedBy;
-import brooklyn.location.Location;
-import brooklyn.location.LocationRegistry;
-import brooklyn.location.LocationResolver;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.BasicLocationRegistry;
-import brooklyn.location.basic.LocationConfigKeys;
-import brooklyn.location.basic.Locations;
-import brooklyn.location.basic.Machines;
-import brooklyn.location.basic.SimulatedLocation;
-import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.location.geo.HostGeoInfo;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.test.entity.TestApplication;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.util.collections.CollectionFunctionals;
-import brooklyn.util.exceptions.Exceptions;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-
-public class AbstractGeoDnsServiceTest {
- public static final Logger log = LoggerFactory.getLogger(AbstractGeoDnsServiceTest.class);
-
- private static final String WEST_IP = "100.0.0.1";
- private static final String EAST_IP = "100.0.0.2";
- private static final double WEST_LATITUDE = 0, WEST_LONGITUDE = -60;
- private static final double EAST_LATITUDE = 0, EAST_LONGITUDE = 60;
-
- private static final String NORTH_IP = "10.0.0.1";
- private static final double NORTH_LATITUDE = 60, NORTH_LONGITUDE = 0;
-
- private ManagementContext managementContext;
-
- private Location westParent;
- private Location westChild;
- private Location westChildWithLocation;
- private Location eastParent;
- private Location eastChild;
- private Location eastChildWithLocationAndWithPrivateHostname;
-
- private Location northParent;
- private Location northChildWithLocation;
-
- private TestApplication app;
- private DynamicRegionsFabric fabric;
- private DynamicGroup testEntities;
- private GeoDnsTestService geoDns;
-
-
- @BeforeMethod(alwaysRun=true)
- public void setup() {
- managementContext = new LocalManagementContext();
-
- westParent = newSimulatedLocation("West parent", WEST_LATITUDE, WEST_LONGITUDE);
-
- // west uses public IP for name, so is always picked up
- westChild = newSshMachineLocation("West child", WEST_IP, westParent);
- westChildWithLocation = newSshMachineLocation("West child with location", WEST_IP, WEST_IP, westParent, WEST_LATITUDE, WEST_LONGITUDE);
-
- // east has public IP but private IP hostname, so should also be picked up but by a different path
- eastParent = newSimulatedLocation("East parent", EAST_LATITUDE, EAST_LONGITUDE);
- eastChild = newSshMachineLocation("East child", EAST_IP, eastParent);
- eastChildWithLocationAndWithPrivateHostname = newSshMachineLocation("East child with location", "localhost", EAST_IP, eastParent, EAST_LATITUDE, EAST_LONGITUDE);
-
- // north has a private IP and private hostname so should not be picked up when we turn off ADD_ANYTHING
- northParent = newSimulatedLocation("North parent", NORTH_LATITUDE, NORTH_LONGITUDE);
- northChildWithLocation = newSshMachineLocation("North child", "localhost", NORTH_IP, northParent, NORTH_LATITUDE, NORTH_LONGITUDE);
- ((BasicLocationRegistry)managementContext.getLocationRegistry()).registerResolver(new LocationResolver() {
- @Override
- public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry) {
- if (!spec.equals("test:north")) throw new IllegalStateException("unsupported");
- return northChildWithLocation;
- }
- @Override
- public void init(ManagementContext managementContext) {
- }
- @Override
- public String getPrefix() {
- return "test";
- }
- @Override
- public boolean accepts(String spec, LocationRegistry registry) {
- return spec.startsWith(getPrefix());
- }
- });
-
- Locations.manage(westParent, managementContext);
- Locations.manage(eastParent, managementContext);
- Locations.manage(northParent, managementContext);
-
- app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
- fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
- .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
-
- testEntities = app.createAndManageChild(EntitySpec.create(DynamicGroup.class)
- .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)));
- geoDns = app.createAndManageChild(EntitySpec.create(GeoDnsTestService.class));
- geoDns.setTargetEntityProvider(testEntities);
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- }
-
- private SimulatedLocation newSimulatedLocation(String name, double lat, double lon) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)
- .displayName(name)
- .configure("latitude", lat)
- .configure("longitude", lon));
- }
-
- private Location newSshMachineLocation(String name, String address, Location parent) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .parent(parent)
- .displayName(name)
- .configure("address", address));
- }
-
- private Location newSshMachineLocation(String name, String hostname, String address, Location parent, double lat, double lon) {
- return managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .parent(parent)
- .displayName(name)
- .configure("hostname", hostname)
- .configure("address", address)
- .configure("latitude", lat)
- .configure("longitude", lon));
- }
-
- @Test
- public void testGeoInfoOnLocation() {
- app.start( ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname) );
- publishSensors(2, true, true, true);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child with location"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
- }
-
- @Test
- public void testGeoInfoOnParentLocation() {
- app.start( ImmutableList.of(westChild, eastChild) );
- publishSensors(2, true, false, false);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child"), "targets="+geoDns.getTargetHostsByName());
- }
-
- @Test
- public void testSubscribesToHostname() {
- ((EntityInternal)geoDns).setConfig(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
- app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname) );
- Assert.assertEquals(geoDns.getTargetHostsByName().size(), 0);
- publishSensors(2, true, true, true);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- Assert.assertEquals(geoDns.getTargetHostsByName().size(), 2);
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
- }
-
- protected void publishSensors(int expectedSize, boolean includeServiceUp, boolean includeHostname, boolean includeAddress) {
- // First wait for the right size of group; the dynamic group gets notified asynchronously
- // of nodes added/removed, so if we don't wait then might not set value for all members.
- EntityTestUtils.assertGroupSizeEqualsEventually(testEntities, expectedSize);
-
- for (Entity e: testEntities.getMembers()) {
- if (includeServiceUp)
- ((EntityInternal)e).setAttribute(Attributes.SERVICE_UP, true);
-
- SshMachineLocation l = Machines.findUniqueSshMachineLocation(e.getLocations()).get();
- if (includeAddress)
- ((EntityInternal)e).setAttribute(Attributes.ADDRESS, l.getAddress().getHostAddress());
- String h = (String) l.config().getBag().getStringKey("hostname");
- if (h==null) h = l.getAddress().getHostName();
- if (includeHostname)
- ((EntityInternal)e).setAttribute(Attributes.HOSTNAME, h);
- }
- }
-
- @Test
- public void testChildAddedLate() {
- app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname) );
- publishSensors(2, true, false, false);
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
-
- String id3 = fabric.addRegion("test:north");
- publishSensors(3, true, false, false);
- try {
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(3));
- } catch (Throwable e) {
- log.warn("Did not pick up third entity, targets are "+geoDns.getAttribute(AbstractGeoDnsService.TARGETS)+" (rethrowing): "+e);
- Exceptions.propagate(e);
- }
- assertTrue(geoDns.getTargetHostsByName().containsKey("North child"), "targets="+geoDns.getTargetHostsByName());
-
- log.info("targets: "+geoDns.getTargetHostsByName());
- }
-
-
- @Test
- public void testFiltersEntirelyPrivate() {
- ((EntityInternal)geoDns).setConfig(GeoDnsTestServiceImpl.ADD_ANYTHING, false);
- app.start( ImmutableList.of(westChild, eastChildWithLocationAndWithPrivateHostname, northChildWithLocation) );
- Assert.assertEquals(geoDns.getTargetHostsByName().size(), 0);
- publishSensors(3, true, true, true);
-
- EntityTestUtils.assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2));
- Assert.assertEquals(geoDns.getTargetHostsByName().size(), 2);
- assertTrue(geoDns.getTargetHostsByName().containsKey("West child"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(geoDns.getTargetHostsByName().containsKey("East child with location"), "targets="+geoDns.getTargetHostsByName());
- assertTrue(!geoDns.getTargetHostsByName().containsKey("North child"), "targets="+geoDns.getTargetHostsByName());
- }
-
- @ImplementedBy(GeoDnsTestServiceImpl.class)
- public static interface GeoDnsTestService extends AbstractGeoDnsService {
- public Map<String, HostGeoInfo> getTargetHostsByName();
- }
-
- public static class GeoDnsTestServiceImpl extends AbstractGeoDnsServiceImpl implements GeoDnsTestService {
- public Map<String, HostGeoInfo> targetHostsByName = new LinkedHashMap<String, HostGeoInfo>();
-
- public static final ConfigKey<Boolean> ADD_ANYTHING = ConfigKeys.newBooleanConfigKey("test.add.always", "", true);
-
- public GeoDnsTestServiceImpl() {
- }
-
- @Override
- public Map<String, HostGeoInfo> getTargetHostsByName() {
- synchronized (targetHostsByName) {
- return ImmutableMap.copyOf(targetHostsByName);
- }
- }
-
- @Override
- protected boolean addTargetHost(Entity e) {
- if (!getConfig(ADD_ANYTHING)) {
- return super.addTargetHost(e);
- } else {
- //ignore geo lookup, override parent menu
- if (e.getLocations().isEmpty()) {
- log.info("GeoDns TestService ignoring target host {} (no location)", e);
- return false;
- }
- Location l = Iterables.getOnlyElement(e.getLocations());
- HostGeoInfo geoInfo = new HostGeoInfo("<address-ignored>", l.getDisplayName(),
- l.getConfig(LocationConfigKeys.LATITUDE), l.getConfig(LocationConfigKeys.LONGITUDE));
- log.info("GeoDns TestService adding target host {} {}", e, geoInfo);
- targetHosts.put(e, geoInfo);
- return true;
- }
- }
-
- @Override
- protected void reconfigureService(Collection<HostGeoInfo> targetHosts) {
- synchronized (targetHostsByName) {
- targetHostsByName.clear();
- for (HostGeoInfo host : targetHosts) {
- if (host != null) targetHostsByName.put(host.displayName, host);
- }
- }
- }
-
- @Override
- public String getHostname() {
- return "localhost";
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
deleted file mode 100644
index 12ffe6e..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingIntegrationTest.java
+++ /dev/null
@@ -1,211 +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 brooklyn.entity.dns.geoscaling;
-
-import static org.testng.Assert.assertEquals;
-
-import java.net.InetAddress;
-
-import org.apache.brooklyn.management.ManagementContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.DynamicGroup;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityLocal;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.location.geo.HostGeoInfo;
-import brooklyn.location.geo.HostGeoLookup;
-import brooklyn.location.geo.MaxMind2HostGeoLookup;
-import brooklyn.location.geo.UtraceHostGeoLookup;
-import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.internal.BrooklynSystemProperties;
-import brooklyn.util.net.Networking;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-
-/**
- * {@link GeoscalingScriptGenerator} unit tests.
- */
-public class GeoscalingIntegrationTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(GeoscalingIntegrationTest.class);
-
- private final String primaryDomain = "geopaas.org";//"domain"+((int)(Math.random()*10000))+".test.org";
- private final String subDomain = "subdomain"+((int)(Math.random()*10000));
- private final InetAddress addrWithGeo = Networking.getLocalHost();
- private final InetAddress addrWithoutGeo = Networking.getInetAddressWithFixedName(StubHostGeoLookup.HOMELESS_IP);
-
- private ManagementContext mgmt;
- private TestApplication app;
- private TestEntity target;
- private DynamicGroup group;
- private GeoscalingDnsService geoDns;
- private String origGeoLookupImpl;
-
- private SshMachineLocation locWithGeo;
- private SshMachineLocation locWithoutGeo;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- origGeoLookupImpl = BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getValue();
- HostGeoInfo.clearCachedLookup();
-
- app = TestApplication.Factory.newManagedInstanceForTests();
- mgmt = app.getManagementContext();
-
- target = app.createAndManageChild(EntitySpec.create(TestEntity.class));
-
- group = app.createAndManageChild(EntitySpec.create(DynamicGroup.class)
- .configure(DynamicGroup.ENTITY_FILTER, Predicates.instanceOf(TestEntity.class)));
-
- geoDns = app.createAndManageChild(EntitySpec.create(GeoscalingDnsService.class)
- .displayName("Geo-DNS")
- .configure("username", "cloudsoft")
- .configure("password", "cl0uds0ft")
- .configure("primaryDomainName", primaryDomain)
- .configure("smartSubdomainName", subDomain)
- .configure("targetEntityProvider", group));
-
- locWithGeo = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", addrWithGeo)
- .configure("name", "Edinburgh")
- .configure("latitude", 55.94944)
- .configure("longitude", -3.16028)
- .configure("iso3166", ImmutableList.of("GB-EDH")));
-
- locWithoutGeo = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", addrWithoutGeo)
- .configure("name", "Nowhere"));
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (origGeoLookupImpl != null) {
- System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), origGeoLookupImpl);
- } else {
- System.clearProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName());
- }
- if (mgmt != null) Entities.destroyAll(mgmt);
- HostGeoInfo.clearCachedLookup();
- }
-
- @Test(groups={"Integration"})
- public void testRoutesToExpectedLocation() {
- // Without this config, running on a home network (i.e. no public IP) the entity will have a private IP and will be ignored
- ((EntityLocal)geoDns).setConfig(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
-
- target.setAttribute(Attributes.HOSTNAME,addrWithGeo.getHostName());
-
- app.start(ImmutableList.of(locWithGeo));
-
- LOG.info("geo-scaling test, using {}.{}; expect to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithGeo});
-
- assertTargetHostsEventually(geoDns, 1);
- }
-
- @Test(groups={"Integration"})
- public void testIgnoresAddressWithoutGeography() throws Exception {
- System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName());
- ((EntityLocal)geoDns).setConfig(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, false); // false is default
-
- app.start(ImmutableList.of(locWithoutGeo));
- target.setAttribute(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP);
-
- LOG.info("geo-scaling test, using {}.{}; expect not to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithoutGeo});
-
- Asserts.succeedsContinually(MutableMap.of("timeout", 10*1000), new Runnable() {
- @Override public void run() {
- assertEquals(geoDns.getTargetHosts().size(), 0, "targets="+geoDns.getTargetHosts());
- }
- });
- }
-
- @Test(groups={"Integration"})
- public void testIncludesAddressWithoutGeography() {
- System.setProperty(BrooklynSystemProperties.HOST_GEO_LOOKUP_IMPL.getPropertyName(), StubHostGeoLookup.class.getName());
- ((EntityLocal)geoDns).setConfig(GeoscalingDnsService.INCLUDE_HOMELESS_ENTITIES, true);
-
- app.start(ImmutableList.of(locWithoutGeo));
- target.setAttribute(Attributes.HOSTNAME, StubHostGeoLookup.HOMELESS_IP);
-
- LOG.info("geo-scaling test, using {}.{}; expect to be wired to {}", new Object[] {subDomain, primaryDomain, addrWithoutGeo});
-
- assertTargetHostsEventually(geoDns, 1);
- }
-
- private void assertTargetHostsEventually(final GeoscalingDnsService geoDns, final int numExpected) {
- Asserts.succeedsEventually(new Runnable() {
- @Override public void run() {
- assertEquals(geoDns.getTargetHosts().size(), 1, "targets="+geoDns.getTargetHosts());
- }
- });
- }
-
- public static class StubHostGeoLookup implements HostGeoLookup {
- public static final String HOMELESS_IP = "1.2.3.4";
- private final HostGeoLookup delegate;
-
- public StubHostGeoLookup() throws Exception {
- this(null);
- }
-
- public StubHostGeoLookup(String delegateImpl) throws Exception {
- if (delegateImpl == null) {
- // don't just call HostGeoInfo.getDefaultLookup; this is the default lookup!
- if (MaxMind2HostGeoLookup.getDatabaseReader()!=null) {
- delegate = new MaxMind2HostGeoLookup();
- } else {
- delegate = new UtraceHostGeoLookup();
- }
- } else {
- delegate = (HostGeoLookup) Class.forName(delegateImpl).newInstance();
- }
- }
-
- @Override
- public HostGeoInfo getHostGeoInfo(InetAddress address) throws Exception {
- // Saw strange test failure on jenkins: hence paranoid logging, just in case exception is swallowed somehow.
- try {
- HostGeoInfo result;
- if (HOMELESS_IP.equals(address.getHostAddress())) {
- result = null;
- } else {
- result = delegate.getHostGeoInfo(address);
- }
- LOG.info("StubHostGeoLookup.getHostGeoInfo queried: address="+address+"; hostAddress="+address.getHostAddress()+"; result="+result);
- return result;
- } catch (Throwable t) {
- LOG.error("StubHostGeoLookup.getHostGeoInfo encountered problem (rethrowing): address="+address+"; hostAddress="+address.getHostAddress(), t);
- throw Exceptions.propagate(t);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingScriptGeneratorTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingScriptGeneratorTest.java b/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingScriptGeneratorTest.java
deleted file mode 100644
index 611e391..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingScriptGeneratorTest.java
+++ /dev/null
@@ -1,58 +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 brooklyn.entity.dns.geoscaling;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Date;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.testng.annotations.Test;
-
-import brooklyn.location.geo.HostGeoInfo;
-import brooklyn.util.ResourceUtils;
-
-
-/**
- * {@link GeoscalingScriptGenerator} unit tests.
- */
-public class GeoscalingScriptGeneratorTest {
-
- private final static Set<HostGeoInfo> HOSTS = new LinkedHashSet<HostGeoInfo>();
- static {
- HOSTS.add(new HostGeoInfo("1.2.3.100", "Server 1", 40.0, -80.0));
- HOSTS.add(new HostGeoInfo("1.2.3.101", "Server 2", 30.0, 20.0));
- }
-
-
- @Test
- public void testScriptGeneration() {
- Date generationTime = new Date(0);
- String generatedScript = GeoscalingScriptGenerator.generateScriptString(generationTime, HOSTS);
- assertTrue(generatedScript.contains("1.2.3"));
- String expectedScript = ResourceUtils.create(this).getResourceAsString("brooklyn/entity/dns/geoscaling/expectedScript.php");
- assertEquals(generatedScript, expectedScript);
- //also make sure leading slash is allowed
- String expectedScript2 = ResourceUtils.create(this).getResourceAsString("/brooklyn/entity/dns/geoscaling/expectedScript.php");
- assertEquals(generatedScript, expectedScript);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java b/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.java
deleted file mode 100644
index 73584b2..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/dns/geoscaling/GeoscalingWebClientTest.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 brooklyn.entity.dns.geoscaling;
-
-import static brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROVIDE_CITY_INFO;
-import static brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROVIDE_COUNTRY_INFO;
-import static brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROVIDE_EXTRA_INFO;
-import static brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROVIDE_NETWORK_INFO;
-import static brooklyn.entity.dns.geoscaling.GeoscalingWebClient.PROVIDE_UPTIME_INFO;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-import org.apache.http.client.HttpClient;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.dns.geoscaling.GeoscalingWebClient.Domain;
-import brooklyn.entity.dns.geoscaling.GeoscalingWebClient.SmartSubdomain;
-import brooklyn.util.http.HttpTool;
-import brooklyn.util.text.Strings;
-
-/**
- * {@link GeoscalingWebClient} unit tests.
- */
-public class GeoscalingWebClientTest {
-
- private final static String GEOSCALING_URL = "https://www.geoscaling.com";
- private final static String USERNAME = "cloudsoft";
- private final static String PASSWORD = "cl0uds0ft";
-
- private final static String PRIMARY_DOMAIN = "domain-" + Strings.makeRandomId(5) + ".test.org";
- private final static String SUBDOMAIN = "subdomain-" + Strings.makeRandomId(5);
-
- private final static String DEFAULT_SCRIPT = "output[] = array(\"fail\");";
-
- private GeoscalingWebClient geoscaling;
-
- private Domain domain;
- private SmartSubdomain smartSubdomain;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() {
- // Insecurely use "trustAll" so that don't need to import signature into trust store
- // before test will work on jenkins machine.
- HttpClient httpClient = HttpTool.httpClientBuilder().uri(GEOSCALING_URL).trustAll().build();
- geoscaling = new GeoscalingWebClient(httpClient);
- geoscaling.login(USERNAME, PASSWORD);
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() {
- if (smartSubdomain != null)
- smartSubdomain.delete();
-
- if (domain != null)
- domain.delete();
-
- if (geoscaling != null)
- geoscaling.logout();
- }
-
- @Test(groups = "Integration")
- public void testSimpleNames() {
- testWebClient(PRIMARY_DOMAIN, SUBDOMAIN);
- }
-
- @Test(groups = "Integration")
- public void testMixedCaseNames() {
- testWebClient("MixedCase-"+PRIMARY_DOMAIN, "MixedCase-"+SUBDOMAIN);
- }
-
- public void testWebClient(String primaryDomainName, String smartSubdomainName) {
- assertNull(geoscaling.getPrimaryDomain(primaryDomainName));
- geoscaling.createPrimaryDomain(primaryDomainName);
- domain = geoscaling.getPrimaryDomain(primaryDomainName);
- assertNotNull(domain);
-
- assertNull(domain.getSmartSubdomain(smartSubdomainName));
- domain.createSmartSubdomain(smartSubdomainName);
- smartSubdomain = domain.getSmartSubdomain(smartSubdomainName);
- assertNotNull(smartSubdomain);
-
- smartSubdomain.configure(
- PROVIDE_NETWORK_INFO | PROVIDE_CITY_INFO | PROVIDE_COUNTRY_INFO | PROVIDE_EXTRA_INFO | PROVIDE_UPTIME_INFO,
- DEFAULT_SCRIPT);
-
- // TODO: read-back config and verify is as expected?
- // TODO: send actual config, test ping/dig from multiple locations?
- // TODO: rename subdomain
-
- smartSubdomain.delete();
- assertNull(domain.getSmartSubdomain(smartSubdomainName));
-
- domain.delete();
- assertNull(geoscaling.getPrimaryDomain(primaryDomainName));
-
- geoscaling.logout();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/AbstractControllerTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/AbstractControllerTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/AbstractControllerTest.java
deleted file mode 100644
index 54f5779..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/AbstractControllerTest.java
+++ /dev/null
@@ -1,363 +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 brooklyn.entity.proxy;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.Inet4Address;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppUnitTestSupport;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.basic.EntityLocal;
-import brooklyn.entity.group.Cluster;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.trait.Startable;
-import brooklyn.event.AttributeSensor;
-import brooklyn.location.Location;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.MachineLocation;
-import brooklyn.location.MachineProvisioningLocation;
-import brooklyn.location.NoMachinesAvailableException;
-import brooklyn.location.basic.FixedListMachineProvisioningLocation;
-import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.test.entity.TestEntityImpl;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.collections.MutableSet;
-import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.flags.SetFromFlag;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-public class AbstractControllerTest extends BrooklynAppUnitTestSupport {
-
- private static final Logger log = LoggerFactory.getLogger(AbstractControllerTest.class);
-
- FixedListMachineProvisioningLocation<?> loc;
- Cluster cluster;
- TrackingAbstractController controller;
-
- @BeforeMethod(alwaysRun = true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- List<SshMachineLocation> machines = new ArrayList<SshMachineLocation>();
- for (int i=1; i<=10; i++) {
- SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure("address", Inet4Address.getByName("1.1.1."+i)));
- machines.add(machine);
- }
- loc = mgmt.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class)
- .configure("machines", machines));
-
- cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", 0)
- .configure("factory", new ClusteredEntity.Factory()));
-
- controller = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class)
- .configure("serverPool", cluster)
- .configure("portNumberSensor", ClusteredEntity.HTTP_PORT)
- .configure("domain", "mydomain"));
-
- app.start(ImmutableList.of(loc));
- }
-
- // Fixes bug where entity that wrapped an AS7 entity was never added to nginx because hostname+port
- // was set after service_up. Now we listen to those changes and reset the nginx pool when these
- // values change.
- @Test
- public void testUpdateCalledWhenChildHostnameAndPortChanges() throws Exception {
- TestEntity child = cluster.addChild(EntitySpec.create(TestEntity.class));
- Entities.manage(child);
- cluster.addMember(child);
-
- List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
- assertTrue(u.isEmpty(), "expected no updates, but got "+u);
-
- child.setAttribute(Startable.SERVICE_UP, true);
-
- // TODO Ugly sleep to allow AbstractController to detect node having been added
- Thread.sleep(100);
-
- child.setAttribute(ClusteredEntity.HOSTNAME, "mymachine");
- child.setAttribute(Attributes.SUBNET_HOSTNAME, "mymachine");
- child.setAttribute(ClusteredEntity.HTTP_PORT, 1234);
- assertEventuallyExplicitAddressesMatch(ImmutableList.of("mymachine:1234"));
-
- child.setAttribute(ClusteredEntity.HOSTNAME, "mymachine2");
- child.setAttribute(Attributes.SUBNET_HOSTNAME, "mymachine2");
- assertEventuallyExplicitAddressesMatch(ImmutableList.of("mymachine2:1234"));
-
- child.setAttribute(ClusteredEntity.HTTP_PORT, 1235);
- assertEventuallyExplicitAddressesMatch(ImmutableList.of("mymachine2:1235"));
-
- child.setAttribute(ClusteredEntity.HOSTNAME, null);
- child.setAttribute(Attributes.SUBNET_HOSTNAME, null);
- assertEventuallyExplicitAddressesMatch(ImmutableList.<String>of());
- }
-
- @Test
- public void testUpdateCalledWithAddressesOfNewChildren() {
- // First child
- cluster.resize(1);
- EntityLocal child = (EntityLocal) Iterables.getOnlyElement(cluster.getMembers());
-
- List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
- assertTrue(u.isEmpty(), "expected empty list but got "+u);
-
- child.setAttribute(ClusteredEntity.HTTP_PORT, 1234);
- child.setAttribute(Startable.SERVICE_UP, true);
- assertEventuallyAddressesMatchCluster();
-
- // Second child
- cluster.resize(2);
- Asserts.succeedsEventually(new Runnable() {
- @Override
- public void run() {
- assertEquals(cluster.getMembers().size(), 2);
- }});
- EntityLocal child2 = (EntityLocal) Iterables.getOnlyElement(MutableSet.builder().addAll(cluster.getMembers()).remove(child).build());
-
- child2.setAttribute(ClusteredEntity.HTTP_PORT, 1234);
- child2.setAttribute(Startable.SERVICE_UP, true);
- assertEventuallyAddressesMatchCluster();
-
- // And remove all children; expect all addresses to go away
- cluster.resize(0);
- assertEventuallyAddressesMatchCluster();
- }
-
- @Test(groups = "Integration", invocationCount=10)
- public void testUpdateCalledWithAddressesOfNewChildrenManyTimes() {
- testUpdateCalledWithAddressesOfNewChildren();
- }
-
- @Test
- public void testUpdateCalledWithAddressesRemovedForStoppedChildren() {
- // Get some children, so we can remove one...
- cluster.resize(2);
- for (Entity it: cluster.getMembers()) {
- ((EntityLocal)it).setAttribute(ClusteredEntity.HTTP_PORT, 1234);
- ((EntityLocal)it).setAttribute(Startable.SERVICE_UP, true);
- }
- assertEventuallyAddressesMatchCluster();
-
- // Now remove one child
- cluster.resize(1);
- assertEquals(cluster.getMembers().size(), 1);
- assertEventuallyAddressesMatchCluster();
- }
-
- @Test
- public void testUpdateCalledWithAddressesRemovedForServiceDownChildrenThatHaveClearedHostnamePort() {
- // Get some children, so we can remove one...
- cluster.resize(2);
- for (Entity it: cluster.getMembers()) {
- ((EntityLocal)it).setAttribute(ClusteredEntity.HTTP_PORT, 1234);
- ((EntityLocal)it).setAttribute(Startable.SERVICE_UP, true);
- }
- assertEventuallyAddressesMatchCluster();
-
- // Now unset host/port, and remove children
- // Note the unsetting of hostname is done in SoftwareProcessImpl.stop(), so this is realistic
- for (Entity it : cluster.getMembers()) {
- ((EntityLocal)it).setAttribute(ClusteredEntity.HTTP_PORT, null);
- ((EntityLocal)it).setAttribute(ClusteredEntity.HOSTNAME, null);
- ((EntityLocal)it).setAttribute(Startable.SERVICE_UP, false);
- }
- assertEventuallyAddressesMatch(ImmutableList.<Entity>of());
- }
-
- @Test
- public void testUsesHostAndPortSensor() throws Exception {
- controller = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class)
- .configure("serverPool", cluster)
- .configure("hostAndPortSensor", ClusteredEntity.HOST_AND_PORT)
- .configure("domain", "mydomain"));
- controller.start(Arrays.asList(loc));
-
- TestEntity child = cluster.addChild(EntitySpec.create(TestEntity.class));
- Entities.manage(child);
- cluster.addMember(child);
-
- List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
- assertTrue(u.isEmpty(), "expected no updates, but got "+u);
-
- child.setAttribute(Startable.SERVICE_UP, true);
-
- // TODO Ugly sleep to allow AbstractController to detect node having been added
- Thread.sleep(100);
-
- child.setAttribute(ClusteredEntity.HOST_AND_PORT, "mymachine:1234");
- assertEventuallyExplicitAddressesMatch(ImmutableList.of("mymachine:1234"));
- }
-
- @Test
- public void testFailsIfSetHostAndPortAndHostnameOrPortNumberSensor() throws Exception {
- try {
- TrackingAbstractController controller2 = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class)
- .configure("serverPool", cluster)
- .configure("hostAndPortSensor", ClusteredEntity.HOST_AND_PORT)
- .configure("hostnameSensor", ClusteredEntity.HOSTNAME)
- .configure("domain", "mydomain"));
- controller2.start(Arrays.asList(loc));
- } catch (Exception e) {
- IllegalStateException unwrapped = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
- if (unwrapped != null && unwrapped.toString().contains("Must not set Sensor")) {
- // success
- } else {
- throw e;
- }
- }
-
- try {
- TrackingAbstractController controller3 = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class)
- .configure("serverPool", cluster)
- .configure("hostAndPortSensor", ClusteredEntity.HOST_AND_PORT)
- .configure("portNumberSensor", ClusteredEntity.HTTP_PORT)
- .configure("domain", "mydomain"));
- controller3.start(Arrays.asList(loc));
- } catch (Exception e) {
- IllegalStateException unwrapped = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
- if (unwrapped != null && unwrapped.toString().contains("Must not set Sensor")) {
- // success
- } else {
- throw e;
- }
- }
- }
-
- // Manual visual inspection test. Previously it repeatedly logged:
- // Unable to construct hostname:port representation for TestEntityImpl{id=jzwSBRQ2} (null:null); skipping in TrackingAbstractControllerImpl{id=tOn4k5BA}
- // every time the service-up was set to true again.
- @Test
- public void testMemberWithoutHostAndPortDoesNotLogErrorRepeatedly() throws Exception {
- controller = app.createAndManageChild(EntitySpec.create(TrackingAbstractController.class)
- .configure("serverPool", cluster)
- .configure("domain", "mydomain"));
- controller.start(ImmutableList.of(loc));
-
- TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class));
- cluster.addMember(child);
-
- for (int i = 0; i < 100; i++) {
- child.setAttribute(Attributes.SERVICE_UP, true);
- }
-
- Thread.sleep(100);
- List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
- assertTrue(u.isEmpty(), "expected no updates, but got "+u);
- }
-
- private void assertEventuallyAddressesMatchCluster() {
- assertEventuallyAddressesMatch(cluster.getMembers());
- }
-
- private void assertEventuallyAddressesMatch(final Collection<Entity> expectedMembers) {
- Asserts.succeedsEventually(MutableMap.of("timeout", 15000), new Runnable() {
- @Override public void run() {
- assertAddressesMatch(locationsToAddresses(1234, expectedMembers));
- }} );
- }
-
- private void assertEventuallyExplicitAddressesMatch(final Collection<String> expectedAddresses) {
- Asserts.succeedsEventually(MutableMap.of("timeout", 15000), new Runnable() {
- @Override public void run() {
- assertAddressesMatch(expectedAddresses);
- }} );
- }
-
- private void assertAddressesMatch(final Collection<String> expectedAddresses) {
- List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
- Collection<String> last = Iterables.getLast(u, null);
- log.debug("test "+u.size()+" updates, expecting "+expectedAddresses+"; actual "+last);
- assertTrue(u.size() > 0);
- assertEquals(ImmutableSet.copyOf(last), ImmutableSet.copyOf(expectedAddresses), "actual="+last+" expected="+expectedAddresses);
- assertEquals(last.size(), expectedAddresses.size(), "actual="+last+" expected="+expectedAddresses);
- }
-
- private Collection<String> locationsToAddresses(int port, Collection<Entity> entities) {
- Set<String> result = MutableSet.of();
- for (Entity e: entities) {
- result.add( ((SshMachineLocation) e.getLocations().iterator().next()) .getAddress().getHostName()+":"+port);
- }
- return result;
- }
-
- public static class ClusteredEntity extends TestEntityImpl {
- public static class Factory implements EntityFactory<ClusteredEntity> {
- @Override
- public ClusteredEntity newEntity(Map flags, Entity parent) {
- return new ClusteredEntity(flags, parent);
- }
- }
- public ClusteredEntity(Map flags, Entity parent) { super(flags,parent); }
- public ClusteredEntity(Entity parent) { super(MutableMap.of(),parent); }
- public ClusteredEntity(Map flags) { super(flags,null); }
- public ClusteredEntity() { super(MutableMap.of(),null); }
-
- @SetFromFlag("hostname")
- public static final AttributeSensor<String> HOSTNAME = Attributes.HOSTNAME;
-
- @SetFromFlag("port")
- public static final AttributeSensor<Integer> HTTP_PORT = Attributes.HTTP_PORT;
-
- @SetFromFlag("hostAndPort")
- public static final AttributeSensor<String> HOST_AND_PORT = Attributes.HOST_AND_PORT;
-
- MachineProvisioningLocation provisioner;
-
- public void start(Collection<? extends Location> locs) {
- provisioner = (MachineProvisioningLocation) locs.iterator().next();
- MachineLocation machine;
- try {
- machine = provisioner.obtain(MutableMap.of());
- } catch (NoMachinesAvailableException e) {
- throw Exceptions.propagate(e);
- }
- addLocations(Arrays.asList(machine));
- setAttribute(HOSTNAME, machine.getAddress().getHostName());
- setAttribute(Attributes.SUBNET_HOSTNAME, machine.getAddress().getHostName());
- }
- public void stop() {
- if (provisioner!=null) provisioner.release((MachineLocation) firstLocation());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
deleted file mode 100644
index c4721ce..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/ProxySslConfigTest.java
+++ /dev/null
@@ -1,60 +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 brooklyn.entity.proxy;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.flags.TypeCoercions;
-
-@Test
-public class ProxySslConfigTest {
-
- @Test
- public void testFromMap() {
- ProxySslConfig config = TypeCoercions.coerce(MutableMap.of(
- "certificateSourceUrl", "file://tmp/cert.txt",
- "keySourceUrl", "file://tmp/key.txt",
- "keyDestination", "dest.txt",
- "targetIsSsl", true,
- "reuseSessions", true),
- ProxySslConfig.class);
- Assert.assertEquals(config.getCertificateSourceUrl(), "file://tmp/cert.txt");
- Assert.assertEquals(config.getKeySourceUrl(), "file://tmp/key.txt");
- Assert.assertEquals(config.getKeyDestination(), "dest.txt");
- Assert.assertEquals(config.getTargetIsSsl(), true);
- Assert.assertEquals(config.getReuseSessions(), true);
- }
-
- @Test
- public void testFromMapWithNullsAndDefaults() {
- ProxySslConfig config = TypeCoercions.coerce(MutableMap.of(
- "certificateSourceUrl", "file://tmp/cert.txt",
- "keySourceUrl", null,
- "targetIsSsl", "false"),
- ProxySslConfig.class);
- Assert.assertEquals(config.getCertificateSourceUrl(), "file://tmp/cert.txt");
- Assert.assertEquals(config.getKeySourceUrl(), null);
- Assert.assertEquals(config.getKeyDestination(), null);
- Assert.assertEquals(config.getTargetIsSsl(), false);
- Assert.assertEquals(config.getReuseSessions(), false);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/StubAppServer.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/StubAppServer.java b/software/webapp/src/test/java/brooklyn/entity/proxy/StubAppServer.java
deleted file mode 100644
index e27ed07..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/StubAppServer.java
+++ /dev/null
@@ -1,86 +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 brooklyn.entity.proxy;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.AbstractEntity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.trait.Startable;
-import brooklyn.event.AttributeSensor;
-import brooklyn.event.basic.PortAttributeSensorAndConfigKey;
-import brooklyn.location.Location;
-import brooklyn.location.MachineLocation;
-import brooklyn.location.MachineProvisioningLocation;
-import brooklyn.location.NoMachinesAvailableException;
-import brooklyn.util.collections.MutableMap;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-public class StubAppServer extends AbstractEntity implements Startable {
- public static final AttributeSensor<String> HOSTNAME = Attributes.HOSTNAME;
- public static final PortAttributeSensorAndConfigKey HTTP_PORT = Attributes.HTTP_PORT;
- public static AtomicInteger nextPort = new AtomicInteger(1234);
-
- public StubAppServer(Map flags) {
- super(flags);
- }
-
- public StubAppServer(Map flags, Entity parent) {
- super(flags, parent);
- }
-
- @Override
- public void start(Collection<? extends Location> locations) {
- Location location = Iterables.getOnlyElement(locations);
- if (location instanceof MachineProvisioningLocation) {
- startInLocation((MachineProvisioningLocation)location);
- } else {
- startInLocation((MachineLocation)location);
- }
- }
-
- private void startInLocation(MachineProvisioningLocation loc) {
- try {
- startInLocation(loc.obtain(MutableMap.of()));
- } catch (NoMachinesAvailableException e) {
- throw Throwables.propagate(e);
- }
- }
-
- private void startInLocation(MachineLocation loc) {
- addLocations(ImmutableList.of((Location)loc));
- setAttribute(HOSTNAME, loc.getAddress().getHostName());
- setAttribute(HTTP_PORT, nextPort.getAndIncrement());
- setAttribute(SERVICE_UP, true);
- }
-
- public void stop() {
- setAttribute(SERVICE_UP, false);
- }
-
- @Override
- public void restart() {
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractController.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractController.java b/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractController.java
deleted file mode 100644
index 5621910..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractController.java
+++ /dev/null
@@ -1,29 +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 brooklyn.entity.proxy;
-
-import java.util.Collection;
-import java.util.List;
-
-import brooklyn.entity.proxying.ImplementedBy;
-
-@ImplementedBy(TrackingAbstractControllerImpl.class)
-public interface TrackingAbstractController extends AbstractController {
- List<Collection<String>> getUpdates();
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractControllerImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractControllerImpl.java b/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractControllerImpl.java
deleted file mode 100644
index de64855..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/TrackingAbstractControllerImpl.java
+++ /dev/null
@@ -1,67 +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 brooklyn.entity.proxy;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.driver.MockSshDriver;
-
-import com.google.common.collect.Lists;
-
-public class TrackingAbstractControllerImpl extends AbstractControllerImpl implements TrackingAbstractController {
-
- private static final Logger log = LoggerFactory.getLogger(TrackingAbstractControllerImpl.class);
-
- private final List<Collection<String>> updates = Lists.newCopyOnWriteArrayList();
-
- @Override
- public List<Collection<String>> getUpdates() {
- return updates;
- }
-
- @Override
- public void connectSensors() {
- super.connectSensors();
- setAttribute(SERVICE_UP, true);
- }
-
- @Override
- protected void reconfigureService() {
- Set<String> addresses = getServerPoolAddresses();
- log.info("test controller reconfigure, targets "+addresses);
- if ((!addresses.isEmpty() && updates.isEmpty()) || (!updates.isEmpty() && addresses != updates.get(updates.size()-1))) {
- updates.add(addresses);
- }
- }
-
- @Override
- public Class getDriverInterface() {
- return MockSshDriver.class;
- }
-
- @Override
- public void reload() {
- // no-op
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/UrlMappingTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/UrlMappingTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/UrlMappingTest.java
deleted file mode 100644
index 25a86fd..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/UrlMappingTest.java
+++ /dev/null
@@ -1,216 +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 brooklyn.entity.proxy;
-
-import static org.testng.Assert.assertEquals;
-
-import java.io.File;
-import java.util.HashSet;
-
-import javax.annotation.Nullable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ApplicationBuilder;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.BasicConfigurableEntityFactory;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxy.nginx.UrlMapping;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.rebind.RebindTestUtils;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestApplication;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.time.Duration;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import com.google.common.io.Files;
-
-public class UrlMappingTest {
-
- private static final Logger log = LoggerFactory.getLogger(UrlMappingTest.class);
-
- private final int initialClusterSize = 2;
-
- private ClassLoader classLoader = getClass().getClassLoader();
- private LocalManagementContext managementContext;
- private File mementoDir;
-
- private TestApplication app;
- private DynamicCluster cluster;
- private UrlMapping urlMapping;
-
- @BeforeMethod(alwaysRun=true)
- public void setup() {
- mementoDir = Files.createTempDir();
- managementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader);
-
- app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
-
- EntityFactory<StubAppServer> serverFactory = new BasicConfigurableEntityFactory<StubAppServer>(StubAppServer.class);
- cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure("initialSize", initialClusterSize)
- .configure("factory", serverFactory));
-
- urlMapping = app.createAndManageChild(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost")
- .configure("target", cluster));
-
- app.start( ImmutableList.of(
- managementContext.getLocationManager().createLocation(
- LocationSpec.create(LocalhostMachineProvisioningLocation.class))
- ));
- log.info("app's location managed: "+managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(app.getLocations())));
- log.info("clusters's location managed: "+managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
- }
-
- @AfterMethod(alwaysRun=true)
- public void shutdown() {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
- }
-
- @Test(groups = "Integration")
- public void testTargetMappingsMatchesClusterMembers() {
- // Check updates its TARGET_ADDRESSES (through async subscription)
- assertExpectedTargetsEventually(cluster.getMembers());
- }
-
- @Test(groups = "Integration")
- public void testTargetMappingsRemovesUnmanagedMember() {
- Iterable<StubAppServer> members = Iterables.filter(cluster.getChildren(), StubAppServer.class);
- assertEquals(Iterables.size(members), 2);
- StubAppServer target1 = Iterables.get(members, 0);
- StubAppServer target2 = Iterables.get(members, 1);
-
- // First wait for targets to be listed
- assertExpectedTargetsEventually(members);
-
- // Unmanage one member, and expect the URL Mapping to be updated accordingly
- Entities.unmanage(target1);
-
- assertExpectedTargetsEventually(ImmutableSet.of(target2));
- }
-
- @Test(groups = "Integration", invocationCount=50)
- public void testTargetMappingsRemovesUnmanagedMemberManyTimes() {
- testTargetMappingsRemovesUnmanagedMember();
- }
-
- @Test(groups = "Integration")
- public void testTargetMappingsRemovesDownMember() {
- Iterable<StubAppServer> members = Iterables.filter(cluster.getChildren(), StubAppServer.class);
- StubAppServer target1 = Iterables.get(members, 0);
- StubAppServer target2 = Iterables.get(members, 1);
-
- // First wait for targets to be listed
- assertExpectedTargetsEventually(members);
-
- // Stop one member, and expect the URL Mapping to be updated accordingly
- target1.setAttribute(StubAppServer.SERVICE_UP, false);
-
- assertExpectedTargetsEventually(ImmutableSet.of(target2));
- }
-
- // i think no real reason for other methods to be Integration apart from the time they take;
- // having one in the unit tests is very handy however, and this is a good choice because it does quite a lot!
- @Test
- public void testTargetMappingUpdatesAfterRebind() throws Exception {
- log.info("starting testTargetMappingUpdatesAfterRebind");
- Iterable<StubAppServer> members = Iterables.filter(cluster.getChildren(), StubAppServer.class);
- assertExpectedTargetsEventually(members);
-
- Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
- rebind();
- Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())),
- "location not managed after rebind");
-
- Iterable<StubAppServer> members2 = Iterables.filter(cluster.getChildren(), StubAppServer.class);
- StubAppServer target1 = Iterables.get(members2, 0);
- StubAppServer target2 = Iterables.get(members2, 1);
-
- // Expect to have existing targets
- assertExpectedTargetsEventually(ImmutableSet.of(target1, target2));
-
- // Add a new member; expect member to be added
- log.info("resizing "+cluster+" - "+cluster.getChildren());
- Integer result = cluster.resize(3);
- Assert.assertTrue(managementContext.getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
- log.info("resized "+cluster+" ("+result+") - "+cluster.getChildren());
- HashSet<StubAppServer> newEntities = Sets.newHashSet(Iterables.filter(cluster.getChildren(), StubAppServer.class));
- newEntities.remove(target1);
- newEntities.remove(target2);
- StubAppServer target3 = Iterables.getOnlyElement(newEntities);
- log.info("expecting "+ImmutableSet.of(target1, target2, target3));
- assertExpectedTargetsEventually(ImmutableSet.of(target1, target2, target3));
-
- // Stop one member, and expect the URL Mapping to be updated accordingly
- log.info("pretending one node down");
- target1.setAttribute(StubAppServer.SERVICE_UP, false);
- assertExpectedTargetsEventually(ImmutableSet.of(target2, target3));
-
- // Unmanage a member, and expect the URL Mapping to be updated accordingly
- log.info("unmanaging another node");
- Entities.unmanage(target2);
- assertExpectedTargetsEventually(ImmutableSet.of(target3));
- log.info("success - testTargetMappingUpdatesAfterRebind");
- }
-
- private void assertExpectedTargetsEventually(final Iterable<? extends Entity> members) {
- Asserts.succeedsEventually(MutableMap.of("timeout", Duration.ONE_MINUTE), new Runnable() {
- public void run() {
- Iterable<String> expectedTargets = Iterables.transform(members, new Function<Entity,String>() {
- @Override public String apply(@Nullable Entity input) {
- return input.getAttribute(Attributes.HOSTNAME)+":"+input.getAttribute(Attributes.HTTP_PORT);
- }});
-
- assertEquals(ImmutableSet.copyOf(urlMapping.getAttribute(UrlMapping.TARGET_ADDRESSES)), ImmutableSet.copyOf(expectedTargets));
- assertEquals(urlMapping.getAttribute(UrlMapping.TARGET_ADDRESSES).size(), Iterables.size(members));
- }});
- }
-
- private void rebind() throws Exception {
- RebindTestUtils.waitForPersisted(app);
-
- // Stop the old management context, so original nginx won't interfere
- managementContext.terminate();
-
- app = (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
- managementContext = (LocalManagementContext) ((EntityInternal)app).getManagementContext();
- cluster = (DynamicCluster) Iterables.find(app.getChildren(), Predicates.instanceOf(DynamicCluster.class));
- urlMapping = (UrlMapping) Iterables.find(app.getChildren(), Predicates.instanceOf(UrlMapping.class));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxClusterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxClusterIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxClusterIntegrationTest.java
deleted file mode 100644
index c75f096..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxClusterIntegrationTest.java
+++ /dev/null
@@ -1,241 +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 brooklyn.entity.proxy.nginx;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.brooklyn.management.EntityManager;
-import org.apache.brooklyn.test.EntityTestUtils;
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.BrooklynAppLiveTestSupport;
-import brooklyn.entity.Group;
-import brooklyn.entity.basic.BasicGroup;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.group.DynamicCluster;
-import brooklyn.entity.proxy.LoadBalancerCluster;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.trait.Startable;
-import brooklyn.entity.webapp.JavaWebAppService;
-import brooklyn.entity.webapp.jboss.JBoss7Server;
-import brooklyn.location.Location;
-import brooklyn.location.basic.PortRanges;
-import brooklyn.test.Asserts;
-import brooklyn.util.collections.MutableMap;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * Test the operation of the {@link NginxController} class.
- */
-public class NginxClusterIntegrationTest extends BrooklynAppLiveTestSupport {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(NginxClusterIntegrationTest.class);
-
- private static final long TIMEOUT_MS = 60*1000;
-
- private Location localhostProvisioningLoc;
- private EntityManager entityManager;
- private LoadBalancerCluster loadBalancerCluster;
- private EntitySpec<NginxController> nginxSpec;
- private Group urlMappings;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
- localhostProvisioningLoc = app.newLocalhostProvisioningLocation();
-
- urlMappings = app.createAndManageChild(EntitySpec.create(BasicGroup.class)
- .configure("childrenAsMembers", true));
- entityManager = app.getManagementContext().getEntityManager();
-
- nginxSpec = EntitySpec.create(NginxController.class);
- }
-
- public String getTestWar() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
- return "classpath://hello-world.war";
- }
-
- @Test(groups = "Integration")
- public void testCreatesNginxInstancesAndResizes() {
- loadBalancerCluster = app.createAndManageChild(EntitySpec.create(LoadBalancerCluster.class)
- .configure(LoadBalancerCluster.MEMBER_SPEC, nginxSpec)
- .configure("initialSize", 1)
- .configure(NginxController.DOMAIN_NAME, "localhost"));
-
- app.start(ImmutableList.of(localhostProvisioningLoc));
-
- assertEquals(findNginxs().size(), 1);
- assertNginxsResponsiveEvenutally(findNginxs());
-
- // Resize load-balancer cluster
- loadBalancerCluster.resize(2);
- assertEquals(findNginxs().size(), 2);
- assertNoDuplicates(findNginxRootUrls());
- assertNginxsResponsiveEvenutally(findNginxs());
- }
-
- @Test(groups = "Integration")
- public void testNginxInstancesConfiguredWithServerPool() {
- DynamicCluster serverPool = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.ROOT_WAR, getTestWar()));
-
- loadBalancerCluster = app.createAndManageChild(EntitySpec.create(LoadBalancerCluster.class)
- .configure("serverPool", serverPool)
- .configure(LoadBalancerCluster.MEMBER_SPEC, nginxSpec)
- .configure("initialSize", 1)
- .configure(NginxController.DOMAIN_NAME, "localhost"));
-
- app.start(ImmutableList.of(localhostProvisioningLoc));
-
- assertEquals(findNginxs().size(), 1);
-
- String hostname = "localhost";
- List<String> pathsFor200 = ImmutableList.of(""); // i.e. app deployed at root
- assertNginxsResponsiveEvenutally(findNginxs(), hostname, pathsFor200);
- }
-
- @Test(groups = "Integration")
- public void testNginxInstancesConfiguredWithUrlMappings() {
- DynamicCluster c1 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
- .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(JBoss7Server.class))
- .configure("initialSize", 1)
- .configure(JavaWebAppService.NAMED_WARS, ImmutableList.of(getTestWar())));
-
- UrlMapping urlMapping = entityManager.createEntity(EntitySpec.create(UrlMapping.class)
- .configure("domain", "localhost")
- .configure("path", "/hello-world($|/.*)")
- .configure("target", c1)
- .parent(urlMappings));
- Entities.manage(urlMapping);
-
- loadBalancerCluster = app.createAndManageChild(EntitySpec.create(LoadBalancerCluster.class)
- .configure("urlMappings", urlMappings)
- .configure(LoadBalancerCluster.MEMBER_SPEC, nginxSpec)
- .configure("initialSize", 1));
-
- app.start(ImmutableList.of(localhostProvisioningLoc));
-
- assertEquals(findNginxs().size(), 1);
-
- String hostname = "localhost";
- List<String> pathsFor200 = ImmutableList.of("hello-world", "hello-world/");
- assertNginxsResponsiveEvenutally(findNginxs(), hostname, pathsFor200);
- }
-
- @Test(groups = "Integration")
- public void testClusterIsUpIffHasChildLoadBalancer() {
- // Note the up-quorum-check behaves different for initialSize==0 (if explicit value not given):
- // it would accept a size==0 as being serviceUp=true. Therefore don't do that!
- loadBalancerCluster = app.createAndManageChild(EntitySpec.create(LoadBalancerCluster.class)
- .configure(LoadBalancerCluster.MEMBER_SPEC, nginxSpec)
- .configure("initialSize", 1)
- .configure(NginxController.DOMAIN_NAME, "localhost"));
-
- app.start(ImmutableList.of(localhostProvisioningLoc));
- EntityTestUtils.assertAttributeEqualsContinually(loadBalancerCluster, Startable.SERVICE_UP, true);
-
- loadBalancerCluster.resize(0);
- EntityTestUtils.assertAttributeEqualsEventually(loadBalancerCluster, Startable.SERVICE_UP, false);
-
- loadBalancerCluster.resize(1);
- EntityTestUtils.assertAttributeEqualsEventually(loadBalancerCluster, Startable.SERVICE_UP, true);
- }
-
- // Warning: test is a little brittle for if a previous run leaves something on these required ports
- @Test(groups = "Integration")
- public void testConfiguresNginxInstancesWithInheritedPortConfig() {
- loadBalancerCluster = app.createAndManageChild(EntitySpec.create(LoadBalancerCluster.class)
- .configure(LoadBalancerCluster.MEMBER_SPEC, nginxSpec)
- .configure("initialSize", 1)
- .configure(NginxController.DOMAIN_NAME, "localhost")
- .configure(NginxController.PROXY_HTTP_PORT, PortRanges.fromString("8765+")));
-
- app.start(ImmutableList.of(localhostProvisioningLoc));
-
- NginxController nginx1 = Iterables.getOnlyElement(findNginxs());
-
- loadBalancerCluster.resize(2);
- NginxController nginx2 = Iterables.getOnlyElement(Iterables.filter(findNginxs(),
- Predicates.not(Predicates.in(ImmutableList.of(nginx1)))));
-
- assertEquals((int) nginx1.getAttribute(NginxController.PROXY_HTTP_PORT), 8765);
- assertEquals((int) nginx2.getAttribute(NginxController.PROXY_HTTP_PORT), 8766);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private List<NginxController> findNginxs() {
- ImmutableList result = ImmutableList.copyOf(Iterables.filter(app.getManagementContext().getEntityManager().getEntities(), Predicates.instanceOf(NginxController.class)));
- return (List<NginxController>) result;
- }
-
- private List<String> findNginxRootUrls() {
- List<String> result = Lists.newArrayList();
- for (NginxController nginx : findNginxs()) {
- result.add(nginx.getAttribute(NginxController.ROOT_URL));
- }
- return result;
- }
-
- private void assertNginxsResponsiveEvenutally(final Iterable<NginxController> nginxs) {
- assertNginxsResponsiveEvenutally(nginxs, null, Collections.<String>emptyList());
- }
-
- private void assertNginxsResponsiveEvenutally(final Iterable<NginxController> nginxs, final String hostname, final List<String> pathsFor200) {
- Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
- public void run() {
- for (NginxController nginx : nginxs) {
- assertTrue(nginx.getAttribute(NginxController.SERVICE_UP));
-
- String normalRootUrl = nginx.getAttribute(NginxController.ROOT_URL);
- int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT);
- String rootUrl = (hostname != null) ? ("http://"+hostname+":"+port+"/") : normalRootUrl;
-
- String wrongUrl = rootUrl+"doesnotexist";
- HttpTestUtils.assertHttpStatusCodeEquals(wrongUrl, 404);
-
- for (String pathFor200 : pathsFor200) {
- String url = rootUrl+pathFor200;
- HttpTestUtils.assertHttpStatusCodeEquals(url, 200);
- }
- }
- }});
- }
-
- private void assertNoDuplicates(Iterable<String> c) {
- assertEquals(Iterables.size(c), ImmutableSet.copyOf(c).size(), "c="+c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77dff880/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxEc2LiveTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxEc2LiveTest.java b/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxEc2LiveTest.java
deleted file mode 100644
index 017415b..0000000
--- a/software/webapp/src/test/java/brooklyn/entity/proxy/nginx/NginxEc2LiveTest.java
+++ /dev/null
@@ -1,72 +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 brooklyn.entity.proxy.nginx;
-
-import org.apache.brooklyn.test.EntityTestUtils;
-import org.apache.brooklyn.test.HttpTestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.AbstractEc2LiveTest;
-import brooklyn.entity.basic.SoftwareProcess;
-import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.entity.webapp.WebAppService;
-import brooklyn.location.Location;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * A simple test of installing+running on AWS-EC2, using various OS distros and versions.
- */
-public class NginxEc2LiveTest extends AbstractEc2LiveTest {
-
- /* FIXME Currently fails on:
- * test_Debian_5: installation of nginx failed
- * test_Ubuntu_12_0: invocation error for disable requiretty
- */
-
- /* PASSED: test_CentOS_5
- * PASSED: test_CentOS_6_3
- * PASSED: test_Debian_6
- * PASSED: test_Ubuntu_10_0
- *
- * test_Red_Hat_Enterprise_Linux_6 passes, if get it to wait for ssh-login rather than "failed to SSH in as root"
- */
-
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(NginxEc2LiveTest.class);
-
- private NginxController nginx;
-
- @Override
- protected void doTest(Location loc) throws Exception {
- nginx = app.createAndManageChild(EntitySpec.create(NginxController.class)
- .configure("portNumberSensor", WebAppService.HTTP_PORT));
-
- app.start(ImmutableList.of(loc));
-
- // nginx should be up, and URL reachable
- EntityTestUtils.assertAttributeEqualsEventually(nginx, SoftwareProcess.SERVICE_UP, true);
- HttpTestUtils.assertHttpStatusCodeEventuallyEquals(nginx.getAttribute(NginxController.ROOT_URL), 404);
- }
-
- @Test(enabled=false)
- public void testDummy() {} // Convince testng IDE integration that this really does have test methods
-}