-
Notifications
You must be signed in to change notification settings - Fork 19
Add in-memory WorkflowInstance store #300
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
Open
mcruzdev
wants to merge
1
commit into
quarkiverse:main
Choose a base branch
from
mcruzdev:issue-118
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
core/deployment/src/test/java/io/quarkiverse/flow/deployment/test/devui/DevUIWorkflow.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| package io.quarkiverse.flow.deployment.test.devui; | ||
|
|
||
| import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.function; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import jakarta.enterprise.context.ApplicationScoped; | ||
|
|
||
| import io.quarkiverse.flow.Flow; | ||
| import io.serverlessworkflow.api.types.Workflow; | ||
| import io.serverlessworkflow.fluent.spec.WorkflowBuilder; | ||
| import io.serverlessworkflow.fluent.func.FuncWorkflowBuilder; | ||
|
|
||
| @ApplicationScoped | ||
| public class DevUIWorkflow extends Flow { | ||
|
|
||
| @Override | ||
| public Workflow descriptor() { | ||
| return WorkflowBuilder.workflow("helloQuarkus") | ||
| return FuncWorkflowBuilder.workflow("helloQuarkus") | ||
| .tasks(t -> t.set("taskHello", """ | ||
| { "message": "helloWorld" } | ||
| """)) | ||
| """), | ||
| function("aliceFn", person -> Map.of("name", "Alice"), Map.class), | ||
| function("messageFn", person -> Map.of("message", "Message from " + person.get("name") + " to me!"), | ||
| Map.class)) | ||
| .build(); | ||
| } | ||
| } |
130 changes: 130 additions & 0 deletions
130
...t/java/io/quarkiverse/flow/deployment/test/devui/LifecycleManagementDevUIJsonRPCTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package io.quarkiverse.flow.deployment.test.devui; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.assertj.core.api.SoftAssertions; | ||
| import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
|
|
||
| import io.quarkus.devui.tests.DevUIJsonRPCTest; | ||
| import io.quarkus.test.QuarkusDevModeTest; | ||
| import io.restassured.RestAssured; | ||
| import io.vertx.core.json.JsonArray; | ||
|
|
||
| public class LifecycleManagementDevUIJsonRPCTest extends DevUIJsonRPCTest { | ||
|
|
||
| @RegisterExtension | ||
| static final QuarkusDevModeTest devMode = new QuarkusDevModeTest() | ||
| .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
| .addClasses(GreetingResource.class, DevUIWorkflow.class)); | ||
|
|
||
| public LifecycleManagementDevUIJsonRPCTest() { | ||
| super("quarkus-flow"); | ||
| } | ||
|
|
||
| @Test | ||
| void should_not_get_due_to_pagination_size_as_zero() throws Exception { | ||
|
|
||
| executeDevUiWorkflowSomeTimes(1); | ||
|
|
||
| JsonNode root = super.executeJsonRPCMethod("listAllWorkflowInstances", Map.of( | ||
| "page", 0, | ||
| "size", 0, | ||
| "sort", "START_TIME_ASC")); | ||
|
|
||
| JsonArray array = new JsonArray(root.toString()); | ||
|
|
||
| Assertions.assertThat(array) | ||
| .as("should not have items because the page is 0 and the size is 0") | ||
| .isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void paginate_options_should_work_as_expected() throws Exception { | ||
|
|
||
| executeDevUiWorkflowSomeTimes(5); | ||
|
|
||
| SoftAssertions softly = new SoftAssertions(); | ||
|
|
||
| JsonNode sizeJson = super.executeJsonRPCMethod("listAllWorkflowInstances", Map.of( | ||
| "page", 0, | ||
| "size", 3, | ||
| "sort", "START_TIME_ASC")); | ||
|
|
||
| JsonArray array = new JsonArray(sizeJson.toString()); | ||
|
|
||
| softly.assertThat(array.size()).isEqualTo(3) | ||
| .as("should have only three workflow instances because we are in the page 0 and the size is 5"); | ||
|
|
||
| JsonNode pageJson = super.executeJsonRPCMethod("listAllWorkflowInstances", Map.of( | ||
| "page", 1, | ||
| "size", 10, | ||
| "sort", "START_TIME_ASC")); | ||
|
|
||
| JsonArray pageArray = new JsonArray(pageJson.toString()); | ||
|
|
||
| softly.assertThat(pageArray) | ||
| .as("should not have workflow instances because the page is 1 (there is no item in page 1 with size 10") | ||
| .isEmpty(); | ||
|
|
||
| softly.assertAll(); | ||
| } | ||
|
|
||
| @Test | ||
| void should_get_by_status() throws Exception { | ||
| executeDevUiWorkflowSomeTimes(1); | ||
|
|
||
| JsonNode root = this.executeJsonRPCMethod("findByStatus", Map.of("status", "COMPLETED")); | ||
|
|
||
| SoftAssertions softly = new SoftAssertions(); | ||
|
|
||
| for (JsonNode jsonNode : root) { | ||
| softly.assertThat(jsonNode.get("status").asText()).isEqualTo("COMPLETED"); | ||
| } | ||
|
|
||
| JsonNode faulted = this.executeJsonRPCMethod("findByStatus", Map.of("status", "FAULTED", "page", 0, "size", 10)); | ||
|
|
||
| softly.assertThat(faulted) | ||
| .as("should not have faulted workflows") | ||
| .isEmpty(); | ||
|
|
||
| softly.assertAll(); | ||
| } | ||
|
|
||
| @Test | ||
| void should_get_workflow_instance_by_id() throws Exception { | ||
|
|
||
| executeDevUiWorkflowSomeTimes(1); | ||
|
|
||
| JsonNode root = this.executeJsonRPCMethod("findByStatus", Map.of("status", "COMPLETED", "page", 0, "size", 10)); | ||
| JsonNode workflowInstance = root.valueStream().findFirst().orElseThrow(); | ||
|
|
||
| SoftAssertions softly = new SoftAssertions(); | ||
|
|
||
| String instanceId = workflowInstance.get("instanceId").asText(); | ||
| softly.assertThat(instanceId).isNotNull(); | ||
| softly.assertThat(instanceId).isNotBlank(); | ||
|
|
||
| JsonNode jsonNode = this.executeJsonRPCMethod("findByWorkflowId", Map.of( | ||
| "instanceId", instanceId)); | ||
|
|
||
| softly.assertThat(jsonNode.get("instanceId").asText()).isEqualTo(instanceId).as( | ||
| "the instance ID must be the same value"); | ||
|
|
||
| softly.assertAll(); | ||
| } | ||
|
|
||
| private static void executeDevUiWorkflowSomeTimes(int times) { | ||
| for (int i = 0; i < times; i++) { | ||
| RestAssured.given() | ||
| .get("/hello") | ||
| .then() | ||
| .statusCode(200); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name already communicates the intention.