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

KAFKA-16627: Remove ClusterConfig parameter in BeforeEach and AfterEach #15824

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 4 additions & 21 deletions core/src/test/java/kafka/test/ClusterTestExtensionsTest.java
Expand Up @@ -26,9 +26,7 @@
import kafka.test.annotation.Type;
import kafka.test.junit.ClusterTestExtensions;
import org.apache.kafka.server.common.MetadataVersion;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.HashMap;
Expand All @@ -42,11 +40,9 @@
public class ClusterTestExtensionsTest {

private final ClusterInstance clusterInstance;
private final ClusterConfig config;

ClusterTestExtensionsTest(ClusterInstance clusterInstance, ClusterConfig config) { // Constructor injections
ClusterTestExtensionsTest(ClusterInstance clusterInstance) { // Constructor injections
this.clusterInstance = clusterInstance;
this.config = config;
}

// Static methods can generate cluster configurations
Expand All @@ -59,22 +55,9 @@ static void generate1(ClusterGenerator clusterGenerator) {
.build());
}

// BeforeEach run after class construction, but before cluster initialization and test invocation
@BeforeEach
public void beforeEach(ClusterConfig config) {
Assertions.assertSame(this.config, config, "Injected objects should be the same");
}

// AfterEach runs after test invocation and cluster teardown
@AfterEach
public void afterEach(ClusterConfig config) {
Assertions.assertSame(this.config, config, "Injected objects should be the same");
}

// With no params, configuration comes from the annotation defaults as well as @ClusterTestDefaults (if present)
@ClusterTest
public void testClusterTest(ClusterConfig config, ClusterInstance clusterInstance) {
Assertions.assertSame(this.config, config, "Injected objects should be the same");
public void testClusterTest(ClusterInstance clusterInstance) {
Assertions.assertSame(this.clusterInstance, clusterInstance, "Injected objects should be the same");
Assertions.assertEquals(ClusterInstance.ClusterType.ZK, clusterInstance.clusterType()); // From the class level default
Assertions.assertEquals("default.value", clusterInstance.config().serverProperties().get("default.key"));
Expand Down Expand Up @@ -129,7 +112,7 @@ public void testNoAutoStart() {
}

@ClusterTest
public void testDefaults(ClusterConfig config) {
Assertions.assertEquals(MetadataVersion.IBP_3_8_IV0, config.metadataVersion());
public void testDefaults(ClusterInstance clusterInstance) {
Assertions.assertEquals(MetadataVersion.IBP_3_8_IV0, clusterInstance.config().metadataVersion());
}
}
51 changes: 0 additions & 51 deletions core/src/test/java/kafka/test/junit/GenericParameterResolver.java

This file was deleted.

Expand Up @@ -118,8 +118,7 @@ public List<Extension> getAdditionalExtensions() {
}
},
(AfterTestExecutionCallback) context -> clusterInstance.stop(),
new ClusterInstanceParameterResolver(clusterInstance),
new GenericParameterResolver<>(clusterConfig, ClusterConfig.class)
new ClusterInstanceParameterResolver(clusterInstance)
);
}

Expand Down
Expand Up @@ -105,8 +105,7 @@ public List<Extension> getAdditionalExtensions() {
}
},
(AfterTestExecutionCallback) context -> clusterShim.stop(),
new ClusterInstanceParameterResolver(clusterShim),
new GenericParameterResolver<>(clusterConfig, ClusterConfig.class)
new ClusterInstanceParameterResolver(clusterShim)
);
}

Expand Down