Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AD315200B0F for ; Thu, 2 Jun 2016 10:57:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AC65A160A3F; Thu, 2 Jun 2016 08:57:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CF18D160A3E for ; Thu, 2 Jun 2016 10:57:40 +0200 (CEST) Received: (qmail 12697 invoked by uid 500); 2 Jun 2016 08:57:39 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 12685 invoked by uid 99); 2 Jun 2016 08:57:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2016 08:57:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B26AFE0105; Thu, 2 Jun 2016 08:57:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: svet@apache.org To: commits@brooklyn.apache.org Date: Thu, 02 Jun 2016 08:57:40 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] brooklyn-server git commit: Disable EntityConfigTest.testGetConfigNonBlocking archived-at: Thu, 02 Jun 2016 08:57:41 -0000 Disable EntityConfigTest.testGetConfigNonBlocking Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7e66c209 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7e66c209 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7e66c209 Branch: refs/heads/master Commit: 7e66c2099519d59336ff7ae014a892b37e369cc2 Parents: fcfcacf Author: Aled Sage Authored: Wed Jun 1 17:57:50 2016 +0100 Committer: Aled Sage Committed: Wed Jun 1 20:33:51 2016 +0100 ---------------------------------------------------------------------- .../brooklyn/core/entity/EntityConfigTest.java | 53 ++++++++++++++++---- .../apache/brooklyn/util/time/Durations.java | 6 ++- 2 files changed, 48 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7e66c209/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java index 9c16a93..76d38e4 100644 --- a/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntityConfigTest.java @@ -45,7 +45,9 @@ import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.util.core.flags.SetFromFlag; import org.apache.brooklyn.util.core.task.BasicTask; import org.apache.brooklyn.util.core.task.DeferredSupplier; +import org.apache.brooklyn.util.core.task.DeferredSupplier; import org.apache.brooklyn.util.core.task.Tasks; +import org.apache.brooklyn.util.exceptions.Exceptions; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -208,8 +210,18 @@ public class EntityConfigTest extends BrooklynAppUnitTestSupport { assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING.subKey("mysub")).get(), "myval"); } - @Test - public void testGetConfigNonBlocking() throws Exception { + // TODO This now fails because the task has been cancelled, in entity.config().get(). + // But it used to pass (e.g. with commit 56fcc1632ea4f5ac7f4136a7e04fabf501337540). + // It failed after the rename of CONF_MAP_THING_OBJ to CONF_MAP_OBJ_THING, which + // suggests there was an underlying problem that was masked by the unfortunate naming + // of the previous "test.confMapThing.obj". + // + // Presumably an earlier call to task.get() timed out, causing it to cancel the task? + // I (Aled) question whether we want to support passing a task (rather than a + // DeferredSupplier or TaskFactory, for example). Our EntitySpec.configure is overloaded + // to take a Task, but that feels wrong!? + @Test(groups="Broken") + public void testGetTaskNonBlocking() throws Exception { final CountDownLatch latch = new CountDownLatch(1); Task task = Tasks.builder().body( new Callable() { @@ -219,9 +231,30 @@ public class EntityConfigTest extends BrooklynAppUnitTestSupport { return "myval"; }}) .build(); - TestEntity entity = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) - .configure(TestEntity.CONF_MAP_OBJ_THING, ImmutableMap.of("mysub", task)) - .configure(TestEntity.CONF_NAME, task)); + runGetConfigNonBlocking(latch, task, "myval"); + } + + @Test + public void testGetDeferredSupplierNonBlocking() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + DeferredSupplier task = new DeferredSupplier() { + @Override public String get() { + try { + latch.await(); + } catch (InterruptedException e) { + throw Exceptions.propagate(e); + } + return "myval"; + } + }; + runGetConfigNonBlocking(latch, task, "myval"); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + protected void runGetConfigNonBlocking(CountDownLatch latch, Object blockingVal, String expectedVal) throws Exception { + TestEntity entity = (TestEntity) mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) + .configure(TestEntity.CONF_MAP_OBJ_THING, ImmutableMap.of("mysub", blockingVal)) + .configure((ConfigKey)TestEntity.CONF_NAME, blockingVal)); // Will initially return absent, because task is not done assertTrue(entity.config().getNonBlocking(TestEntity.CONF_MAP_OBJ_THING).isAbsent()); @@ -229,12 +262,12 @@ public class EntityConfigTest extends BrooklynAppUnitTestSupport { latch.countDown(); - // Can now finish task, so will return "myval" - assertEquals(entity.config().get(TestEntity.CONF_MAP_OBJ_THING), ImmutableMap.of("mysub", "myval")); - assertEquals(entity.config().get(TestEntity.CONF_MAP_OBJ_THING.subKey("mysub")), "myval"); + // Can now finish task, so will return expectedVal + assertEquals(entity.config().get(TestEntity.CONF_MAP_OBJ_THING), ImmutableMap.of("mysub", expectedVal)); + assertEquals(entity.config().get(TestEntity.CONF_MAP_OBJ_THING.subKey("mysub")), expectedVal); - assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_OBJ_THING).get(), ImmutableMap.of("mysub", "myval")); - assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_OBJ_THING.subKey("mysub")).get(), "myval"); + assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_OBJ_THING).get(), ImmutableMap.of("mysub", expectedVal)); + assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_OBJ_THING.subKey("mysub")).get(), expectedVal); } @Test http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7e66c209/utils/common/src/main/java/org/apache/brooklyn/util/time/Durations.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Durations.java b/utils/common/src/main/java/org/apache/brooklyn/util/time/Durations.java index 7680184..2028434 100644 --- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Durations.java +++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Durations.java @@ -48,7 +48,11 @@ public class Durations { Thread.yield(); Thread.sleep(0, 1); } - return Maybe.absent("Task "+t+" not completed when immediate completion requested"); + if (t.isDone()) { + return Maybe.of(t.get()); + } else { + return Maybe.absent("Task "+t+" not completed when immediate completion requested"); + } } return Maybe.of(t.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS)); } catch (TimeoutException e) {