TestActivityEnvironment does not work with Asynchronous Activity Completion
We have activity, that is using "Asynchronous Activity Completion" and we want to test it. In our case, we just want to test, that activity will send proper kafka message, but still, we need to set up test environment, to obtain activity token, etc.
In shortest form, our test looks like this:
var testActivityEnvironment = TestActivityEnvironment.newInstance(TestEnvironmentOptions.getDefaultInstance());
testActivityEnvironment.registerActivitiesImplementations(activityImpl);
var testActivity = testActivityEnvironment.newActivityStub(SomeActivities.class);
testActivity.execute();
Inside of activityImpl we use context.doNotCompleteOnReturn();
Problem is, that TestActivityEnvironmentInternal expects either cancelled, failed or completed activity.
In case of not async activity, all fields of ActivityTaskHandler.Result are null and we get NullPointerException
Problematic block of code: https://github.com/temporalio/sdk-java/blob/master/temporal-testing/src/main/java/io/temporal/testing/TestActivityEnvironmentInternal.java#L489-L496
Expected Behavior
Calling mehod of async activity will do nothing.
Actual Behavior
NullPointerException at https://github.com/temporalio/sdk-java/blob/master/temporal-testing/src/main/java/io/temporal/testing/TestActivityEnvironmentInternal.java#L496 (response.getTaskFailed() is null)
Specifications
- Version: 1.23.2
- Platform: windows
Hi, I found a similar open issue: https://github.com/temporalio/sdk-java/issues/460 They may be connected or reflect the same issue. There are not too many activities but maybe it is a good idea to link them.
Hi, i added a very small fix for this issue - i wonder why this bug is open for so long. Anyway, as a sidenote: testing async activities is should get more love, e.g. there is no TestWorkflowClient at the moment that would allow proper testing of the activity