-
Notifications
You must be signed in to change notification settings - Fork 28
/
ZeebeTestContainer.java
79 lines (64 loc) · 2.5 KB
/
ZeebeTestContainer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package io.zeebe.hazelcast.testcontainers;
import io.camunda.zeebe.client.ZeebeClient;
import io.zeebe.containers.ZeebeContainer;
import org.testcontainers.utility.DockerImageName;
import java.util.Map;
public class ZeebeTestContainer extends ZeebeContainer {
private HazelcastContainer hazelcastContainer;
protected ZeebeTestContainer(HazelcastContainer hazelcastContainer) {
super(DockerImageName.parse("ghcr.io/camunda-community-hub/zeebe-with-hazelcast-exporter"));
withExposedPorts(26500,9600,5701);
this.hazelcastContainer = hazelcastContainer;
}
public static ZeebeTestContainer withDefaultConfig() {
return new ZeebeTestContainer(null);
}
public static ZeebeTestContainer withDefaultConfig(String clusterName) {
ZeebeTestContainer container = withDefaultConfig();
container.withEnv("ZEEBE_HAZELCAST_CLUSTER_NAME", clusterName);
return container;
}
public static ZeebeTestContainer withJsonFormat() {
ZeebeTestContainer container = withDefaultConfig();
container.withEnv("ZEEBE_HAZELCAST_FORMAT", "json");
return container;
}
public static ZeebeTestContainer withHazelcastContainer() {
return new ZeebeTestContainer(new HazelcastContainer());
}
public static ZeebeTestContainer withHazelcastContainer(String clusterName) {
HazelcastContainer hazelcast = new HazelcastContainer();
hazelcast.withEnv("HZ_CLUSTERNAME", clusterName);
ZeebeTestContainer container = new ZeebeTestContainer(hazelcast);
container.withEnv("ZEEBE_HAZELCAST_CLUSTER_NAME", clusterName);
return container;
}
public ZeebeClient getClient() {
return ZeebeClient.newClientBuilder()
.gatewayAddress(getExternalGatewayAddress())
.usePlaintext()
.build();
}
public String getHazelcastAddress() {
return getExternalAddress(5701);
}
@Override
public void start() {
if (hazelcastContainer != null) {
hazelcastContainer.start();
withNetwork(hazelcastContainer.getNetwork());
withEnv("ZEEBE_HAZELCAST_REMOTE_ADDRESS", hazelcastContainer.getHazelcastServerAddress());
}
super.start();
}
@Override
public void stop() {
if (hazelcastContainer != null) {
hazelcastContainer.stop();
}
super.stop();
}
public HazelcastContainer getHazelcastContainer() {
return hazelcastContainer;
}
}