hachikuji commented on a change in pull request #10240:
URL: https://github.com/apache/kafka/pull/10240#discussion_r588513624
##########
File path:
core/src/test/scala/unit/kafka/server/AutoTopicCreationManagerTest.scala
##########
@@ -146,29 +146,118 @@ class AutoTopicCreationManagerTest {
}
@Test
- def testNotEnoughLiveBrokers(): Unit = {
- val props = TestUtils.createBrokerConfig(1, "localhost")
- props.setProperty(KafkaConfig.DefaultReplicationFactorProp, 3.toString)
- config = KafkaConfig.fromProps(props)
+ def testInvalidReplicationFactorForNonInternalTopics(): Unit = {
+ testErrorWithCreationInZk(Errors.INVALID_REPLICATION_FACTOR, "topic",
isInternal = false)
+ }
+
+ @Test
+ def testInvalidReplicationFactorForConsumerOffsetsTopic(): Unit = {
+ Mockito.when(groupCoordinator.offsetsTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.INVALID_REPLICATION_FACTOR,
Topic.GROUP_METADATA_TOPIC_NAME, isInternal = true)
+ }
+
+ @Test
+ def testInvalidReplicationFactorForTxnOffsetTopic(): Unit = {
+
Mockito.when(transactionCoordinator.transactionTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.INVALID_REPLICATION_FACTOR,
Topic.TRANSACTION_STATE_TOPIC_NAME, isInternal = true)
+ }
+
+ @Test
+ def testTopicExistsErrorSwapForNonInternalTopics(): Unit = {
+ testErrorWithCreationInZk(Errors.TOPIC_ALREADY_EXISTS, "topic", isInternal
= false,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testTopicExistsErrorSwapForConsumerOffsetsTopic(): Unit = {
+ Mockito.when(groupCoordinator.offsetsTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.TOPIC_ALREADY_EXISTS,
Topic.GROUP_METADATA_TOPIC_NAME, isInternal = true,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testTopicExistsErrorSwapForTxnOffsetTopic(): Unit = {
+
Mockito.when(transactionCoordinator.transactionTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.TOPIC_ALREADY_EXISTS,
Topic.TRANSACTION_STATE_TOPIC_NAME, isInternal = true,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testRequestTimeoutErrorSwapForNonInternalTopics(): Unit = {
+ testErrorWithCreationInZk(Errors.REQUEST_TIMED_OUT, "topic", isInternal =
false,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testRequestTimeoutErrorSwapForConsumerOffsetTopic(): Unit = {
+ Mockito.when(groupCoordinator.offsetsTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.REQUEST_TIMED_OUT,
Topic.GROUP_METADATA_TOPIC_NAME, isInternal = true,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testRequestTimeoutErrorSwapForTxnOffsetTopic(): Unit = {
+
Mockito.when(transactionCoordinator.transactionTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.REQUEST_TIMED_OUT,
Topic.TRANSACTION_STATE_TOPIC_NAME, isInternal = true,
+ expectedError = Errors.LEADER_NOT_AVAILABLE)
+ }
+
+ @Test
+ def testUnknownTopicPartitionForNonIntervalTopic(): Unit = {
+ testErrorWithCreationInZk(Errors.UNKNOWN_TOPIC_OR_PARTITION, "topic",
isInternal = false)
+ }
+ @Test
+ def testUnknownTopicPartitionForConsumerOffsetTopic(): Unit = {
+ Mockito.when(groupCoordinator.offsetsTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.UNKNOWN_TOPIC_OR_PARTITION,
Topic.GROUP_METADATA_TOPIC_NAME, isInternal = true)
+ }
+
+ @Test
+ def testUnknownTopicPartitionForTxnOffsetTopic(): Unit = {
+
Mockito.when(transactionCoordinator.transactionTopicConfigs).thenReturn(new
Properties)
+ testErrorWithCreationInZk(Errors.UNKNOWN_TOPIC_OR_PARTITION,
Topic.TRANSACTION_STATE_TOPIC_NAME, isInternal = true)
+ }
+
+ private def testErrorWithCreationInZk(error: Errors,
+ topicName: String,
+ isInternal: Boolean,
+ expectedError: Errors = null): Unit = {
Review comment:
nit: a little more idiomatic to use `Option[Errors]` for a case like this
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]