Testing an activity implementation when using ActivityExecutionContext to asynchronously execute activities

Hello!

We’ve started using the ManualActivityCompletionClient as a way to execute the code in our activities asynchronously . The question we have is on how to test the activities after this change, as calling the activities in our test code now gives the following IllegalStateException:

ActivityExecutionContext can be used only inside of activity implementation methods and in the same thread that invoked an activity.
java.lang.IllegalStateException: ActivityExecutionContext can be used only inside of activity implementation methods and in the same thread that invoked an activity.

Any examples on how to test code that makes use of the ManualActivityCompletionClient would be greatly appreciated!

In the java sdk samples repo you can look at

  1. HelloAsyncActivityCompletion
  2. HelloAsyncActivityCompletionTest

is this what you are looking for?

Hey!
Thanks for the reply!
I think the example you gave is for testing a full workflow. In my case it’s just the activity I want to be testing. Before using the async logic, I was able to simply instantiate the activities implementation, mocking out the backend, so I can define exactly what to return when the method on the activity is called. Since I was awaiting the result in the activity, I could then compare the output of the call with the expected outcome.
I hope that makes some sense. Please tell me if you need me to clarify a bit more

I don’t think it is currently supported. Here is the associated issue.