DslYamlTest.getConfigEventually: donât use entityâs task As per previous TODO about PR #480, we donât need to retrieve the config in the context of the given entity.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/3200ee8c Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/3200ee8c Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/3200ee8c Branch: refs/heads/master Commit: 3200ee8c74b45c30a087ff57b6509798e69a01d3 Parents: a4b1377 Author: Aled Sage <[email protected]> Authored: Wed May 24 12:45:46 2017 +0100 Committer: Aled Sage <[email protected]> Committed: Wed May 24 12:45:46 2017 +0100 ---------------------------------------------------------------------- .../camp/brooklyn/spi/dsl/DslYamlTest.java | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3200ee8c/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java ---------------------------------------------------------------------- diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java index c8463e6..f7ec4c8 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java @@ -19,10 +19,13 @@ import static org.testng.Assert.assertEquals; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslTestObjects.DslTestCallable; @@ -758,17 +761,19 @@ public class DslYamlTest extends AbstractYamlTest { } private static <T> T getConfigEventually(final Entity entity, final ConfigKey<T> configKey) throws Exception { - Task<T> result = ((EntityInternal)entity).getExecutionContext().submit(new Callable<T>() { - @Override - public T call() throws Exception { - // TODO Move the getNonBlocking call out of the task after #480 is merged. - // Currently doesn't work because no execution context available. - T blockingValue = entity.config().get(configKey); - Maybe<T> immediateValue = ((EntityInternal)entity).config().getNonBlocking(configKey); - assertEquals(immediateValue.get(), blockingValue); - return blockingValue; - } - }); - return result.get(Asserts.DEFAULT_LONG_TIMEOUT); + // Use an executor, in case config().get() blocks forever, waiting for the config value. + ExecutorService executor = Executors.newSingleThreadExecutor(); + try { + Future<T> future = executor.submit(new Callable<T>() { + public T call() { + T blockingValue = entity.config().get(configKey); + Maybe<T> immediateValue = ((EntityInternal)entity).config().getNonBlocking(configKey); + assertEquals(immediateValue.get(), blockingValue); + return blockingValue; + }}); + return future.get(Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS); + } finally { + executor.shutdownNow(); + } } }
