Skip to content

Commit

Permalink
refactor: use rest/grpc for the wait strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
npepinpe committed Dec 29, 2024
1 parent 72579c8 commit 8854c9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.camunda.zeebe.client.api.response.BrokerInfo;
import io.camunda.zeebe.client.api.response.PartitionInfo;
import io.camunda.zeebe.client.api.response.Topology;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -233,11 +234,20 @@ protected void waitUntilReady() {
}

private ZeebeClient newZeebeClient(final WaitStrategyTarget waitStrategyTarget) {
final String gatewayHost = waitStrategyTarget.getHost();
final int exposedGatewayPort = waitStrategyTarget.getMappedPort(gatewayPort);
//noinspection HttpUrlsUsage
final URI gatewayAddress =
URI.create(
"http://"
+ waitStrategyTarget.getHost()
+ ":"
+ waitStrategyTarget.getMappedPort(gatewayPort));

// use the same URI for the REST and gRPC address, and rely on the user to correctly set the
// port they wish to use
return clientBuilderProvider
.get()
.gatewayAddress(gatewayHost + ":" + exposedGatewayPort)
.restAddress(gatewayAddress)
.grpcAddress(gatewayAddress)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition;
import io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerRole;
import io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse;
import java.net.URI;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -70,7 +71,8 @@ final class ZeebeTopologyWaitStrategyTest {

@BeforeEach
void setup() {
Mockito.when(builder.gatewayAddress(Mockito.anyString())).thenReturn(builder);
Mockito.when(builder.grpcAddress(Mockito.any())).thenReturn(builder);
Mockito.when(builder.restAddress(Mockito.any())).thenReturn(builder);
Mockito.when(builder.build()).thenReturn(client);
Mockito.when(client.newTopologyRequest()).thenReturn(topologyRequest);
}
Expand Down Expand Up @@ -132,8 +134,9 @@ void shouldUseCorrectGatewayAddress() {
strategy.waitUntilReady(target);

// then
Mockito.verify(builder, Mockito.timeout(5000).atLeastOnce())
.gatewayAddress(target.getHost() + ":" + target.mappedPort);
final URI expectedAddress = URI.create("http://" + target.getHost() + ":" + target.mappedPort);
Mockito.verify(builder, Mockito.timeout(5000).atLeastOnce()).grpcAddress(expectedAddress);
Mockito.verify(builder, Mockito.timeout(5000).atLeastOnce()).restAddress(expectedAddress);
}

@ParameterizedTest(name = "should timeout on incomplete topology when {0}")
Expand Down

0 comments on commit 8854c9d

Please sign in to comment.