chia7712 commented on code in PR #15714: URL: https://github.com/apache/kafka/pull/15714#discussion_r1570903125
########## storage/src/test/java/org/apache/kafka/storage/internals/checkpoint/PartitionMetadataFileTest.java: ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.storage.internals.checkpoint; + +import org.apache.kafka.common.Uuid; +import org.apache.kafka.common.errors.InconsistentTopicIdException; + +import org.apache.kafka.storage.internals.log.LogDirFailureChannel; +import org.apache.kafka.test.TestUtils; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class PartitionMetadataFileTest { + private final File dir = TestUtils.tempDirectory(); + private final File file = PartitionMetadataFile.newFile(dir); + + @Test + public void testSetRecordWithDifferentTopicId() { + PartitionMetadataFile partitionMetadataFile = new PartitionMetadataFile(file, null); + Uuid topicId = Uuid.randomUuid(); + partitionMetadataFile.record(topicId); + Uuid differentTopicId = Uuid.randomUuid(); + assertThrows(InconsistentTopicIdException.class, () -> partitionMetadataFile.record(differentTopicId)); + } + + @Test + public void testSetRecordWithSameTopicId() { + PartitionMetadataFile partitionMetadataFile = new PartitionMetadataFile(file, null); + Uuid topicId = Uuid.randomUuid(); + partitionMetadataFile.record(topicId); + assertDoesNotThrow(() -> partitionMetadataFile.record(topicId)); Review Comment: we need test to call record with UUID having different reference and same content. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org