You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by jg...@apache.org on 2022/10/29 01:50:16 UTC
[kafka] branch trunk updated: MINOR: Add test case for topic recreation with collision chars (#12796)
This is an automated email from the ASF dual-hosted git repository.
jgus pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new cbe50d95a98 MINOR: Add test case for topic recreation with collision chars (#12796)
cbe50d95a98 is described below
commit cbe50d95a980529c84698d0d2be476ff178c2c29
Author: Jason Gustafson <ja...@confluent.io>
AuthorDate: Fri Oct 28 18:50:08 2022 -0700
MINOR: Add test case for topic recreation with collision chars (#12796)
This patch adds a unit test for topic recreation with colliding characters (such as `.`). This was broken up until https://github.com/apache/kafka/pull/12790.
Reviewers: José Armando García Sancio <js...@users.noreply.github.com>
---
.../controller/ReplicationControlManager.java | 4 +++
.../controller/ReplicationControlManagerTest.java | 31 ++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java b/metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java
index 8c3e2880334..6683d5e1476 100644
--- a/metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java
+++ b/metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java
@@ -263,6 +263,10 @@ public class ReplicationControlManager {
public Uuid topicId() {
return id;
}
+
+ public int numPartitions(long epoch) {
+ return parts.size(epoch);
+ }
}
/**
diff --git a/metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerTest.java b/metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerTest.java
index ff67e0e6d66..c81f25e4c00 100644
--- a/metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerTest.java
+++ b/metadata/src/test/java/org/apache/kafka/controller/ReplicationControlManagerTest.java
@@ -60,6 +60,7 @@ import org.apache.kafka.common.metadata.ConfigRecord;
import org.apache.kafka.common.metadata.PartitionChangeRecord;
import org.apache.kafka.common.metadata.PartitionRecord;
import org.apache.kafka.common.metadata.RegisterBrokerRecord;
+import org.apache.kafka.common.metadata.RemoveTopicRecord;
import org.apache.kafka.common.metadata.TopicRecord;
import org.apache.kafka.common.protocol.ApiKeys;
import org.apache.kafka.common.protocol.Errors;
@@ -269,6 +270,21 @@ public class ReplicationControlManagerTest {
return topicResult;
}
+ void deleteTopic(Uuid topicId) throws Exception {
+ ControllerResult<Map<Uuid, ApiError>> result = replicationControl.deleteTopics(Collections.singleton(topicId));
+ assertEquals(Collections.singleton(topicId), result.response().keySet());
+ assertEquals(NONE, result.response().get(topicId).error());
+ assertEquals(1, result.records().size());
+
+ ApiMessageAndVersion removeRecordAndVersion = result.records().get(0);
+ assertTrue(removeRecordAndVersion.message() instanceof RemoveTopicRecord);
+
+ RemoveTopicRecord removeRecord = (RemoveTopicRecord) removeRecordAndVersion.message();
+ assertEquals(topicId, removeRecord.topicId());
+
+ replay(result.records());
+ }
+
void createPartitions(int count, String name,
int[][] replicas, short expectedErrorCode) throws Exception {
assertFalse(replicas.length == 0);
@@ -698,6 +714,21 @@ public class ReplicationControlManagerTest {
ctx.createTestTopic("quux", new int[][] {new int[] {1, 2, 0}}, POLICY_VIOLATION.code());
}
+ @Test
+ public void testCreateTopicWithCollisionChars() throws Exception {
+ ReplicationControlTestContext ctx = new ReplicationControlTestContext(Optional.empty());
+ ctx.registerBrokers(0, 1, 2);
+ ctx.unfenceBrokers(0, 1, 2);
+
+ CreatableTopicResult initialTopic = ctx.createTestTopic("foo.bar", 2, (short) 2, NONE.code());
+ assertEquals(2, ctx.replicationControl.getTopic(initialTopic.topicId()).numPartitions(Long.MAX_VALUE));
+ ctx.deleteTopic(initialTopic.topicId());
+
+ CreatableTopicResult recreatedTopic = ctx.createTestTopic("foo.bar", 4, (short) 2, NONE.code());
+ assertNotEquals(initialTopic.topicId(), recreatedTopic.topicId());
+ assertEquals(4, ctx.replicationControl.getTopic(recreatedTopic.topicId()).numPartitions(Long.MAX_VALUE));
+ }
+
@Test
public void testGlobalTopicAndPartitionMetrics() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();