From d5d920164707a5f61f56e26523f2696b7b037d96 Mon Sep 17 00:00:00 2001 From: Loic Hermann Date: Mon, 12 Aug 2024 08:19:13 -0400 Subject: [PATCH] workflow & activities discovery unit test --- .../ROOT/pages/includes/quarkus-temporal.adoc | 17 ------- .../deployment/TemporalProcessor.java | 2 +- ...ctivityDiscoveryOnDifferentWorkerTest.java | 37 ++++++++++++++++ ...SameActivityDiscoveryOnSameWorkerTest.java | 44 +++++++++++++++++++ ...orkflowDiscoveryOnDifferentWorkerTest.java | 36 +++++++++++++++ ...SameWorkflowDiscoveryOnSameWorkerTest.java | 40 +++++++++++++++++ .../discovery/DefaultSimpleActivityImpl.java | 7 +++ .../discovery/DefaultSimpleWorkflowImpl.java | 9 ++++ .../DuplicateDefaultSimpleActivityImpl.java | 7 +++ .../DuplicateDefaultSimpleWorkflowImpl.java | 9 ++++ .../discovery/NamedSimpleActivityImpl.java | 10 +++++ .../discovery/NamedSimpleWorkflowImpl.java | 12 +++++ .../deployment/discovery/SimpleActivity.java | 11 +++++ .../deployment/discovery/SimpleWorkflow.java | 11 +++++ 14 files changed, 234 insertions(+), 18 deletions(-) create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnDifferentWorkerTest.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnSameWorkerTest.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnDifferentWorkerTest.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnSameWorkerTest.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleActivityImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleWorkflowImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleActivityImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleWorkflowImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleActivityImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleWorkflowImpl.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleActivity.java create mode 100644 extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleWorkflow.java diff --git a/docs/modules/ROOT/pages/includes/quarkus-temporal.adoc b/docs/modules/ROOT/pages/includes/quarkus-temporal.adoc index e26c5c3..4c31ba3 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-temporal.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-temporal.adoc @@ -13,23 +13,6 @@ h|Default a|icon:lock[title=Fixed at build time] [[quarkus-temporal_quarkus-temporal-enable-mock]]`link:#quarkus-temporal_quarkus-temporal-enable-mock[quarkus.temporal.enable-mock]` -[.description] --- -enable mock for testing - -ifdef::add-copy-button-to-env-var[] -Environment variable: env_var_with_copy_button:+++QUARKUS_TEMPORAL_ENABLE_MOCK+++[] -endif::add-copy-button-to-env-var[] -ifndef::add-copy-button-to-env-var[] -Environment variable: `+++QUARKUS_TEMPORAL_ENABLE_MOCK+++` -endif::add-copy-button-to-env-var[] ---|boolean -|`false` - - -a|icon:lock[title=Fixed at build time] [[quarkus-temporal_quarkus-temporal-enable-mock]]`link:#quarkus-temporal_quarkus-temporal-enable-mock[quarkus.temporal.enable-mock]` - - [.description] -- enable mock for testing diff --git a/extension/deployment/src/main/java/io/quarkiverse/temporal/deployment/TemporalProcessor.java b/extension/deployment/src/main/java/io/quarkiverse/temporal/deployment/TemporalProcessor.java index 73f43a5..f7a47e1 100644 --- a/extension/deployment/src/main/java/io/quarkiverse/temporal/deployment/TemporalProcessor.java +++ b/extension/deployment/src/main/java/io/quarkiverse/temporal/deployment/TemporalProcessor.java @@ -147,7 +147,7 @@ void produceWorkers( } for (String worker : workers) { - producer.produce(new WorkerBuildItem(worker, workflowsByWorker.get(worker), activitiesByWorker.get(worker))); + producer.produce(new WorkerBuildItem(worker, workflowsByWorker.getOrDefault(worker, List.of()), activitiesByWorker.getOrDefault(worker, List.of()))); } } diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnDifferentWorkerTest.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnDifferentWorkerTest.java new file mode 100644 index 0000000..3a3eedc --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnDifferentWorkerTest.java @@ -0,0 +1,37 @@ +package io.quarkiverse.temporal.deployment; + +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleActivityImpl; +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.NamedSimpleActivityImpl; +import io.quarkiverse.temporal.deployment.discovery.NamedSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.SimpleActivity; +import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.QuarkusUnitTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; + +public class SameActivityDiscoveryOnDifferentWorkerTest { + + @RegisterExtension + static final QuarkusUnitTest unitTest = new QuarkusUnitTest() + .setForcedDependencies(List.of(Dependency.of("io.quarkiverse.temporal", "quarkus-temporal-test", "999-SNAPSHOT"))) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClass(SimpleActivity.class) + .addClass(DefaultSimpleActivityImpl.class) + .addClass(NamedSimpleActivityImpl.class) + .addAsResource( + new StringAsset("quarkus.temporal.enable-mock: true\n"), + "application.properties")); + + @Test + public void testSameActivityDiscoveryOnSameWorker() { + // should be called, this deployment is valid: + // it is legal to to have two different implementation of the same workflow on different workers + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnSameWorkerTest.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnSameWorkerTest.java new file mode 100644 index 0000000..e836095 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameActivityDiscoveryOnSameWorkerTest.java @@ -0,0 +1,44 @@ +package io.quarkiverse.temporal.deployment; + +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleActivityImpl; +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleActivityImpl; +import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.NamedSimpleActivityImpl; +import io.quarkiverse.temporal.deployment.discovery.SimpleActivity; +import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.QuarkusUnitTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; + +public class SameActivityDiscoveryOnSameWorkerTest { + + @RegisterExtension + static final QuarkusUnitTest unitTest = new QuarkusUnitTest() + .setForcedDependencies(List.of(Dependency.of("io.quarkiverse.temporal", "quarkus-temporal-test", "999-SNAPSHOT"))) + .assertException(ex -> { + Assertions.assertEquals(IllegalStateException.class, ex.getClass()); + Assertions.assertEquals("Activity io.quarkiverse.temporal.deployment.discovery.SimpleActivity has more than one implementor on worker", ex.getMessage()); + }) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClass(SimpleActivity.class) + .addClass(DefaultSimpleActivityImpl.class) + .addClass(DuplicateDefaultSimpleActivityImpl.class) + .addAsResource( + new StringAsset("quarkus.temporal.enable-mock: true\n"), + "application.properties")); + + @Test + public void testSameActivityDiscoveryOnSameWorker() { + // should not be called, deployment exception should happen first: + // it's illegal to have two workflow implementation on the same worker + Assertions.fail(); + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnDifferentWorkerTest.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnDifferentWorkerTest.java new file mode 100644 index 0000000..8e84022 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnDifferentWorkerTest.java @@ -0,0 +1,36 @@ +package io.quarkiverse.temporal.deployment; + +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.NamedSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.QuarkusUnitTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; + +public class SameWorkflowDiscoveryOnDifferentWorkerTest { + + @RegisterExtension + static final QuarkusUnitTest unitTest = new QuarkusUnitTest() + .setForcedDependencies(List.of(Dependency.of("io.quarkiverse.temporal", "quarkus-temporal-test", "999-SNAPSHOT"))) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClass(SimpleWorkflow.class) + .addClass(DefaultSimpleWorkflowImpl.class) + .addClass(NamedSimpleWorkflowImpl.class) + .addAsResource( + new StringAsset("quarkus.temporal.enable-mock: true\n"), + "application.properties")); + + @Test + public void testSameWorkflowDiscoveryOnSameWorker() { + // should be called, this deployment is valid: + // it is legal to to have two different implementation of the same workflow on different workers + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnSameWorkerTest.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnSameWorkerTest.java new file mode 100644 index 0000000..3bcc4c3 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/SameWorkflowDiscoveryOnSameWorkerTest.java @@ -0,0 +1,40 @@ +package io.quarkiverse.temporal.deployment; + +import io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleWorkflowImpl; +import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.test.QuarkusUnitTest; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; + +public class SameWorkflowDiscoveryOnSameWorkerTest { + + @RegisterExtension + static final QuarkusUnitTest unitTest = new QuarkusUnitTest() + .setForcedDependencies(List.of(Dependency.of("io.quarkiverse.temporal", "quarkus-temporal-test", "999-SNAPSHOT"))) + .assertException(ex -> { + Assertions.assertEquals(IllegalStateException.class, ex.getClass()); + Assertions.assertEquals("Workflow io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow has more than one implementor on worker", ex.getMessage()); + }) + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClass(SimpleWorkflow.class) + .addClass(DefaultSimpleWorkflowImpl.class) + .addClass(DuplicateDefaultSimpleWorkflowImpl.class) + .addAsResource( + new StringAsset("quarkus.temporal.enable-mock: true\n"), + "application.properties")); + + @Test + public void testSameWorkflowDiscoveryOnSameWorker() { + // should not be called, deployment exception should happen first: + // it's illegal to have two workflow implementation on the same worker + Assertions.fail(); + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleActivityImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleActivityImpl.java new file mode 100644 index 0000000..20eca62 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleActivityImpl.java @@ -0,0 +1,7 @@ +package io.quarkiverse.temporal.deployment.discovery; + +public class DefaultSimpleActivityImpl implements SimpleActivity { + @Override + public void withdraw() { + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleWorkflowImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleWorkflowImpl.java new file mode 100644 index 0000000..35d39fe --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DefaultSimpleWorkflowImpl.java @@ -0,0 +1,9 @@ +package io.quarkiverse.temporal.deployment.discovery; + +public class DefaultSimpleWorkflowImpl implements SimpleWorkflow { + + @Override + public void transfer() { + + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleActivityImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleActivityImpl.java new file mode 100644 index 0000000..1571e81 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleActivityImpl.java @@ -0,0 +1,7 @@ +package io.quarkiverse.temporal.deployment.discovery; + +public class DuplicateDefaultSimpleActivityImpl implements SimpleActivity { + @Override + public void withdraw() { + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleWorkflowImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleWorkflowImpl.java new file mode 100644 index 0000000..9590bbd --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/DuplicateDefaultSimpleWorkflowImpl.java @@ -0,0 +1,9 @@ +package io.quarkiverse.temporal.deployment.discovery; + +public class DuplicateDefaultSimpleWorkflowImpl implements SimpleWorkflow { + + @Override + public void transfer() { + + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleActivityImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleActivityImpl.java new file mode 100644 index 0000000..a0c004b --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleActivityImpl.java @@ -0,0 +1,10 @@ +package io.quarkiverse.temporal.deployment.discovery; + +import io.quarkiverse.temporal.ActivityImpl; + +@ActivityImpl(workers = "namedWorker") +public class NamedSimpleActivityImpl implements SimpleActivity { + @Override + public void withdraw() { + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleWorkflowImpl.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleWorkflowImpl.java new file mode 100644 index 0000000..3968a5b --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/NamedSimpleWorkflowImpl.java @@ -0,0 +1,12 @@ +package io.quarkiverse.temporal.deployment.discovery; + +import io.quarkiverse.temporal.WorkflowImpl; + +@WorkflowImpl(workers = "namedWorker") +public class NamedSimpleWorkflowImpl implements SimpleWorkflow { + + @Override + public void transfer() { + + } +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleActivity.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleActivity.java new file mode 100644 index 0000000..5502c81 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleActivity.java @@ -0,0 +1,11 @@ +package io.quarkiverse.temporal.deployment.discovery; + +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityMethod; + +@ActivityInterface +public interface SimpleActivity { + @ActivityMethod + void withdraw(); + +} diff --git a/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleWorkflow.java b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleWorkflow.java new file mode 100644 index 0000000..24f96f6 --- /dev/null +++ b/extension/deployment/src/test/java/io/quarkiverse/temporal/deployment/discovery/SimpleWorkflow.java @@ -0,0 +1,11 @@ +package io.quarkiverse.temporal.deployment.discovery; + +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; + +@WorkflowInterface +public interface SimpleWorkflow { + + @WorkflowMethod + void transfer(); +}