public void testGetImmediatelyFallsBackToDeferredCallInTaskOnUnsupported() throws Exception { final MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(new ImmediateSupplier.ImmediateUnsupportedException("Simulate immediate unsupported")); CallInfo callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).immediately(true).get(); assertNotNull(callInfo.task); assertEquals(BrooklynTaskTags.getContextEntity(callInfo.task), app); assertNotContainsCallingMethod(callInfo.stackTrace, "testGetImmediatelyFallsBackToDeferredCallInTask"); }
public void testGetImmediatelyInTask() throws Exception { final MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(); Task<CallInfo> task = app.getExecutionContext().submit(new Callable<CallInfo>() { @Override public CallInfo call() { return myUniquelyNamedMethod(); } private CallInfo myUniquelyNamedMethod() { return Tasks.resolving(supplier).as(CallInfo.class).immediately(true).get(); } }); CallInfo callInfo = task.get(); assertImmediateFakeTaskFromMethod(callInfo, "myUniquelyNamedMethod"); }
public void testImmediateSupplierWithTimeoutUsesBlocking() { MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(); CallInfo callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).timeout(Asserts.DEFAULT_LONG_TIMEOUT).get(); assertRealTaskNotFromMethod(callInfo, "testImmediateSupplierWithTimeoutUsesBlocking"); }
public void testGetImmediatelyDoesntFallBackToDeferredCallOnNotAvailable() throws Exception { final MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(new ImmediateSupplier.ImmediateValueNotAvailableException()); Maybe<CallInfo> callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).immediately(true).getMaybe(); Asserts.assertNotPresent(callInfo); try { callInfo.get(); Asserts.shouldHaveFailedPreviously("resolution should have failed now the ImmediateSupplier is not expected to fallback to other evaluation forms; instead got "+callInfo); } catch (Exception e) { Asserts.expectedFailureOfType(e, ImmediateValueNotAvailableException.class); } }
public void testGetImmediately() { MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(); CallInfo callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).immediately(true).get(); assertImmediateFakeTaskFromMethod(callInfo, "testGetImmediately"); }