You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/07/16 07:19:20 UTC

[1/2] git commit: make server pool test wait for membership to catch up before making assertions, as resize happens in bg (whereas start is immediate)

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master b74e76c35 -> a0a8c9613


make server pool test wait for membership to catch up before making assertions, as resize happens in bg (whereas start is immediate)


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

Branch: refs/heads/master
Commit: ce8d19c9348797724ab9d9915b3a8627379a6bc6
Parents: 342a336
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Jul 11 02:23:06 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Jul 11 02:23:06 2014 -0400

----------------------------------------------------------------------
 .../brooklyn/entity/pool/ServerPoolImpl.java    | 24 +++++++++-----------
 .../entity/pool/ServerPoolLocation.java         |  2 ++
 .../entity/pool/ServerPoolLocationResolver.java |  1 +
 .../entity/pool/AbstractServerPoolTest.java     |  5 ++++
 .../entity/pool/ServerPoolRebindTest.java       | 15 +++++-------
 .../brooklyn/entity/pool/ServerPoolTest.java    | 23 +++++++++++++------
 6 files changed, 41 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
index 980e828..b05a4dc 100644
--- a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
@@ -18,24 +18,12 @@
  */
 package brooklyn.entity.pool;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 import java.util.Collection;
 import java.util.Map;
