Skip to content

Commit

Permalink
KAFKA-17171: Add test cases for STATIC_BROKER_CONFIGin kraft mode
Browse files Browse the repository at this point in the history
  • Loading branch information
frankvicky committed Jan 10, 2025
1 parent 8b72204 commit 875e338
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions core/src/test/java/kafka/admin/StaticBrokerConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 kafka.admin;


import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.Config;
import org.apache.kafka.clients.admin.ConfigEntry;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.config.TopicConfig;
import org.apache.kafka.common.test.api.ClusterConfigProperty;
import org.apache.kafka.common.test.api.ClusterInstance;
import org.apache.kafka.common.test.api.ClusterTest;
import org.apache.kafka.common.test.api.ClusterTestDefaults;
import org.apache.kafka.common.test.api.ClusterTestExtensions;
import org.apache.kafka.common.test.api.Type;
import org.apache.kafka.coordinator.group.GroupCoordinatorConfig;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.List;
import java.util.concurrent.ExecutionException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

@ExtendWith(value = ClusterTestExtensions.class)
@ClusterTestDefaults(types = {Type.KRAFT},
serverProperties = {
@ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_PARTITIONS_CONFIG, value = "1"),
@ClusterConfigProperty(key = GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "1"),
@ClusterConfigProperty(key = "log.segment.bytes", value = "12345")
})
public class StaticBrokerConfigTest {
private static final String TOPIC = "topic";

@ClusterTest
public void temp(ClusterInstance cluster) throws ExecutionException, InterruptedException {
try (Admin admin = cluster.admin()) {
CreateTopicsResult createResult = admin.createTopics(List.of(new NewTopic(TOPIC, 1, (short) 1)));
ConfigEntry config = createResult.config(TOPIC).get().get(TopicConfig.SEGMENT_BYTES_CONFIG);
assertNotNull(config, "Create Topic result should include static topic config");
assertEquals("12345", config.value());

ConfigResource resource = new ConfigResource(ConfigResource.Type.BROKER, "0");
Config configResourceConfigMap = admin.describeConfigs(List.of(resource)).all().get().get(resource);
assertNull(configResourceConfigMap.get(TopicConfig.SEGMENT_BYTES_CONFIG));
}
}
}

0 comments on commit 875e338

Please sign in to comment.