Search in sources :

Example 1 with ConfigResourceExistenceChecker

use of org.apache.kafka.controller.QuorumController.ConfigResourceExistenceChecker in project kafka by apache.

the class QuorumControllerTest method testConfigResourceExistenceChecker.

@Test
public void testConfigResourceExistenceChecker() throws Throwable {
    try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(3, Optional.empty())) {
        try (QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, b -> b.setConfigDefs(CONFIGS))) {
            QuorumController active = controlEnv.activeController();
            registerBrokers(active, 5);
            active.createTopics(new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName("foo").setReplicationFactor((short) 3).setNumPartitions(1)).iterator()))).get();
            ConfigResourceExistenceChecker checker = active.new ConfigResourceExistenceChecker();
            // A ConfigResource with type=BROKER and name=(empty string) represents
            // the default broker resource. It is used to set cluster configs.
            checker.accept(new ConfigResource(BROKER, ""));
            // Broker 3 exists, so we can set a configuration for it.
            checker.accept(new ConfigResource(BROKER, "3"));
            // Broker 10 does not exist, so this should throw an exception.
            assertThrows(BrokerIdNotRegisteredException.class, () -> checker.accept(new ConfigResource(BROKER, "10")));
            // Topic foo exists, so we can set a configuration for it.
            checker.accept(new ConfigResource(TOPIC, "foo"));
            // Topic bar does not exist, so this should throw an exception.
            assertThrows(UnknownTopicOrPartitionException.class, () -> checker.accept(new ConfigResource(TOPIC, "bar")));
        }
    }
}
Also used : CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) LocalLogManagerTestEnv(org.apache.kafka.metalog.LocalLogManagerTestEnv) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) ConfigResource(org.apache.kafka.common.config.ConfigResource) ConfigResourceExistenceChecker(org.apache.kafka.controller.QuorumController.ConfigResourceExistenceChecker) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigResource (org.apache.kafka.common.config.ConfigResource)1 CreateTopicsRequestData (org.apache.kafka.common.message.CreateTopicsRequestData)1 CreatableTopic (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic)1 CreatableTopicCollection (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection)1 ConfigResourceExistenceChecker (org.apache.kafka.controller.QuorumController.ConfigResourceExistenceChecker)1 LocalLogManagerTestEnv (org.apache.kafka.metalog.LocalLogManagerTestEnv)1 Test (org.junit.jupiter.api.Test)1