Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeebeSpringTest fails when using manually registered workers #922

Open
billbarni opened this issue Aug 28, 2024 · 0 comments
Open

ZeebeSpringTest fails when using manually registered workers #922

billbarni opened this issue Aug 28, 2024 · 0 comments

Comments

@billbarni
Copy link

billbarni commented Aug 28, 2024

Describe the bug

When registering JobWorkers manually:

@Component
@Log
public class SomeWorker {

    @Value("${zeebe.workers.someWorker.jobType}")
    private String jobType;

    @Autowired
    private ZeebeClient zeebeClient;

    @PostConstruct
    public void registerWorker() {
        zeebeClient.newWorker()
                .jobType(jobType)
                .handler((jobClient, activatedJob) -> System.out.println(jobClient.toString() + " | " + activatedJob.toString()))
                .open();
    }

}

@ZeebeSpringTest tests are not able to inject ZeebeClient, considering it as not initalized.

@SpringBootTest
@ZeebeSpringTest
@ExtendWith(ProcessEngineCoverageExtension.class)
class CamundaWorkersAndWorkflowTest {

    @Autowired
    private ZeebeTestEngine zeebeTestEngine;

    @Autowired
    private ZeebeClient zeebeClient;

    @Test
    public void testHappyPath() throws InterruptedException, TimeoutException {
        zeebeClient.newDeployResourceCommand().addResourceFromClasspath("camunda/bpmn/some_process.bpmn").send().join();
    }

}

Exception
Caused by: java.lang.RuntimeException: Cannot invoke public abstract io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1 io.camunda.zeebe.client.ZeebeClient.newWorker() on ZeebeClient, as ZeebeClient is currently not initialized. Maybe you run outside of a testcase?
at io.camunda.zeebe.spring.test.proxy.ZeebeClientProxy.handleInvocation(ZeebeClientProxy.java:28)
at io.camunda.zeebe.spring.test.proxy.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:40)
at jdk.proxy2/jdk.proxy2.$Proxy93.newWorker(Unknown Source)

To Reproduce

Create the worker class in the project like the one above, and create a test like the one above. The project runs fine but the tests don't.

Expected behavior

The project and tests to work.
Or @Jobworker to support non-constant variable as jobType, using SPEL or other technique to feed the jobType during startup.

Environment:

  • OS: Windows 10
  • Deployment: Self-Managed
  • Spring-Zeebe Version: 8.5.9
  • SpringBoot Version: 3.3.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant