Class ThreadContextTest
java.lang.Object
org.jboss.arquillian.testng.Arquillian
org.eclipse.microprofile.context.tck.ThreadContextTest
- All Implemented Interfaces:
org.testng.IHookable,org.testng.ITestNGListener
public class ThreadContextTest
extends org.jboss.arquillian.testng.Arquillian
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jboss.arquillian.testng.Arquillian
org.jboss.arquillian.testng.Arquillian.UpdateResultListener -
Field Summary
Fields inherited from class org.jboss.arquillian.testng.Arquillian
ARQUILLIAN_DATA_PROVIDER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafter()voidafterMethod(Method m, org.testng.ITestResult result) voidbefore()voidvoidvoidVerify that if JTA transactions are supported, then configuring cleared=TRANSACTION results in the active transaction being suspended before running a task and resumed afterward, such that a task can use its own transactions if so desired.voidVerify that the ThreadContext implementation clears context types that are not configured under propagated, unchanged, or cleared.voidVerify the MicroProfile Context Propagation implementation of propagate(), cleared(), and unchanged() for ThreadContext.Builder.voidVerify that the ThreadContext's contextualConsumer method can be used to wrap a BiConsumer instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the BiConsumer accept method runs.voidVerify that the ThreadContext's contextualFunction method can be used to wrap a BiFunction instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the BiFunction apply method runs.voidVerify that the ThreadContext's contextualCallable method can be used to wrap a Callable instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Callable call method runs.voidVerify that the ThreadContext's contextualConsumer method can be used to wrap a Consumer instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Consumer accept method runs.voidVerify that the ThreadContext's contextualFunction method can be used to wrap a Function instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Function apply method runs.voidVerify that the ThreadContext's contextualRunnable method can be used to wrap a Runnable instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Runnable run method runs.voidVerify that the ThreadContext's contextualSupplier method can be used to wrap a Supplier instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Supplier get method runs.static org.jboss.shrinkwrap.api.spec.WebArchivevoidVerify that the ThreadContext's currentContextExecutor method can be used to create an Executor instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied to the thread where the Executor's execute method runs.voidVerify that the ThreadContext.Builder can be used to create multiple ThreadContexts with different configured contexts.voidVerify that the MicroProfile Context Propagation implementation finds third-party thread context providers that are made available to the ServiceLoader, allows their configuration via the ThreadContext builder, and correctly captures and propagates or clears these thread context types per the builder configuration.voidIt is optional to specify the set of unchanged context.voidVerify that the ThreadContext's withContextCapture method can be used to create a dependent CompletableFuture instance that completes when the original stage completes and runs dependent stage actions with context that is captured from the thread that creates the dependent stage.voidVerify that the ThreadContext's withContextCapture method can be used to create a dependent CompletionStage instance that completes when the original stage completes and runs dependent stage actions with context that is captured from the thread that creates the dependent stage.voidVerify that dependent stages created via withContextCapture can be completed independently of the original stage.voidThe withContextCapture method should be able to create multiple dependent stages having a single parent stage, where each of the dependent stages propagates a different set of thread context.voidThe withContextCapture method should be able to create a dependent stage that is associated with a thread context even if its parent stage is already associated with a different thread context.voidVerify that the presence of a default executor service allows contextualised CompletableFuture/CompletionStage to run async actions on them, and that they are running on that executor service.voidVerify that the lack of a default executor service bans contextualised CompletableFuture/CompletionStage from running async actions on them.Methods inherited from class org.jboss.arquillian.testng.Arquillian
arquillianAfterClass, arquillianAfterSuite, arquillianAfterTest, arquillianArgumentProvider, arquillianBeforeClass, arquillianBeforeSuite, arquillianBeforeTest, run
-
Constructor Details
-
ThreadContextTest
public ThreadContextTest()
-
-
Method Details
-
after
@AfterClass public void after() -
afterMethod
-
before
@BeforeClass public void before() -
beforeMethod
-
createDeployment
@Deployment public static org.jboss.shrinkwrap.api.spec.WebArchive createDeployment() -
builderForThreadContextIsProvided
public void builderForThreadContextIsProvided() -
clearTransactionContextJTA
Verify that if JTA transactions are supported, then configuring cleared=TRANSACTION results in the active transaction being suspended before running a task and resumed afterward, such that a task can use its own transactions if so desired. The test tries to get hold ofUserTransactionvia JNDI and via CDI. Should neither work, it still doesn't throw exception but instead returns.- Throws:
Exception- indicates test failure
-
clearUnspecifiedContexts
Verify that the ThreadContext implementation clears context types that are not configured under propagated, unchanged, or cleared.- Throws:
Exception- indicates test failure
-
contextualBiConsumerRunsWithContext
Verify that the ThreadContext's contextualConsumer method can be used to wrap a BiConsumer instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the BiConsumer accept method runs. This test case aligns with use case of supplying a contextual BiConsumer to a completion stage that is otherwise not context-aware.- Throws:
InterruptedException- indicates test failure
-
contextualBiFunctionRunsWithContext
public void contextualBiFunctionRunsWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's contextualFunction method can be used to wrap a BiFunction instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the BiFunction apply method runs. This test case aligns with use case of supplying a contextual BiFunction to a completion stage that is otherwise not context-aware.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
contextualCallableRunsWithContext
public void contextualCallableRunsWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's contextualCallable method can be used to wrap a Callable instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Callable call method runs. This test case aligns with use case of supplying a contextual Callable to an unmanaged executor that is otherwise not context-aware.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
contextualConsumerRunsWithContext
Verify that the ThreadContext's contextualConsumer method can be used to wrap a Consumer instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Consumer accept method runs. This test case aligns with use case of supplying a contextual Consumer to a completion stage that is otherwise not context-aware.- Throws:
InterruptedException- indicates test failure
-
contextualFunctionRunsWithContext
public void contextualFunctionRunsWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's contextualFunction method can be used to wrap a Function instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Function apply method runs. This test case aligns with use case of supplying a contextual Function to a completion stage that is otherwise not context-aware.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
contextualRunnableRunsWithContext
public void contextualRunnableRunsWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's contextualRunnable method can be used to wrap a Runnable instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Runnable run method runs. This test case aligns with use case of supplying a contextual Runnable to a completion stage that is otherwise not context-aware.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
contextualSupplierRunsWithContext
Verify that the ThreadContext's contextualSupplier method can be used to wrap a Supplier instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied when the Supplier get method runs. This test case aligns with use case of supplying a contextual Supplier to a completion stage that is otherwise not context-aware.- Throws:
InterruptedException- indicates test failure
-
reuseThreadContextBuilder
Verify that the ThreadContext.Builder can be used to create multiple ThreadContexts with different configured contexts.- Throws:
Exception- indicates test failure
-
unchangedContextListDefaultsToEmpty
public void unchangedContextListDefaultsToEmpty()It is optional to specify the set of unchanged context. In absence of any specified value and if MicroProfile Config is not used to override the default, the unchanged context list defaults to empty. -
thirdPartyContextProvidersAreIncludedInThreadContext
public void thirdPartyContextProvidersAreIncludedInThreadContext()Verify that the MicroProfile Context Propagation implementation finds third-party thread context providers that are made available to the ServiceLoader, allows their configuration via the ThreadContext builder, and correctly captures and propagates or clears these thread context types per the builder configuration. Subsequently verify that the MicroProfile Context Propagation implementation properly restores thread context after the contextual action completes. -
withContextCaptureDependentCompletableFuturesRunWithContext
public void withContextCaptureDependentCompletableFuturesRunWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's withContextCapture method can be used to create a dependent CompletableFuture instance that completes when the original stage completes and runs dependent stage actions with context that is captured from the thread that creates the dependent stage.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
withContextCaptureDependentCompletionStagesRunWithContext
public void withContextCaptureDependentCompletionStagesRunWithContext() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the ThreadContext's withContextCapture method can be used to create a dependent CompletionStage instance that completes when the original stage completes and runs dependent stage actions with context that is captured from the thread that creates the dependent stage.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
withContextCaptureDependentStageForcedCompletion
public void withContextCaptureDependentStageForcedCompletion() throws ExecutionException, InterruptedExceptionVerify that dependent stages created via withContextCapture can be completed independently of the original stage.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failure
-
withContextCaptureMultipleThreadContexts
public void withContextCaptureMultipleThreadContexts() throws ExecutionException, InterruptedException, TimeoutExceptionThe withContextCapture method should be able to create multiple dependent stages having a single parent stage, where each of the dependent stages propagates a different set of thread context.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
withContextCaptureSwitchThreadContext
public void withContextCaptureSwitchThreadContext() throws ExecutionException, InterruptedException, TimeoutExceptionThe withContextCapture method should be able to create a dependent stage that is associated with a thread context even if its parent stage is already associated with a different thread context. Both stages must honor their respective thread context.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
contextControlsForThreadContextBuilder
public void contextControlsForThreadContextBuilder() throws InterruptedException, ExecutionException, TimeoutExceptionVerify the MicroProfile Context Propagation implementation of propagate(), cleared(), and unchanged() for ThreadContext.Builder.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
currentContextExecutorRunsWithContext
public void currentContextExecutorRunsWithContext() throws InterruptedException, ExecutionException, TimeoutExceptionVerify that the ThreadContext's currentContextExecutor method can be used to create an Executor instance with the context that is captured from the current thread per the configuration of the ThreadContext builder, and that the context is applied to the thread where the Executor's execute method runs. This test case aligns with use case of supplying a contextual Executor to a thread that is otherwise not context-aware.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
withDefaultExecutorServiceContextCanInvokeAsyncActions
public void withDefaultExecutorServiceContextCanInvokeAsyncActions() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the presence of a default executor service allows contextualised CompletableFuture/CompletionStage to run async actions on them, and that they are running on that executor service.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-
withoutDefaultExecutorServiceContextCannotInvokeAsyncActions
public void withoutDefaultExecutorServiceContextCannotInvokeAsyncActions() throws ExecutionException, InterruptedException, TimeoutExceptionVerify that the lack of a default executor service bans contextualised CompletableFuture/CompletionStage from running async actions on them.- Throws:
ExecutionException- indicates test failureInterruptedException- indicates test failureTimeoutException- indicates test failure
-