Skip to content

Commit

Permalink
workflow & activities discovery unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Loic Hermann authored and Loic Hermann committed Aug 12, 2024
1 parent dcc8bbf commit d5d9201
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 18 deletions.
17 changes: 0 additions & 17 deletions docs/modules/ROOT/pages/includes/quarkus-temporal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkiverse.temporal.deployment.discovery;

public class DefaultSimpleActivityImpl implements SimpleActivity {
@Override
public void withdraw() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkiverse.temporal.deployment.discovery;

public class DefaultSimpleWorkflowImpl implements SimpleWorkflow {

@Override
public void transfer() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkiverse.temporal.deployment.discovery;

public class DuplicateDefaultSimpleActivityImpl implements SimpleActivity {
@Override
public void withdraw() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkiverse.temporal.deployment.discovery;

public class DuplicateDefaultSimpleWorkflowImpl implements SimpleWorkflow {

@Override
public void transfer() {

}
}
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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() {

}
}
Original file line number Diff line number Diff line change
@@ -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();

}
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit d5d9201

Please sign in to comment.