Yeah, looks like it get past at least the error.
In your example, put a break point in POJOActivityImplMetadata.java
. When you call worker.registerActivitiesImplementations(activities);
, and it hits your break point you will see that the getAnnotation code doesn’t work. The method Account::deposit has a defined annotation. Not sure why it doesn’t pick it up.
But in my code, the annotation actually picks up @ActivityMethod
and throws the exception.
But without the @ActivityMethod
I don’t believe workflow would work since it won’t know how to pick it up (from my understanding). So in my case, the activity gets scheduled, but it seems like the workflow doesn’t know how to trigger the activity.
One thing i do notice is that when I debug the sample java project, I notice that all the methods in the mocked out interface contain an enhancerByMockitoWithGLIB
which I don’t have on mine.
Mine has MockitoMock.
It looks like your using
testImplementation group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.4'
It looks like the different version of mockito and your usage of powermock that may allow you to by pass the annotation that are part of the interface method which will trigger an exception.
Interestingly, if you tried to mock the Activities implementation, you will get the following error
java.lang.IllegalArgumentException: Class doesn't implement any non empty interface annotated with @ActivityInterface: io.temporal.samples.hello.HelloActivity$GreetingActivitiesImpl$$EnhancerByMockitoWithCGLIB$$fb34bcd0
@Test
public void testMockedActivity() {
HelloActivity.GreetingActivitiesImpl activities =
mock(HelloActivity.GreetingActivitiesImpl.class);
when(activities.composeGreeting("Hello", "World")).thenReturn("Hello World!");
worker.registerActivitiesImplementations(activities);
testEnv.start();
// Get a workflow stub using the same task queue the worker uses.
GreetingWorkflow workflow =
client.newWorkflowStub(
GreetingWorkflow.class,
WorkflowOptions.newBuilder().setTaskQueue("GreetingActivities").build());
// Execute a workflow waiting for it to complete.
String greeting = workflow.getGreeting("World");
assertEquals("Hello World!", greeting);
}
/** Activity interface is just a POJI. */
@ActivityInterface
public interface GreetingActivities {
@ActivityMethod
String composeGreeting(String greeting, String name);
}
static class GreetingActivitiesImpl implements GreetingActivities {
@Override
public String composeGreeting(String greeting, String name) {
return greeting + " " + name + "!";
}
}
looks like it doesn’t handle interface for annotation so doesn’t look like this way is possible