|
| 1 | +package io.temporal.worker; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import io.temporal.api.worker.v1.PluginInfo; |
| 6 | +import io.temporal.client.WorkflowClient; |
| 7 | +import io.temporal.client.WorkflowClientOptions; |
| 8 | +import io.temporal.common.SimplePlugin; |
| 9 | +import io.temporal.testing.CloudTestExclusion.RequiresLocalServer; |
| 10 | +import io.temporal.testing.CloudTestExclusionNote; |
| 11 | +import io.temporal.testing.TestWorkflowEnvironment; |
| 12 | +import java.util.Collections; |
| 13 | +import java.util.List; |
| 14 | +import java.util.stream.Collectors; |
| 15 | +import org.junit.Test; |
| 16 | +import org.junit.experimental.categories.Category; |
| 17 | + |
| 18 | +@CloudTestExclusionNote("This test directly creates and controls a local test service.") |
| 19 | +@Category(RequiresLocalServer.class) |
| 20 | +public class WorkerHeartbeatPluginsTest { |
| 21 | + |
| 22 | + @Test |
| 23 | + public void pluginRegisteredOnClientAndFactoryIsReportedOnce() { |
| 24 | + SimplePlugin plugin = SimplePlugin.newBuilder("test-plugin").build(); |
| 25 | + |
| 26 | + try (TestWorkflowEnvironment env = TestWorkflowEnvironment.newInstance()) { |
| 27 | + WorkflowClient client = |
| 28 | + WorkflowClient.newInstance( |
| 29 | + env.getWorkflowServiceStubs(), |
| 30 | + WorkflowClientOptions.newBuilder() |
| 31 | + .setNamespace(env.getNamespace()) |
| 32 | + .setPlugins(plugin) |
| 33 | + .build()); |
| 34 | + WorkerFactory factory = |
| 35 | + WorkerFactory.newInstance( |
| 36 | + client, WorkerFactoryOptions.newBuilder().setPlugins(plugin).build()); |
| 37 | + Worker worker = factory.newWorker("test-queue"); |
| 38 | + factory.start(); |
| 39 | + |
| 40 | + List<String> reportedPlugins = |
| 41 | + worker.buildHeartbeatCallback("test-worker-group", null).get().getPluginsList().stream() |
| 42 | + .map(PluginInfo::getName) |
| 43 | + .collect(Collectors.toList()); |
| 44 | + assertEquals(Collections.singletonList("test-plugin"), reportedPlugins); |
| 45 | + |
| 46 | + factory.shutdownNow(); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments