Skip to content

Commit

Permalink
Try with embedded kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Oct 9, 2023
1 parent e4e19f5 commit 738dc1b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 54 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ libraries["wiremock"] = "com.github.tomakehurst:wiremock-standalone:3.0.1"
libraries["awaitility"] = "org.awaitility:awaitility:4.2.0"
libraries["splunk-otel-agent"] = 'com.splunk:splunk-otel-javaagent:1.28.0'
libraries["testcontainers-postgresql"] = 'org.testcontainers:postgresql:1.19.1'
libraries["embeddedkafka"] = 'io.github.embeddedkafka:embedded-kafka_3:3.6.0'
2 changes: 1 addition & 1 deletion swatch-producer-aws/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:kafka'
testImplementation 'org.testcontainers:postgresql'
testImplementation 'org.testcontainers:testcontainers'
testImplementation libraries["junit-jupiter"]
testImplementation libraries["wiremock"]
testImplementation project(':swatch-common-testcontainers')
testImplementation libraries["embeddedkafka"]
}

compileJava.dependsOn tasks.openApiGenerate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,28 @@
*/
package com.redhat.swatch.aws;

import io.github.embeddedkafka.EmbeddedK;
import io.github.embeddedkafka.EmbeddedKafka;
import io.github.embeddedkafka.EmbeddedKafkaConfig;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import java.util.Collections;
import java.util.Map;
import org.testcontainers.containers.CustomKafkaContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

public class KafkaResource implements QuarkusTestResourceLifecycleManager {

static KafkaContainer kafka =
new CustomKafkaContainer(
DockerImageName.parse("quay.io/cloudservices/cp-kafka:latest-ubi8")
.asCompatibleSubstituteFor("confluentinc/cp-kafka"))
// SMELL: Workaround for https://github.com/testcontainers/testcontainers-java/issues/7539
// This is because testcontainers randomly fails to start a container when using Podman
// socket.
.withStartupAttempts(3);
private EmbeddedK kafka;

@Override
public Map<String, String> start() {
kafka.start();
return Collections.singletonMap("kafka.bootstrap.servers", kafka.getBootstrapServers());
kafka = EmbeddedKafka.start(EmbeddedKafkaConfig.defaultConfig());
return Collections.singletonMap(
"kafka.bootstrap.servers", "PLAINTEXT://localhost:" + kafka.config().kafkaPort());
}

@Override
public void stop() {
kafka.stop();
if (kafka != null) {
kafka.stop(false);
}
}
}

This file was deleted.

0 comments on commit 738dc1b

Please sign in to comment.