Repository: incubator-brooklyn Updated Branches: refs/heads/master 26f667707 -> f7f6b09c6
ServerPoolTest: fix non-determinism in test Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e0ea816b Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e0ea816b Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e0ea816b Branch: refs/heads/master Commit: e0ea816bebdd2d51c28ac5fc8f3d874ba004fd43 Parents: dc53885 Author: Aled Sage <[email protected]> Authored: Wed Jan 21 15:01:04 2015 +0000 Committer: Aled Sage <[email protected]> Committed: Wed Jan 21 15:01:04 2015 +0000 ---------------------------------------------------------------------- .../entity/pool/AbstractServerPoolTest.java | 29 ++++++++------------ .../entity/pool/ServerPoolRebindTest.java | 12 ++++---- .../brooklyn/entity/pool/ServerPoolTest.java | 28 +++++++++---------- 3 files changed, 32 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e0ea816b/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 b1d3bba..5575e87 100644 --- a/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java +++ b/software/base/src/test/java/brooklyn/entity/pool/AbstractServerPoolTest.java @@ -18,8 +18,6 @@ */ package brooklyn.entity.pool; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.util.List; @@ -27,9 +25,6 @@ import java.util.List; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - import brooklyn.entity.basic.ApplicationBuilder; import brooklyn.entity.basic.Attributes; import brooklyn.entity.basic.BrooklynConfigKeys; @@ -46,6 +41,9 @@ import brooklyn.test.entity.LocalManagementContextForTests; import brooklyn.test.entity.TestApplication; import brooklyn.util.exceptions.Exceptions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + public abstract class AbstractServerPoolTest { // Note not extending BrooklynAppUnitTestSupport because sub-classes of this are for live and for unit tests. @@ -72,7 +70,8 @@ public abstract class AbstractServerPoolTest { .configure(ServerPool.INITIAL_SIZE, getInitialPoolSize()) .configure(ServerPool.MEMBER_SPEC, EntitySpec.create(EmptySoftwareProcess.class))); poolApp.start(ImmutableList.of(location)); - assertTrue(pool.getAttribute(Attributes.SERVICE_UP)); + EntityTestUtils.assertAttributeEqualsEventually(pool, Attributes.SERVICE_UP, true); + assertAvailableCountEventuallyEquals(getInitialPoolSize()); } @AfterMethod(alwaysRun=true) @@ -116,24 +115,20 @@ public abstract class AbstractServerPoolTest { } } - protected void assertAvailableCountEquals(int count) { - assertAvailableCountEquals(pool, count); - } - - protected void assertAvailableCountEquals(ServerPool pool, Integer count) { - assertEquals(pool.getAttribute(ServerPool.AVAILABLE_COUNT), count); + protected void assertAvailableCountEventuallyEquals(int count) { + assertAvailableCountEventuallyEquals(pool, count); } - protected void assertAvailableCountEventuallyEquals(int count) { + protected void assertAvailableCountEventuallyEquals(ServerPool pool, int count) { EntityTestUtils.assertAttributeEqualsEventually(pool, ServerPool.AVAILABLE_COUNT, count); } - protected void assertClaimedCountEquals(int count) { - assertClaimedCountEquals(pool, count); + protected void assertClaimedCountEventuallyEquals(int count) { + assertClaimedCountEventuallyEquals(pool, count); } - protected void assertClaimedCountEquals(ServerPool pool, Integer count) { - assertEquals(pool.getAttribute(ServerPool.CLAIMED_COUNT), count); + protected void assertClaimedCountEventuallyEquals(ServerPool pool, Integer count) { + EntityTestUtils.assertAttributeEqualsEventually(pool, ServerPool.CLAIMED_COUNT, count); } protected TestApplication createAppWithChildren(int numChildren) { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e0ea816b/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 87feeff..ca4e5ca 100644 --- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java +++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolRebindTest.java @@ -77,8 +77,8 @@ public class ServerPoolRebindTest extends AbstractServerPoolTest { TestApplication app = createAppWithChildren(1); app.start(ImmutableList.of(pool.getDynamicLocation())); assertTrue(app.getAttribute(Attributes.SERVICE_UP)); - assertAvailableCountEquals(pool, getInitialPoolSize() - 1); - assertClaimedCountEquals(pool, 1); + assertAvailableCountEventuallyEquals(pool, getInitialPoolSize() - 1); + assertClaimedCountEventuallyEquals(pool, 1); Collection<Application> reboundApps = rebind(poolApp); ServerPool reboundPool = null; @@ -95,14 +95,14 @@ public class ServerPoolRebindTest extends AbstractServerPoolTest { " child. Apps: " + reboundApps); assertNotNull(reboundPool.getDynamicLocation()); assertTrue(reboundPool.getAttribute(Attributes.SERVICE_UP)); - assertAvailableCountEquals(reboundPool, getInitialPoolSize() - 1); - assertClaimedCountEquals(reboundPool, 1); + assertAvailableCountEventuallyEquals(reboundPool, getInitialPoolSize() - 1); + assertClaimedCountEventuallyEquals(reboundPool, 1); TestApplication app2 = createAppWithChildren(1); app2.start(ImmutableList.of(reboundPool.getDynamicLocation())); assertTrue(app2.getAttribute(Attributes.SERVICE_UP)); - assertAvailableCountEquals(reboundPool, getInitialPoolSize() - 2); - assertClaimedCountEquals(reboundPool, 2); + assertAvailableCountEventuallyEquals(reboundPool, getInitialPoolSize() - 2); + assertClaimedCountEventuallyEquals(reboundPool, 2); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e0ea816b/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 1eb222b..962400f 100644 --- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java +++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java @@ -68,19 +68,19 @@ public class ServerPoolTest extends AbstractServerPoolTest { TestApplication app2 = createAppWithChildren(1); app.start(ImmutableList.of(pool.getDynamicLocation())); - assertTrue(app.getAttribute(Attributes.SERVICE_UP)); - assertAvailableCountEquals(0); + EntityTestUtils.assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); + assertAvailableCountEventuallyEquals(0); assertNoMachinesAvailableForApp(app2); app.stop(); assertFalse(app.getAttribute(Attributes.SERVICE_UP)); - assertAvailableCountEquals(getInitialPoolSize()); + assertAvailableCountEventuallyEquals(getInitialPoolSize()); app2.start(ImmutableList.of(pool.getDynamicLocation())); - assertTrue(app2.getAttribute(Attributes.SERVICE_UP)); + EntityTestUtils.assertAttributeEqualsEventually(app2, Attributes.SERVICE_UP, true); assertAvailableCountEventuallyEquals(getInitialPoolSize() - 1); - assertClaimedCountEquals(1); + assertClaimedCountEventuallyEquals(1); } @Test @@ -105,7 +105,7 @@ public class ServerPoolTest extends AbstractServerPoolTest { public void testResizePoolDownSucceedsWhenEnoughMachinesAreFree() { TestApplication app = createAppWithChildren(1); app.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(getInitialPoolSize() - 1); + assertAvailableCountEventuallyEquals(getInitialPoolSize() - 1); pool.resize(1); @@ -116,23 +116,23 @@ public class ServerPoolTest extends AbstractServerPoolTest { public void testResizeDownDoesNotReleaseClaimedMachines() { TestApplication app = createAppWithChildren(getInitialPoolSize() - 1); app.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(1); - assertClaimedCountEquals(getInitialPoolSize() - 1); + assertAvailableCountEventuallyEquals(1); + assertClaimedCountEventuallyEquals(getInitialPoolSize() - 1); LOG.info("Test attempting to resize to 0 members. Should only drop the one available machine."); pool.resize(0); assertAvailableCountEventuallyEquals(0); assertEquals(Iterables.size(pool.getMembers()), getInitialPoolSize() - 1); - assertAvailableCountEquals(0); - assertClaimedCountEquals(getInitialPoolSize() - 1); + assertAvailableCountEventuallyEquals(0); + assertClaimedCountEventuallyEquals(getInitialPoolSize() - 1); } @Test public void testCanAddExistingMachinesToPool() { TestApplication app = createAppWithChildren(getInitialPoolSize()); app.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(0); + assertAvailableCountEventuallyEquals(0); LocalhostMachine loc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachine.class)); Entity added = pool.addExistingMachine(loc); @@ -141,7 +141,7 @@ public class ServerPoolTest extends AbstractServerPoolTest { TestApplication app2 = createAppWithChildren(1); app2.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(0); + assertAvailableCountEventuallyEquals(0); } @Test @@ -159,7 +159,7 @@ public class ServerPoolTest extends AbstractServerPoolTest { public void testAddExistingMachineFromSpec() { TestApplication app = createAppWithChildren(getInitialPoolSize()); app.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(0); + assertAvailableCountEventuallyEquals(0); Collection<Entity> added = pool.addExistingMachinesFromSpec("byon:(hosts=\"localhost,localhost\")"); assertEquals(added.size(), 2, "Added: " + Joiner.on(", ").join(added)); @@ -170,6 +170,6 @@ public class ServerPoolTest extends AbstractServerPoolTest { TestApplication app2 = createAppWithChildren(2); app2.start(ImmutableList.of(pool.getDynamicLocation())); - assertAvailableCountEquals(0); + assertAvailableCountEventuallyEquals(0); } }
