Skip to content

Commit 3200ee8

Browse files
committed
DslYamlTest.getConfigEventually: don’t use entity’s task
As per previous TODO about PR apache#480, we don’t need to retrieve the config in the context of the given entity.
1 parent a4b1377 commit 3200ee8

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

  • camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl

camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslYamlTest.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
import java.util.concurrent.Callable;
2121
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;
2226

2327
import org.apache.brooklyn.api.entity.Entity;
2428
import org.apache.brooklyn.api.location.Location;
25-
import org.apache.brooklyn.api.mgmt.Task;
2629
import org.apache.brooklyn.api.sensor.AttributeSensor;
2730
import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
2831
import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslTestObjects.DslTestCallable;
@@ -758,17 +761,19 @@ public void testDeferredDslChainingWithNestedEvaluation() throws Exception {
758761
}
759762

760763
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+
}
773778
}
774779
}

0 commit comments

Comments
 (0)