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")));
}
}
}
Aggregations