diff --git a/README.md b/README.md index 13dc6bb8..25598c2d 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,8 @@ public class MyFeatureTest { // given final ZeebeClient client = ZeebeClient.newClientBuilder() - .gatewayAddress(zeebeContainer.getExternalGatewayAddress()) + .grpcAddress(zeebeContainer.getGrpcAddress()) + .restAddress(zeebeContainer.getRestAddress()) .usePlaintext() .build(); final BpmnModelInstance process = @@ -249,7 +250,8 @@ public class MyFeatureTest { // given final ZeebeClient client = ZeebeClient.newClientBuilder() - .gatewayAddress(zeebeContainer.getExternalGatewayAddress()) + .grpcAddress(zeebeContainer.getGrpcAddress()) + .restAddress(zeebeContainer.getRestAddress()) .usePlaintext() .build(); final BpmnModelInstance process = @@ -309,7 +311,7 @@ The container is considered started if and only if: > A topology is considered complete if there is a leader for all partitions. Once started, the container is ready to accept commands, and a client can connect to it by setting -its `gatewayAddress` to `ZeebeContainer#getExternalGatewayAddress()`. +its `grpcAddress` to `ZeebeContainer#getGrpcAddress()`, and its `restAddress` to `ZeebeContainer#getRestAddress()`. ## Standalone broker without gateway @@ -348,7 +350,7 @@ The container is considered started if and only if: > A topology is considered complete if there is a leader for all partitions. Once started, the container is ready to accept commands, and a client can connect to it by setting -its `gatewayAddress` to `ZeebeContainer#getExternalGatewayAddress()`. +its `grpcAddress` to `ZeebeContainer#getGrpcAddress()`, and its `restAddress` to `ZeebeContainer#getRestAddress()`. ## Configuring your container diff --git a/core/src/main/java/io/zeebe/containers/ZeebeContainer.java b/core/src/main/java/io/zeebe/containers/ZeebeContainer.java index 6b5f59f6..669c6131 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeContainer.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeContainer.java @@ -99,7 +99,8 @@ private void applyDefaultConfiguration() { .withEnv("ZEEBE_BROKER_NETWORK_HOST", "0.0.0.0") .withEnv("ZEEBE_BROKER_NETWORK_ADVERTISEDHOST", getInternalHost()) .addExposedPorts( - ZeebePort.GATEWAY.getPort(), + ZeebePort.GATEWAY_REST.getPort(), + ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.COMMAND.getPort(), ZeebePort.INTERNAL.getPort(), ZeebePort.MONITORING.getPort()); diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java index a6046dc0..1ac0583c 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java @@ -56,13 +56,14 @@ * *
{@code
  * ZeebeClient.newClientBuilder()
- *   .brokerContainerPoint(container.getExternalGatewayAddress())
+ *   .grpcAddress(container.getGrpcAddress())
+ *   .restAddress(container.getRestAddress())
  *   .usePlaintext()
  *   .build();
  * }
* *

Note that if your client is also a container within the same network, you can and should use - * the {@link #getInternalGatewayAddress()}. + * the {@link #getInternalGrpcAddress()} and {@link #getInternalRestAddress()} variants. */ @API(status = Status.STABLE) @SuppressWarnings({"WeakerAccess", "UnusedReturnValue"}) @@ -115,7 +116,8 @@ private void applyDefaultConfiguration() { .withEnv("ZEEBE_STANDALONE_GATEWAY", "true") .withStartupTimeout(DEFAULT_STARTUP_TIMEOUT) .addExposedPorts( - ZeebePort.GATEWAY.getPort(), + ZeebePort.GATEWAY_REST.getPort(), + ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.INTERNAL.getPort(), ZeebePort.MONITORING.getPort()); } diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java index 3dfa8ebb..ee7b2348 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java @@ -15,6 +15,7 @@ */ package io.zeebe.containers; +import java.net.URI; import org.apiguardian.api.API; import org.apiguardian.api.API.Status; import org.testcontainers.containers.GenericContainer; @@ -23,11 +24,10 @@ * Represents common properties of nodes which can act as a gateway for a Zeebe cluster, e.g. {@link * ZeebeContainer} or {@link ZeebeGatewayContainer}. * - *

You can use {@link #getExternalGatewayAddress()} for clients which are not part of the gateway - * container's network; this is most likely what you want to use, so when in doubt use this. - * - *

You can use {@link #getInternalGatewayAddress()} for clients which are within the gateway - * container's network. + *

You should typically use {@link #getGrpcAddress()} and {@link #getRestAddress()} to wire your + * clients with this gateway. If your client happens to be running in the same network as the Docker + * container, then you may want to use {@link #getInternalGrpcAddress()} or {@link + * #getInternalRestAddress()} instead. * * @param the concrete type of the underlying container */ @@ -73,13 +73,16 @@ public interface ZeebeGatewayNode & ZeebeGatewayNo * *

@{code
    *   ZeebeClient.newClientBuilder()
-   *     .withBrokerContactPoint(container.getExternalGatewayAddress())
+   *     .gatewayAddress(container.getExternalGatewayAddress())
    *     .usePlaintext()
    *     .build();
    * }
* * @return the gateway address visible from outside the docker network + * @deprecated Use the protocol specific variants from now on, {@link #getGrpcAddress()} or {@link + * #getRestAddress()} */ + @Deprecated default String getExternalGatewayAddress() { return getExternalAddress(ZeebePort.GATEWAY.getPort()); } @@ -91,14 +94,185 @@ default String getExternalGatewayAddress() { * *
@{code
    *   ZeebeClient.newClientBuilder()
-   *     .withBrokerContactPoint(container.getInternalGatewayAddress())
+   *     .gatewayAddress(container.getInternalGatewayAddress())
    *     .usePlaintext()
    *     .build();
    * }
* * @return the gateway address visible from within the docker network + * @deprecated Use the protocol specific variants from now on, {@link #getInternalGrpcAddress()} + * or {@link #getInternalRestAddress()} */ + @Deprecated default String getInternalGatewayAddress() { return getInternalAddress(ZeebePort.GATEWAY.getPort()); } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getInternalRestUrl())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return internally accessible REST API address + */ + default URI getInternalRestAddress() { + return getInternalRestAddress("http"); + } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

Use this variant if you need to specify a different scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getInternalRestUrl("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return internally accessible REST API address + */ + default URI getInternalRestAddress(final String scheme) { + final int port = ZeebePort.GATEWAY_REST.getPort(); + return URI.create(String.format("%s://%s:%d", scheme, getInternalHost(), port)); + } + + /** + * Returns the address of the REST API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use * + * {@link #getInternalRestAddress()} + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getRestAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return externally accessible REST API address + */ + default URI getRestAddress() { + return getRestAddress("http"); + } + + /** + * Returns the address of the REST API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalRestAddress(String)}. + * + *

Use this method if you need to specify a different connection scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getExternalRestAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return externally accessible REST API address + */ + default URI getRestAddress(final String scheme) { + final int port = getMappedPort(ZeebePort.GATEWAY_REST.getPort()); + return URI.create(String.format("%s://%s:%d", scheme, getExternalHost(), port)); + } + + /** + * Returns an address accessible from within the container's network for the gRPC API. Primarily + * meant to be used by clients. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getInternalGrpcAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return internally accessible REST API address + */ + default URI getInternalGrpcAddress() { + return getInternalGrpcAddress("http"); + } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

Use this variant if you need to specify a different scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getInternalGrpcAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return internally accessible REST API address + */ + default URI getInternalGrpcAddress(final String scheme) { + final int port = ZeebePort.GATEWAY_REST.getPort(); + return URI.create(String.format("%s://%s:%d", scheme, getInternalHost(), port)); + } + + /** + * Returns the address of the gRPC API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalGrpcAddress()}. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getGrpcAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return externally accessible gRPC API address + */ + default URI getGrpcAddress() { + return getGrpcAddress("http"); + } + + /** + * Returns the address of the gRPC API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalGrpcAddress(String)}. + * + *

Use this method if you need to specify a different connection scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getGrpcAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return externally accessible gRPC API address + */ + default URI getGrpcAddress(final String scheme) { + final int port = getMappedPort(ZeebePort.GATEWAY_GRPC.getPort()); + return URI.create(String.format("%s://%s:%d", scheme, getExternalHost(), port)); + } } diff --git a/core/src/main/java/io/zeebe/containers/ZeebePort.java b/core/src/main/java/io/zeebe/containers/ZeebePort.java index 0ffbf978..fca65066 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebePort.java +++ b/core/src/main/java/io/zeebe/containers/ZeebePort.java @@ -23,12 +23,24 @@ public enum ZeebePort { /** Port of the command API, i.e. the port used by the gateway to communicate with the broker */ COMMAND(26501), - /** Port of the gateway API, i.e. the port used by the client to communicate with any gateway */ + /** + * Deprecated reference to the old GATEWAY port, which is the gRPC port; use {@link #GATEWAY_REST} + * or {@link #GATEWAY_GRPC} in the future + */ + @Deprecated GATEWAY(26500), /** Port for internal communication, i.e. what all nodes use to communicate for clustering */ INTERNAL(26502), /** Port for the management server, i.e. actuators, metrics, etc. */ - MONITORING(9600); + MONITORING(9600), + /** + * Port of the gateway REST API, i.e. the port used by the client to communicate with any gateway + */ + GATEWAY_REST(8080), + /** + * Port of the gateway gRPC API, i.e. the port used by the client to communicate with any gateway + */ + GATEWAY_GRPC(26500); private final int port; diff --git a/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java b/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java index ec5903e8..ff80e4d9 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java @@ -103,7 +103,7 @@ public ZeebeTopologyWaitStrategy(final int brokersCount, final int replicationFa */ public ZeebeTopologyWaitStrategy( final int brokersCount, final int replicationFactor, final int partitionsCount) { - this(brokersCount, replicationFactor, partitionsCount, ZeebePort.GATEWAY.getPort()); + this(brokersCount, replicationFactor, partitionsCount, ZeebePort.GATEWAY_GRPC.getPort()); } /** diff --git a/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java b/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java index b914d81a..e821a92a 100644 --- a/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java +++ b/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java @@ -234,7 +234,8 @@ public ZeebeClientBuilder newClientBuilder() { final ZeebeGatewayNode gateway = getAvailableGateway(); return ZeebeClient.newClientBuilder() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .usePlaintext(); } diff --git a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java index 5e1b5743..8bebc88e 100644 --- a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java @@ -134,10 +134,12 @@ void shouldExposeAllPortsButGateway( // given final List expectedPorts = Arrays.stream(ZeebePort.values()).map(ZeebePort::getPort).collect(Collectors.toList()); + final List gatewayPorts = + Arrays.asList(ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.GATEWAY_REST.getPort()); + expectedPorts.removeAll(gatewayPorts); // when final List exposedPorts = node.getExposedPorts(); - expectedPorts.remove((Integer) ZeebePort.GATEWAY.getPort()); // then assertThat(exposedPorts) diff --git a/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java b/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java index 251664c8..40eb4107 100644 --- a/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java +++ b/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java @@ -82,7 +82,11 @@ void shouldStartClusterWithEmbeddedGateways() { for (final ZeebeGatewayNode gateway : cluster.getGateways().values()) { final Topology topology; try (final ZeebeClient client = - cluster.newClientBuilder().gatewayAddress(gateway.getExternalGatewayAddress()).build()) { + cluster + .newClientBuilder() + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) + .build()) { topology = client.newTopologyRequest().send().join(); } @@ -154,7 +158,8 @@ void shouldStartClusterWithMixedGateways() { try (final ZeebeClient client = ZeebeClient.newClientBuilder() .usePlaintext() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .build()) { final Topology topology = client.newTopologyRequest().send().join(); assertThat(topology.getPartitionsCount()) diff --git a/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java index 27c51c95..21a67b59 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java @@ -116,7 +116,8 @@ private ZeebeContainer getConfiguredClusterBroker( private ZeebeClient newZeebeClient(final ZeebeContainer node) { return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) + .grpcAddress(node.getGrpcAddress()) + .restAddress(node.getRestAddress()) .usePlaintext() .build(); } diff --git a/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java index b27cc16d..ec7dce00 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java @@ -123,7 +123,8 @@ private ZeebeBrokerContainer getConfiguredClusterBroker( private ZeebeClient newZeebeClient(final ZeebeGatewayContainer node) { return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) + .grpcAddress(node.getGrpcAddress()) + .restAddress(node.getRestAddress()) .usePlaintext() .build(); } diff --git a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java index 7417abcb..361ee4a3 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java @@ -23,6 +23,7 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.ZeebeVolume; +import io.zeebe.containers.util.TestSupport; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.Test; @@ -56,7 +57,7 @@ void shouldReuseVolume() { Bpmn.createExecutableProcess("process").startEvent().endEvent().done(); // when - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); } @@ -67,7 +68,7 @@ void shouldReuseVolume() { // create a process instance from the one we previously deployed - this would fail if we hadn't // previously deployed our process model final ProcessInstanceEvent processInstance; - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { processInstance = client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join(); } @@ -77,11 +78,4 @@ void shouldReuseVolume() { .as("a process instance was successfully created") .isPositive(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java index bf84039c..68885170 100644 --- a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java @@ -22,6 +22,7 @@ import io.camunda.zeebe.model.bpmn.Bpmn; import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; +import io.zeebe.containers.util.TestSupport; import java.util.Map; import java.util.concurrent.TimeUnit; import org.assertj.core.api.Assertions; @@ -61,7 +62,7 @@ void shouldConnectToZeebe() { final ProcessInstanceResult workflowInstanceResult; // when - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { try (final JobWorker ignored = createJobWorker(variables, client)) { deploymentEvent = client @@ -99,11 +100,4 @@ private JobWorker createJobWorker( jobClient.newCompleteCommand(job.getKey()).variables(variables).send()) .open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java index a6c76a8b..e0748014 100644 --- a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java @@ -24,6 +24,7 @@ import io.zeebe.containers.ZeebeDefaults; import io.zeebe.containers.ZeebeVolume; import io.zeebe.containers.archive.ContainerArchive; +import io.zeebe.containers.util.TestSupport; import java.nio.file.Path; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.*; @@ -102,11 +103,7 @@ void shouldReuseData(final @TempDir Path tempDir) { } private void deployProcess(final ZeebeContainer container) { - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { client .newDeployResourceCommand() .addProcessModel( @@ -118,11 +115,7 @@ private void deployProcess(final ZeebeContainer container) { } private ProcessInstanceEvent createProcessInstance(final ZeebeContainer container) { - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { return client .newCreateInstanceCommand() .bpmnProcessId(PROCESS_ID) diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java index 11b58cf3..1b75cebf 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java @@ -23,6 +23,7 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.clock.ZeebeClock; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.time.Instant; import java.util.List; @@ -77,7 +78,7 @@ void shouldTriggerTimerStartEvent() { // when final JobHandler handler = (client, job) -> activatedJobs.add(job); - try (final ZeebeClient client = newZeebeClient(zeebeContainer); + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer); final JobWorker ignored = newJobWorker(handler, client)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join(); @@ -98,11 +99,4 @@ void shouldTriggerTimerStartEvent() { private JobWorker newJobWorker(final JobHandler handler, final ZeebeClient client) { return client.newWorker().jobType(JOB_TYPE).handler(handler).open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java index cea905fa..4e79b95b 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java @@ -23,6 +23,7 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.clock.ZeebeClock; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.time.Instant; import java.util.List; @@ -76,7 +77,7 @@ void shouldTriggerTimerStartEvent() { // when final JobHandler handler = (client, job) -> activatedJobs.add(job); - try (final ZeebeClient client = newZeebeClient(zeebeContainer); + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer); final JobWorker ignored = newJobWorker(handler, client)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); brokerTime = clock.addTime(TIME_OFFSET); @@ -96,11 +97,4 @@ void shouldTriggerTimerStartEvent() { private JobWorker newJobWorker(final JobHandler handler, final ZeebeClient client) { return client.newWorker().jobType(JOB_TYPE).handler(handler).open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java index 824e6883..a6b87c72 100644 --- a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java +++ b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java @@ -23,6 +23,7 @@ import io.camunda.zeebe.protocol.record.intent.MessageIntent; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.exporter.DebugReceiver; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -67,11 +68,7 @@ void afterEach() { @Test void shouldReadExportedRecords() { // given - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { // when client diff --git a/core/src/test/java/io/zeebe/containers/util/TestSupport.java b/core/src/test/java/io/zeebe/containers/util/TestSupport.java index 16c952fb..ed68a09f 100644 --- a/core/src/test/java/io/zeebe/containers/util/TestSupport.java +++ b/core/src/test/java/io/zeebe/containers/util/TestSupport.java @@ -60,7 +60,8 @@ public static String getUid() { public static ZeebeClient newZeebeClient(final ZeebeGatewayNode gateway) { return ZeebeClient.newClientBuilder() .usePlaintext() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .build(); } diff --git a/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java b/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java index ce216652..1eff04f8 100644 --- a/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java +++ b/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java @@ -20,6 +20,7 @@ import io.camunda.zeebe.client.ZeebeClientBuilder; import io.camunda.zeebe.client.impl.ZeebeObjectMapper; import io.camunda.zeebe.process.test.api.RecordStreamSource; +import io.zeebe.containers.ZeebeGatewayNode; import io.zeebe.containers.ZeebeNode; import io.zeebe.containers.clock.ZeebeClock; import io.zeebe.containers.cluster.ZeebeCluster; @@ -77,6 +78,7 @@ public ZeebeClient createClient(final ObjectMapper customObjectMapper) { return createClient(b -> b.withJsonMapper(new ZeebeObjectMapper(customObjectMapper))); } + @SuppressWarnings("deprecation") @Override public String getGatewayAddress() { return cluster.getAvailableGateway().getExternalGatewayAddress(); @@ -114,9 +116,13 @@ public void stop() { } private ZeebeClient createClient(final UnaryOperator configurator) { + final ZeebeGatewayNode gateway = cluster.getAvailableGateway(); final ZeebeClientBuilder builder = configurator.apply( - ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(getGatewayAddress())); + ZeebeClient.newClientBuilder() + .usePlaintext() + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress())); final ZeebeClient client = builder.build(); clients.add(client); diff --git a/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java b/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java index 3893fef8..517c50b5 100644 --- a/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java +++ b/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java @@ -75,6 +75,7 @@ public ZeebeClient createClient(final ObjectMapper objectMapper) { return createClient(b -> b.withJsonMapper(new ZeebeObjectMapper(objectMapper))); } + @SuppressWarnings("deprecation") @Override public String getGatewayAddress() { return container.getExternalGatewayAddress(); @@ -114,7 +115,10 @@ public void stop() { private ZeebeClient createClient(final UnaryOperator configurator) { final ZeebeClientBuilder builder = configurator.apply( - ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(getGatewayAddress())); + ZeebeClient.newClientBuilder() + .usePlaintext() + .grpcAddress(container.getGrpcAddress()) + .restAddress(container.getRestAddress())); final ZeebeClient client = builder.build(); clients.add(client); diff --git a/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java b/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java index 861a1e6a..2f82efe7 100644 --- a/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java +++ b/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java @@ -114,6 +114,7 @@ void shouldCreateClient() { .succeedsWithin(Duration.ofSeconds(1)); } + @SuppressWarnings("deprecation") @Test void shouldReturnGatewayAddress() { // given diff --git a/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java b/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java index d17dadb7..81c49923 100644 --- a/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java +++ b/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java @@ -97,6 +97,7 @@ void shouldCreateClient() { .succeedsWithin(Duration.ofSeconds(1)); } + @SuppressWarnings("deprecation") @Test void shouldReturnGatewayAddress() { // given