@ZeebeWorker(type = "task1-service-worker")
public void task1Service(final ActivatedJob job, final JobClient client) throws Exception {
try {
log.info("Task1 Service is running, job key: {}", job.getKey());
Map<String, Object> variableMap = job.getVariablesAsMap();
Object taskToFail = variableMap.get("taskToFail");
if (taskToFail != null) {
boolean isFail = taskToFail.toString().trim().equalsIgnoreCase("task1");
if (!isFail) {
int sleepDurationSecs = 10;
log.info("Simulating short run by sleeping for {} seconds...", sleepDurationSecs);
TimeUnit.SECONDS.sleep(sleepDurationSecs);
client.newCompleteCommand(job).send();
log.info("Task1 Service is completed");
} else {
client.newFailCommand(job).retries(0).send();
log.info("Task1 Service is failed");
}
} else {
throw new ExampleServiceException("taskToFail variable is not available");
}
} catch (InterruptedException ie) {
log.error("Error in Task1 Service. Sleeping is interrupted.");
throw ie;
} catch (ExampleServiceException ese) {
log.error("Error in Task1 Service.");
throw ese;
} catch (Exception e) {
log.error("Error in Task1 Service.");
throw new ExampleServiceException("Error in Task1 Service", e);
}
}
This is the method for which I have to provide Junit tests
Please provide example for reference as well with ZeebeWorker