diff --git a/connect/connect-c7/worker-adapter-c7/src/main/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7WorkerAdapter.java b/connect/connect-c7/worker-adapter-c7/src/main/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7WorkerAdapter.java index d1a7907a8..bef679a45 100644 --- a/connect/connect-c7/worker-adapter-c7/src/main/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7WorkerAdapter.java +++ b/connect/connect-c7/worker-adapter-c7/src/main/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7WorkerAdapter.java @@ -49,7 +49,7 @@ public void execute(final WorkerExecutor executor, final ExternalTask externalTa } catch (final Exception error) { int retries = getRemainingRetries(externalTask.getRetries(), workerRetries); log.severe("Error while executing external task " + error.getMessage()); - service.handleFailure(externalTask, error.getMessage(), Arrays.toString(error.getStackTrace()), retries -1, 5000L); + service.handleFailure(externalTask, error.getMessage(), Arrays.toString(error.getStackTrace()), retries, 5000L); } } @@ -66,11 +66,15 @@ public void execute(final WorkerExecutor executor, final ExternalTask externalTa * @return The remaining number of retries for the task. */ private int getRemainingRetries(Integer externalTaskRetries, Integer workerRetries) { + int retries = 0; if (Objects.isNull(externalTaskRetries)) { - return Objects.isNull(workerRetries) ? + retries = Objects.isNull(workerRetries) ? camunda7WorkerProperties.getDefaultRetries() : workerRetries; + }else { + retries = externalTaskRetries; } - return externalTaskRetries; + retries -= 1; + return Math.max(retries, 0); } } \ No newline at end of file diff --git a/connect/connect-c7/worker-adapter-c7/src/test/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7AdapterTest.java b/connect/connect-c7/worker-adapter-c7/src/test/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7AdapterTest.java index 99ecb5e5d..95a38ef61 100644 --- a/connect/connect-c7/worker-adapter-c7/src/test/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7AdapterTest.java +++ b/connect/connect-c7/worker-adapter-c7/src/test/java/io/miragon/miranum/connect/adapter/in/c7/worker/Camunda7AdapterTest.java @@ -87,7 +87,7 @@ void givenDefaultUseCaseAndRetriesProvided_thenInvokeGetRemainingRetries() throw var retriesCaptor = ArgumentCaptor.forClass(Integer.class); then(service).should().handleFailure((ExternalTask) any(), any(), any(), retriesCaptor.capture(), anyLong()); - assertEquals(3, retriesCaptor.getValue()); + assertEquals(3-1, retriesCaptor.getValue()); } @Test @@ -101,7 +101,7 @@ void givenDefaultUseCaseAndRetriesSetInBpmn_thenUseBpmnRetries() { adapter.execute(defaultWorker, externalTask, service); - then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(bpmnRetries), anyLong()); + then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(bpmnRetries-1), anyLong()); } @Test @@ -117,7 +117,7 @@ void givenDefaultUseCaseAndRetriesSetInWorkerInput_thenUseWorkerRetries() { adapter.execute(defaultWorker, externalTask, service); - then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(workerRetries), anyLong()); + then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(workerRetries-1), anyLong()); } @Test @@ -131,7 +131,7 @@ void givenDefaultUseCaseAndNoRetriesProvided_thenUseDefaultRetries() { adapter.execute(defaultWorker, externalTask, service); - then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(defaultRetries), anyLong()); + then(service).should().handleFailure((ExternalTask) any(), any(), any(), eq(defaultRetries-1), anyLong()); } @Test