From 2b8e595bfa999d2a8a392af7909ae09e961c2531 Mon Sep 17 00:00:00 2001 From: Viren Baraiya Date: Sun, 28 Jan 2024 17:04:26 -0800 Subject: [PATCH] tests and formatting --- build.gradle | 2 +- .../conductor/client/http/WorkflowClient.java | 1 + .../io/orkes/conductor/client/ApiClient.java | 3 +- .../conductor/client/WorkflowClient.java | 2 +- .../client/http/ConflictException.java | 7 +++-- .../client/http/OrkesWorkflowClient.java | 2 +- .../conductor/client/api/ClientTest.java | 1 + .../client/api/WorkflowClientTests.java | 1 + .../client/api/WorkflowStateUpdateTests.java | 29 +++++++++++++++++++ 9 files changed, 41 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 36ae3def..25a7f546 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ ext { versions = [ awaitility : '4.2.0', commonsLang : '3.12.0', - conductor : '3.9.24-orkes', + conductor : '3.9.30-orkes', jackson : '2.11.4!!', junit : '5.9.0', slf4j : '1.7.36', diff --git a/src/main/java/com/netflix/conductor/client/http/WorkflowClient.java b/src/main/java/com/netflix/conductor/client/http/WorkflowClient.java index fc4dab3f..dbd37c2b 100644 --- a/src/main/java/com/netflix/conductor/client/http/WorkflowClient.java +++ b/src/main/java/com/netflix/conductor/client/http/WorkflowClient.java @@ -22,6 +22,7 @@ import com.netflix.conductor.common.run.WorkflowSummary; import com.netflix.conductor.common.run.WorkflowTestRequest; import com.netflix.conductor.common.utils.ExternalPayloadStorage; + import io.orkes.conductor.client.http.ConflictException; public abstract class WorkflowClient { diff --git a/src/main/java/io/orkes/conductor/client/ApiClient.java b/src/main/java/io/orkes/conductor/client/ApiClient.java index fcfbc11b..bdf234df 100644 --- a/src/main/java/io/orkes/conductor/client/ApiClient.java +++ b/src/main/java/io/orkes/conductor/client/ApiClient.java @@ -41,7 +41,6 @@ import javax.net.ssl.*; -import com.netflix.conductor.common.validation.ErrorResponse; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +48,8 @@ import org.threeten.bp.OffsetDateTime; import org.threeten.bp.format.DateTimeFormatter; +import com.netflix.conductor.common.validation.ErrorResponse; + import io.orkes.conductor.client.http.*; import io.orkes.conductor.client.http.api.TokenResourceApi; import io.orkes.conductor.client.http.auth.ApiKeyAuth; diff --git a/src/main/java/io/orkes/conductor/client/WorkflowClient.java b/src/main/java/io/orkes/conductor/client/WorkflowClient.java index 0c79e19c..b5e08958 100644 --- a/src/main/java/io/orkes/conductor/client/WorkflowClient.java +++ b/src/main/java/io/orkes/conductor/client/WorkflowClient.java @@ -104,7 +104,7 @@ public abstract Map> getWorkflowsByNamesAndCorrelationIds * the call will return with the current status of the workflow * @param updateRequest Payload for updating state of workflow. * - * @return + * @return Returns updated workflow execution */ public abstract WorkflowRun updateWorkflow(String workflowId, List waitUntilTaskRefNames, Integer waitForSeconds, WorkflowStateUpdate updateRequest); diff --git a/src/main/java/io/orkes/conductor/client/http/ConflictException.java b/src/main/java/io/orkes/conductor/client/http/ConflictException.java index 93ee2970..ae4d54f2 100644 --- a/src/main/java/io/orkes/conductor/client/http/ConflictException.java +++ b/src/main/java/io/orkes/conductor/client/http/ConflictException.java @@ -12,12 +12,13 @@ */ package io.orkes.conductor.client.http; -import io.orkes.conductor.client.OrkesClientException; -import org.apache.commons.lang3.StringUtils; - import java.util.List; import java.util.Map; +import org.apache.commons.lang3.StringUtils; + +import io.orkes.conductor.client.OrkesClientException; + public class ConflictException extends OrkesClientException { private int code; diff --git a/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java b/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java index f6f64794..3eca4225 100644 --- a/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java +++ b/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java @@ -19,9 +19,9 @@ import java.util.UUID; import java.util.concurrent.*; -import com.netflix.conductor.common.metadata.workflow.*; import org.apache.commons.lang.StringUtils; +import com.netflix.conductor.common.metadata.workflow.*; import com.netflix.conductor.common.model.BulkResponse; import com.netflix.conductor.common.run.SearchResult; import com.netflix.conductor.common.run.Workflow; diff --git a/src/test/java/io/orkes/conductor/client/api/ClientTest.java b/src/test/java/io/orkes/conductor/client/api/ClientTest.java index 81171714..f162b2af 100644 --- a/src/test/java/io/orkes/conductor/client/api/ClientTest.java +++ b/src/test/java/io/orkes/conductor/client/api/ClientTest.java @@ -16,6 +16,7 @@ import io.orkes.conductor.client.util.ApiUtil; public abstract class ClientTest { + protected static OrkesClients orkesClients; static { diff --git a/src/test/java/io/orkes/conductor/client/api/WorkflowClientTests.java b/src/test/java/io/orkes/conductor/client/api/WorkflowClientTests.java index b793c5f5..e5a104c9 100644 --- a/src/test/java/io/orkes/conductor/client/api/WorkflowClientTests.java +++ b/src/test/java/io/orkes/conductor/client/api/WorkflowClientTests.java @@ -206,6 +206,7 @@ public void testSkipTaskFromWorkflow() throws Exception { () -> workflowClient.terminateWorkflowsWithFailure(List.of(workflowId), null, false)); } + @Test public void testUpdateVariables() { ConductorWorkflow workflow = new ConductorWorkflow<>(workflowExecutor); workflow.add(new SimpleTask("simple_task", "simple_task_ref")); diff --git a/src/test/java/io/orkes/conductor/client/api/WorkflowStateUpdateTests.java b/src/test/java/io/orkes/conductor/client/api/WorkflowStateUpdateTests.java index 1505179f..e18f85b8 100644 --- a/src/test/java/io/orkes/conductor/client/api/WorkflowStateUpdateTests.java +++ b/src/test/java/io/orkes/conductor/client/api/WorkflowStateUpdateTests.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -23,16 +24,19 @@ import com.netflix.conductor.common.metadata.tasks.Task; import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.common.metadata.workflow.IdempotencyStrategy; import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; import com.netflix.conductor.common.run.Workflow; import io.orkes.conductor.client.WorkflowClient; +import io.orkes.conductor.client.http.ConflictException; import io.orkes.conductor.client.model.WorkflowStateUpdate; import io.orkes.conductor.common.model.WorkflowRun; import lombok.SneakyThrows; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class WorkflowStateUpdateTests extends ClientTest { @@ -96,4 +100,29 @@ public void test() { .collect(Collectors.toList())); } + + @Test + public void testIdempotency() { + StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); + startWorkflowRequest.setName("sync_task_variable_updates"); + startWorkflowRequest.setVersion(1); + String idempotencyKey = UUID.randomUUID().toString(); + startWorkflowRequest.setIdempotencyKey(idempotencyKey); + startWorkflowRequest.setIdempotencyStrategy(IdempotencyStrategy.FAIL); + String workflowId = workflowClient.startWorkflow(startWorkflowRequest); + + + startWorkflowRequest.setIdempotencyStrategy(IdempotencyStrategy.RETURN_EXISTING); + String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); + assertEquals(workflowId, workflowId2); + + startWorkflowRequest.setIdempotencyStrategy(IdempotencyStrategy.FAIL); + boolean conflict = false; + try { + workflowClient.startWorkflow(startWorkflowRequest); + } catch (ConflictException ce) { + conflict = true; + } + assertTrue(conflict); + } }