Skip to content

Commit

Permalink
add test and rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiJuWu committed Feb 2, 2025
1 parent 97476ad commit 0516650
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/src/test/java/kafka/server/KraftVoterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public void createController() throws Exception {
props.put("process.roles", "controller");
props.put(QuorumConfig.QUORUM_BOOTSTRAP_SERVERS_CONFIG, bootstrapControllers);
props.put(KRaftConfigs.CONTROLLER_LISTENER_NAMES_CONFIG, "CONTROLLER");
props.put("listeners", String.format("CONTROLLER://localhost:3999"));
props.put("advertised.listeners", String.format("PLAINTEXT://localhost:4000"));
props.put("listeners", "CONTROLLER://localhost:3999");
props.put("advertised.listeners", "PLAINTEXT://localhost:4000");
props.put("listener.security.protocol.map", "EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT");
System.err.println("KKK listeners " + props.get("listeners") + " advertised.listeners: " + props.get("advertised.listeners"));
System.err.println("KKK Bootstrap server " + bootstrapControllers);
cluster.createController(props, false);
cluster.createIsolatedController(props);
Collection<Integer> res = new ArrayList<>();
res.add(0);
res.add(3000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,12 @@ public void format() throws Exception {
}
}

public ControllerServer createController(Map<String, String> props, boolean isCombined) {
public ControllerServer createIsolatedController(Map<String, String> props) {
props.put(KRaftConfigs.SERVER_MAX_STARTUP_TIME_MS_CONFIG,
Long.toString(TimeUnit.MINUTES.toMillis(10)));
props.put(KRaftConfigs.PROCESS_ROLES_CONFIG, "controller");
KafkaConfig config = new KafkaConfig(props);

TestKitNode node = nodes.createControllerNode(config, isCombined);
TestKitNode node = nodes.createControllerNode(config, false);
MetaPropertiesEnsemble metaPropsEnsemble = node.initialMetaPropertiesEnsemble();
formatNode(metaPropsEnsemble, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.fail;

public class KafkaClusterTestKitTest {
Expand Down Expand Up @@ -153,4 +154,22 @@ public void testExposedFaultHandlers() {
fail("Failed to initialize cluster", e);
}
}

@Test
public void testCreateOutOfClusterController() throws Exception {
TestKitNodes nodes = new TestKitNodes.Builder()
.setNumBrokerNodes(1)
.setNumControllerNodes(1)
.build();
Map<String, String> props = new HashMap<>();
props.put("node.id", "2");
props.put("controller.quorum.bootstrap.servers", "localhost:9000");
props.put("controller.listener.names", "CONTROLLER");
props.put("listeners", "CONTROLLER://localhost:3999");
props.put("advertised.listeners", "PLAINTEXT://localhost:4000");
props.put("listener.security.protocol.map", "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT");
try (KafkaClusterTestKit cluster = new KafkaClusterTestKit.Builder(nodes).build()) {
assertDoesNotThrow(() -> cluster.createIsolatedController(props));
}
}
}

0 comments on commit 0516650

Please sign in to comment.