-import java.util.Set;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.reflect.TypeToken;
-
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.EntityInternal;
@@ -57,6 +45,13 @@ import brooklyn.policy.PolicySpec;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.guava.Maybe;
 
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+import com.google.common.reflect.TypeToken;
+
 public class ServerPoolImpl extends DynamicClusterImpl implements ServerPool {
 
     private static final Logger LOG = LoggerFactory.getLogger(ServerPoolImpl.class);
@@ -75,14 +70,17 @@ public class ServerPoolImpl extends DynamicClusterImpl implements ServerPool {
 
     /** Accesses must be synchronised by mutex */
     // Would use BiMap but persisting them tends to throw ConcurrentModificationExceptions.
+    @SuppressWarnings("serial")
     public static final AttributeSensor<Map<Entity, MachineLocation>> ENTITY_MACHINE = Sensors.newSensor(new TypeToken<Map<Entity, MachineLocation>>() {},
                 "pool.entityMachineMap", "A mapping of entities and their machine locations");
+    @SuppressWarnings("serial")
     public static final AttributeSensor<Map<MachineLocation, Entity>> MACHINE_ENTITY = Sensors.newSensor(new TypeToken<Map<MachineLocation, Entity>>() {},
                 "pool.machineEntityMap", "A mapping of machine locations and their entities");
 
     public static final AttributeSensor<LocationDefinition> DYNAMIC_LOCATION_DEFINITION = Sensors.newSensor(LocationDefinition.class,
             "pool.locationDefinition", "The location definition used to create the pool's dynamic location");
 
+    @SuppressWarnings("unused")
     private MemberTrackingPolicy membershipTracker;
 
     @Override
@@ -233,7 +231,7 @@ public class ServerPoolImpl extends DynamicClusterImpl implements ServerPool {
                         new Object[]{this, delta, -removeable});
                 delta = -removeable;
             }
-            Collection removed = super.shrink(delta);
+            Collection<Entity> removed = super.shrink(delta);
             updateCountSensors();
             return removed;
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocation.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocation.java b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocation.java
index d0e2c00..ed04ea2 100644
--- a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocation.java
+++ b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocation.java
@@ -40,6 +40,8 @@ import brooklyn.util.flags.SetFromFlag;
 public class ServerPoolLocation extends AbstractLocation implements MachineProvisioningLocation<MachineLocation>,
         DynamicLocation<ServerPool, ServerPoolLocation> {
 
+    private static final long serialVersionUID = -6771844611899475409L;
+
     private static final Logger LOG = LoggerFactory.getLogger(ServerPoolLocation.class);
 
     @SetFromFlag("owner")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocationResolver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocationResolver.java b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocationResolver.java
index 357deca..83cb20e 100644
--- a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocationResolver.java
+++ b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolLocationResolver.java
@@ -80,6 +80,7 @@ public class ServerPoolLocationResolver implements EnableableLocationResolver {
         return BasicLocationRegistry.isResolverPrefixForSpec(this, spec, true);
     }
 
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     @Override
     public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry) {
         if (LOG.isDebugEnabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java b/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java
index f58b3a7..babc87c 100644
--- a/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java
+++ b/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java
@@ -40,6 +40,7 @@ import brooklyn.location.LocationSpec;
 import brooklyn.location.NoMachinesAvailableException;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.EntityTestUtils;
 import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.exceptions.Exceptions;
@@ -112,6 +113,10 @@ public abstract class AbstractServerPoolTest {
         assertEquals(pool.getAttribute(ServerPool.AVAILABLE_COUNT), count);
     }
 
+    protected void assertAvailableCountEventuallyEquals(int count) {
+        EntityTestUtils.assertAttributeEqualsEventually(pool, ServerPool.AVAILABLE_COUNT, count);
+    }
+
     protected void assertClaimedCountEquals(int count) {
         assertClaimedCountEquals(pool, count);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java
index f81c345..842b3fa 100644
--- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java
+++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java
@@ -18,7 +18,6 @@
  */
 package brooklyn.entity.pool;
 
-import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
@@ -30,22 +29,20 @@ import org.slf4j.LoggerFactory;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
-
 import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.rebind.RebindTestUtils;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.test.entity.TestApplication;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.io.Files;
+
 public class ServerPoolRebindTest extends AbstractServerPoolTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(ServerPoolRebindTest.class);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ce8d19c9/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
index 6b56010..8fe09b9 100644
--- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
+++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
@@ -26,15 +26,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.Test;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.test.entity.TestApplication;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+
 public class ServerPoolTest extends AbstractServerPoolTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(ServerPoolTest.class);
@@ -73,8 +71,9 @@ public class ServerPoolTest extends AbstractServerPoolTest {
 
         app2.start(ImmutableList.of(pool.getDynamicLocation()));
         assertTrue(app2.getAttribute(Attributes.SERVICE_UP));
+        
+        assertAvailableCountEventuallyEquals(getInitialPoolSize() - 1);
         assertClaimedCountEquals(1);
-        assertAvailableCountEquals(getInitialPoolSize() - 1);
     }
 
     @Test
@@ -87,12 +86,20 @@ public class ServerPoolTest extends AbstractServerPoolTest {
         assertNoMachinesAvailableForApp(app2);
 
         pool.resizeByDelta(1);
+        
+        assertAvailableCountEventuallyEquals(1);
 
         assertEquals((int) pool.getCurrentSize(), getInitialPoolSize() + 1);
         app2.start(ImmutableList.of(pool.getDynamicLocation()));
         assertTrue(app2.getAttribute(Attributes.SERVICE_UP));
     }
 
+//    @Test(invocationCount=100, groups="Integration")
+//    public void testResizingPoolUpManyTimes() {
+//        testResizingPoolUp();
+//    }
+
+
     @Test
     public void testResizePoolDownSucceedsWhenEnoughMachinesAreFree() {
         TestApplication app = createAppWithChildren(1);
@@ -101,7 +108,7 @@ public class ServerPoolTest extends AbstractServerPoolTest {
 
         pool.resize(1);
 
-        assertAvailableCountEquals(0);
+        assertAvailableCountEventuallyEquals(0);
     }
 
     @Test
@@ -114,6 +121,8 @@ public class ServerPoolTest extends AbstractServerPoolTest {
         LOG.info("Test attempting to resize to 0 members. Should only drop one machine.");
         pool.resize(0);
 
+        assertAvailableCountEventuallyEquals(0);
+
         assertEquals(Iterables.size(pool.getMembers()), getInitialPoolSize() - 1);
         assertAvailableCountEquals(0);
         assertClaimedCountEquals(getInitialPoolSize() - 1);


[2/2] git commit: This closes #64

Posted by he...@apache.org.
This closes #64


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

Branch: refs/heads/master
Commit: a0a8c961325610b26c70156b381610640d52f0fc
Parents: b74e76c ce8d19c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Jul 16 01:17:20 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Jul 16 01:17:20 2014 -0400

----------------------------------------------------------------------
 .../brooklyn/entity/pool/ServerPoolImpl.java    | 24 +++++++++-----------
 .../entity/pool/ServerPoolLocation.java         |  2 ++
 .../entity/pool/ServerPoolLocationResolver.java |  1 +
 .../entity/pool/AbstractServerPoolTest.java     |  5 ++++
 .../entity/pool/ServerPoolRebindTest.java       | 15 +++++-------
 .../brooklyn/entity/pool/ServerPoolTest.java    | 23 +++++++++++++------
 6 files changed, 41 insertions(+), 29 deletions(-)
----------------------------------------------------------------------