|
19 | 19 |
|
20 | 20 | import java.util.concurrent.Callable; |
21 | 21 | import java.util.concurrent.ExecutionException; |
| 22 | +import java.util.concurrent.ExecutorService; |
| 23 | +import java.util.concurrent.Executors; |
| 24 | +import java.util.concurrent.Future; |
| 25 | +import java.util.concurrent.TimeUnit; |
22 | 26 |
|
23 | 27 | import org.apache.brooklyn.api.entity.Entity; |
24 | 28 | import org.apache.brooklyn.api.location.Location; |
25 | | -import org.apache.brooklyn.api.mgmt.Task; |
26 | 29 | import org.apache.brooklyn.api.sensor.AttributeSensor; |
27 | 30 | import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; |
28 | 31 | import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslTestObjects.DslTestCallable; |
@@ -758,17 +761,19 @@ public void testDeferredDslChainingWithNestedEvaluation() throws Exception { |
758 | 761 | } |
759 | 762 |
|
760 | 763 | private static <T> T getConfigEventually(final Entity entity, final ConfigKey<T> configKey) throws Exception { |
761 | | - Task<T> result = ((EntityInternal)entity).getExecutionContext().submit(new Callable<T>() { |
762 | | - @Override |
763 | | - public T call() throws Exception { |
764 | | - // TODO Move the getNonBlocking call out of the task after #480 is merged. |
765 | | - // Currently doesn't work because no execution context available. |
766 | | - T blockingValue = entity.config().get(configKey); |
767 | | - Maybe<T> immediateValue = ((EntityInternal)entity).config().getNonBlocking(configKey); |
768 | | - assertEquals(immediateValue.get(), blockingValue); |
769 | | - return blockingValue; |
770 | | - } |
771 | | - }); |
772 | | - return result.get(Asserts.DEFAULT_LONG_TIMEOUT); |
| 764 | + // Use an executor, in case config().get() blocks forever, waiting for the config value. |
| 765 | + ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 766 | + try { |
| 767 | + Future<T> future = executor.submit(new Callable<T>() { |
| 768 | + public T call() { |
| 769 | + T blockingValue = entity.config().get(configKey); |
| 770 | + Maybe<T> immediateValue = ((EntityInternal)entity).config().getNonBlocking(configKey); |
| 771 | + assertEquals(immediateValue.get(), blockingValue); |
| 772 | + return blockingValue; |
| 773 | + }}); |
| 774 | + return future.get(Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS); |
| 775 | + } finally { |
| 776 | + executor.shutdownNow(); |
| 777 | + } |
773 | 778 | } |
774 | 779 | } |
0 commit comments