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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    afterMethod(Method m, org.testng.ITestResult result)
     
    void
     
    void
     
    void
     
    void
    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.
    void
    Verify that the ThreadContext implementation clears context types that are not configured under propagated, unchanged, or cleared.
    void
    Verify the MicroProfile Context Propagation implementation of propagate(), cleared(), and unchanged() for ThreadContext.Builder.
    void
    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.
    void
    Verify 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.
    void
    Verify 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.
    void
    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.
    void
    Verify 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.
    void
    Verify 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.
    void
    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.
    static org.jboss.shrinkwrap.api.spec.WebArchive
     
    void
    Verify 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.
    void
    Verify that the ThreadContext.Builder can be used to create multiple ThreadContexts with different configured contexts.
    void
    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.
    void
    It is optional to specify the set of unchanged context.
    void
    Verify 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.
    void
    Verify 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.
    void
    Verify that dependent stages created via withContextCapture can be completed independently of the original stage.
    void
    The 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.
    void
    The 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.
    void
    Verify 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.
    void
    Verify 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ThreadContextTest

      public ThreadContextTest()
  • Method Details

    • after

      @AfterClass public void after()
    • afterMethod

      @AfterMethod public void afterMethod(Method m, org.testng.ITestResult result)
    • before

      @BeforeClass public void before()
    • beforeMethod

      @BeforeMethod public void beforeMethod(Method m)
    • createDeployment

      @Deployment public static org.jboss.shrinkwrap.api.spec.WebArchive createDeployment()
    • builderForThreadContextIsProvided

      public void builderForThreadContextIsProvided()
    • clearTransactionContextJTA

      public void clearTransactionContextJTA() throws Exception
      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 of UserTransaction via JNDI and via CDI. Should neither work, it still doesn't throw exception but instead returns.
      Throws:
      Exception - indicates test failure
    • clearUnspecifiedContexts

      public void clearUnspecifiedContexts() throws Exception
      Verify that the ThreadContext implementation clears context types that are not configured under propagated, unchanged, or cleared.
      Throws:
      Exception - indicates test failure
    • contextualBiConsumerRunsWithContext

      public void contextualBiConsumerRunsWithContext() throws InterruptedException
      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, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • contextualCallableRunsWithContext

      public void contextualCallableRunsWithContext() throws ExecutionException, InterruptedException, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • contextualConsumerRunsWithContext

      public void contextualConsumerRunsWithContext() throws InterruptedException
      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, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • contextualRunnableRunsWithContext

      public void contextualRunnableRunsWithContext() throws ExecutionException, InterruptedException, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • contextualSupplierRunsWithContext

      public void contextualSupplierRunsWithContext() throws InterruptedException
      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

      public void reuseThreadContextBuilder() throws Exception
      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, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • withContextCaptureDependentCompletionStagesRunWithContext

      public void withContextCaptureDependentCompletionStagesRunWithContext() throws ExecutionException, InterruptedException, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • withContextCaptureDependentStageForcedCompletion

      public void withContextCaptureDependentStageForcedCompletion() throws ExecutionException, InterruptedException
      Verify that dependent stages created via withContextCapture can be completed independently of the original stage.
      Throws:
      ExecutionException - indicates test failure
      InterruptedException - indicates test failure
    • withContextCaptureMultipleThreadContexts

      public void withContextCaptureMultipleThreadContexts() throws ExecutionException, InterruptedException, TimeoutException
      The 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • withContextCaptureSwitchThreadContext

      public void withContextCaptureSwitchThreadContext() throws ExecutionException, InterruptedException, TimeoutException
      The 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • contextControlsForThreadContextBuilder

      public void contextControlsForThreadContextBuilder() throws InterruptedException, ExecutionException, TimeoutException
      Verify the MicroProfile Context Propagation implementation of propagate(), cleared(), and unchanged() for ThreadContext.Builder.
      Throws:
      ExecutionException - indicates test failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • currentContextExecutorRunsWithContext

      public void currentContextExecutorRunsWithContext() throws InterruptedException, ExecutionException, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • withDefaultExecutorServiceContextCanInvokeAsyncActions

      public void withDefaultExecutorServiceContextCanInvokeAsyncActions() throws ExecutionException, InterruptedException, TimeoutException
      Verify 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 failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure
    • withoutDefaultExecutorServiceContextCannotInvokeAsyncActions

      public void withoutDefaultExecutorServiceContextCannotInvokeAsyncActions() throws ExecutionException, InterruptedException, TimeoutException
      Verify that the lack of a default executor service bans contextualised CompletableFuture/CompletionStage from running async actions on them.
      Throws:
      ExecutionException - indicates test failure
      InterruptedException - indicates test failure
      TimeoutException - indicates test failure