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

refactor: use rest/grpc for the wait strategy #814

Merged
merged 1 commit into from
Dec 29, 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 @@ -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
Loading