Skip to content

Commit

Permalink
Merge pull request #356 from rekby-forks/add-kafka-to-testcontainers
Browse files Browse the repository at this point in the history
added kafkaport to ydb container start
  • Loading branch information
alex268 authored Jan 10, 2025
2 parents 407f054 + 09cd0c5 commit f6b9cbf
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
public class YdbDockerContainer extends GenericContainer<YdbDockerContainer> {
public static final int DEFAULT_SECURE_PORT = 2135;
public static final int DEFAULT_INSECURE_PORT = 2136;
public static final int DEFAULT_KAFKA_PORT = 9092;

private final YdbEnvironment env;
private final int grpcsPort; // Secure connection
private final int grpcPort; // Non secure connection
private final int kafkaPort; // Non secure kafka port

public YdbDockerContainer(YdbEnvironment env, PortsGenerator portGenerator) {
super(env.dockerImage());
Expand All @@ -33,20 +35,25 @@ public YdbDockerContainer(YdbEnvironment env, PortsGenerator portGenerator) {
if (env.useDockerIsolation()) {
this.grpcsPort = DEFAULT_SECURE_PORT;
this.grpcPort = DEFAULT_INSECURE_PORT;
this.kafkaPort = DEFAULT_KAFKA_PORT;
} else {
this.grpcsPort = portGenerator.findAvailablePort();
this.grpcPort = portGenerator.findAvailablePort();
this.kafkaPort = portGenerator.findAvailablePort();
}
}

public void init() {
addExposedPort(grpcPort);
addExposedPort(grpcsPort);
addExposedPort(kafkaPort);

withEnv("YDB_KAFKA_PROXY_PORT", String.valueOf(kafkaPort));
if (!env.useDockerIsolation()) {
// Host ports and container ports MUST BE equal - ydb implementation limitation
addFixedExposedPort(grpcsPort, grpcsPort);
addFixedExposedPort(grpcPort, grpcPort);
addFixedExposedPort(kafkaPort, kafkaPort);

withEnv("GRPC_PORT", String.valueOf(grpcPort));
withEnv("GRPC_TLS_PORT", String.valueOf(grpcsPort));
Expand Down Expand Up @@ -85,6 +92,10 @@ public EndpointRecord secureEndpoint() {
return new EndpointRecord(getHost(), getMappedPort(grpcsPort));
}

public String nonSecureKafkaEndpoint() {
return getHost() + ":" + getMappedPort(kafkaPort);
}

public byte[] pemCert() {
return copyFileFromContainer(env.dockerPemPath(), is -> {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down

0 comments on commit f6b9cbf

Please sign in to comment.