Skip to content
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

workflow & activities discovery unit test #28

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ 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,31 @@
package io.quarkiverse.temporal.deployment;

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 io.quarkiverse.temporal.deployment.discovery.DefaultSimpleActivityImpl;
import io.quarkiverse.temporal.deployment.discovery.NamedSimpleActivityImpl;
import io.quarkiverse.temporal.deployment.discovery.SimpleActivity;
import io.quarkus.test.QuarkusUnitTest;

public class SameActivityDiscoveryOnDifferentWorkerTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClass(SimpleActivity.class)
.addClass(DefaultSimpleActivityImpl.class)
.addClass(NamedSimpleActivityImpl.class)
.addAsResource(
new StringAsset("quarkus.temporal.start-workers: false\n"),
"application.properties"));

@Test
public void testSameActivityDiscoveryOnSameWorker() {
// should be called, this deployment is valid:
// it is legal to have two different implementations of a given activity on different workers
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkiverse.temporal.deployment;

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 io.quarkiverse.temporal.deployment.discovery.DefaultSimpleActivityImpl;
import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleActivityImpl;
import io.quarkiverse.temporal.deployment.discovery.SimpleActivity;
import io.quarkus.test.QuarkusUnitTest;

public class SameActivityDiscoveryOnSameWorkerTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.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.start-workers: false\n"),
"application.properties"));

@Test
public void testSameActivityDiscoveryOnSameWorker() {
// should not be called, deployment exception should happen first:
// it's illegal to have two implementations of a given activity on the same worker
Assertions.fail();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkiverse.temporal.deployment;

import io.temporal.worker.WorkerFactory;
import jakarta.inject.Inject;
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 io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl;
import io.quarkiverse.temporal.deployment.discovery.NamedSimpleWorkflowImpl;
import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow;
import io.quarkus.test.QuarkusUnitTest;

public class SameWorkflowDiscoveryOnDifferentWorkerTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClass(SimpleWorkflow.class)
.addClass(DefaultSimpleWorkflowImpl.class)
.addClass(NamedSimpleWorkflowImpl.class)
.addAsResource(
new StringAsset("quarkus.temporal.start-workers: false\n"),
"application.properties"));

@Inject
WorkerFactory factory;

@Test
public void testSameWorkflowDiscoveryOnSameWorker() {
// should be called, this deployment is valid:
// it is legal to have two different implementations of a given workflow on different workers
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkiverse.temporal.deployment;

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 io.quarkiverse.temporal.deployment.discovery.DefaultSimpleWorkflowImpl;
import io.quarkiverse.temporal.deployment.discovery.DuplicateDefaultSimpleWorkflowImpl;
import io.quarkiverse.temporal.deployment.discovery.SimpleWorkflow;
import io.quarkus.test.QuarkusUnitTest;

public class SameWorkflowDiscoveryOnSameWorkerTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.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.start-workers: false\n"),
"application.properties"));

@Test
public void testSameWorkflowDiscoveryOnSameWorker() {
// should not be called, deployment exception should happen first:
// it's illegal to have two implementations of a given workflow 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();
}
Loading