use of org.apache.kafka.common.metadata.RemoveTopicRecord in project kafka by apache.
the class ReplicationControlManager method deleteTopic.
void deleteTopic(Uuid id, List<ApiMessageAndVersion> records) {
TopicControlInfo topic = topics.get(id);
if (topic == null) {
throw new UnknownTopicIdException(UNKNOWN_TOPIC_ID.message());
}
records.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(id), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
}
use of org.apache.kafka.common.metadata.RemoveTopicRecord in project kafka by apache.
the class MetadataNodeManagerTest method testTopicRecordAndRemoveTopicRecord.
@Test
public void testTopicRecordAndRemoveTopicRecord() {
// Add topic
TopicRecord topicRecord = new TopicRecord().setName("topicName").setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ"));
metadataNodeManager.handleMessage(topicRecord);
assertEquals("topicName", metadataNodeManager.getData().root().directory("topics", "topicName").file("name").contents());
assertEquals("GcaQDl2UTsCNs1p9s37XkQ", metadataNodeManager.getData().root().directory("topics", "topicName").file("id").contents());
assertEquals("topicName", metadataNodeManager.getData().root().directory("topicIds", "GcaQDl2UTsCNs1p9s37XkQ").file("name").contents());
assertEquals("GcaQDl2UTsCNs1p9s37XkQ", metadataNodeManager.getData().root().directory("topicIds", "GcaQDl2UTsCNs1p9s37XkQ").file("id").contents());
// Remove topic
RemoveTopicRecord removeTopicRecord = new RemoveTopicRecord().setTopicId(Uuid.fromString("GcaQDl2UTsCNs1p9s37XkQ"));
metadataNodeManager.handleMessage(removeTopicRecord);
assertFalse(metadataNodeManager.getData().root().directory("topicIds").children().containsKey("GcaQDl2UTsCNs1p9s37XkQ"));
assertFalse(metadataNodeManager.getData().root().directory("topics").children().containsKey("topicName"));
}
use of org.apache.kafka.common.metadata.RemoveTopicRecord in project kafka by apache.
the class TopicsImageTest method testDeleteAfterChanges.
@Test
public void testDeleteAfterChanges() {
int localId = 3;
Uuid zooId = Uuid.fromString("0hHJ3X5ZQ-CFfQ5xgpj90w");
List<TopicImage> topics = new ArrayList<>();
topics.add(newTopicImage("zoo", zooId, newPartition(new int[] { localId, 1, 2 })));
TopicsImage image = new TopicsImage(newTopicsByIdMap(topics), newTopicsByNameMap(topics));
List<ApiMessageAndVersion> topicRecords = new ArrayList<>();
// leader to follower
topicRecords.add(new ApiMessageAndVersion(new PartitionChangeRecord().setTopicId(zooId).setPartitionId(0).setLeader(1), PARTITION_CHANGE_RECORD.highestSupportedVersion()));
// remove zoo topic
topicRecords.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(zooId), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
TopicsDelta delta = new TopicsDelta(image);
RecordTestUtils.replayAll(delta, topicRecords);
LocalReplicaChanges changes = delta.localChanges(localId);
assertEquals(new HashSet<>(Arrays.asList(new TopicPartition("zoo", 0))), changes.deletes());
assertEquals(Collections.emptyMap(), changes.leaders());
assertEquals(Collections.emptyMap(), changes.followers());
}
Aggregations