Skip to content

Commit

Permalink
[MO] - replace EmbeddedKafkaCluster with Strimzi test container (2/x)…
Browse files Browse the repository at this point in the history
… - user module

Signed-off-by: morsak <xorsak02@stud.fit.vutbr.cz>
  • Loading branch information
morsak committed Feb 9, 2022
1 parent b78490b commit 49989aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 50 deletions.
20 changes: 2 additions & 18 deletions topic-operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,10 @@
<groupId>io.strimzi</groupId>
<artifactId>test</artifactId>
</dependency>
<!-- Used by EmbeddedKafkaCluster -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<classifier>test</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<classifier>test</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<classifier>test</classifier>
<scope>test</scope>
<groupId>io.strimzi</groupId>
<artifactId>strimzi-test-container</artifactId>
</dependency>
<!-- ^^^^^ Used by EmbeddedKafkaCluster -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
19 changes: 2 additions & 17 deletions user-operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<!-- Used by EmbeddedKafkaCluster -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<classifier>test</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<classifier>test</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
<classifier>test</classifier>
<groupId>io.strimzi</groupId>
<artifactId>strimzi-test-container</artifactId>
<scope>test</scope>
</dependency>
<!-- ^^^^^ Used by EmbeddedKafkaCluster -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.13</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.user.model.KafkaUserModel;
import io.strimzi.test.container.StrimziKafkaContainer;
import io.vertx.core.Vertx;
import io.vertx.junit5.Checkpoint;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hamcrest.Matchers;
Expand All @@ -21,8 +21,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -36,26 +37,23 @@ public abstract class AbstractAdminApiOperatorIT<T, S extends Collection<String>
public static final String SCRAM_USERNAME = "my-user";
public static final String TLS_USERNAME = "CN=my-user";

private static EmbeddedKafkaCluster kafkaCluster;
private static StrimziKafkaContainer kafkaContainer;
protected static Vertx vertx;
protected static Admin adminClient;

@BeforeAll
public static void beforeAll() {
vertx = Vertx.vertx();
try {
Properties config = new Properties();
config.setProperty("authorizer.class.name", "kafka.security.authorizer.AclAuthorizer");
config.setProperty("super.users", "User:ANONYMOUS");

kafkaCluster = new EmbeddedKafkaCluster(1, config);
kafkaCluster.start();
} catch (IOException e) {
throw new RuntimeException("Failed to start Kafka cluster");
}
Map<String, String> additionalConfiguration = Map.of(
"authorizer.class.name", "kafka.security.authorizer.AclAuthorizer",
"super.users", "User:ANONYMOUS");
kafkaContainer = new StrimziKafkaContainer()
.withBrokerId(1)
.withKafkaConfigurationMap(additionalConfiguration);
kafkaContainer.start();

Properties p = new Properties();
p.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCluster.bootstrapServers());
p.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers());
adminClient = Admin.create(p);
}

Expand All @@ -69,7 +67,7 @@ public static void afterAll() {
adminClient.close();
}

kafkaCluster.stop();
kafkaContainer.stop();
}

abstract AbstractAdminApiOperator<T, S> operator();
Expand Down

0 comments on commit 49989aa

Please sign in to comment.