sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

TestActivityEnvironment does not work with Asynchronous Activity Completion

Open bjab opened this issue 1 year ago • 1 comments

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

bjab avatar Jun 06 '24 13:06 bjab