use of org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy in project kafka by apache.
the class AbstractHerderTest method testConfigValidationAllOverride.
@Test
public void testConfigValidationAllOverride() {
AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, new AllConnectorClientConfigOverridePolicy());
replayAll();
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
config.put(ConnectorConfig.NAME_CONFIG, "connector-name");
// connector required config
config.put("required", "value");
// Try to test a variety of configuration types: string, int, long, boolean, list, class
String protocolConfigKey = producerOverrideKey(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG);
config.put(protocolConfigKey, "SASL_PLAINTEXT");
String maxRequestSizeConfigKey = producerOverrideKey(ProducerConfig.MAX_REQUEST_SIZE_CONFIG);
config.put(maxRequestSizeConfigKey, "420");
String maxBlockConfigKey = producerOverrideKey(ProducerConfig.MAX_BLOCK_MS_CONFIG);
config.put(maxBlockConfigKey, "28980");
String idempotenceConfigKey = producerOverrideKey(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG);
config.put(idempotenceConfigKey, "true");
String bootstrapServersConfigKey = producerOverrideKey(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
config.put(bootstrapServersConfigKey, "SASL_PLAINTEXT://localhost:12345,SASL_PLAINTEXT://localhost:23456");
String loginCallbackHandlerConfigKey = producerOverrideKey(SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS);
config.put(loginCallbackHandlerConfigKey, OAuthBearerUnsecuredLoginCallbackHandler.class.getName());
final Set<String> overriddenClientConfigs = new HashSet<>();
overriddenClientConfigs.add(protocolConfigKey);
overriddenClientConfigs.add(maxRequestSizeConfigKey);
overriddenClientConfigs.add(maxBlockConfigKey);
overriddenClientConfigs.add(idempotenceConfigKey);
overriddenClientConfigs.add(bootstrapServersConfigKey);
overriddenClientConfigs.add(loginCallbackHandlerConfigKey);
ConfigInfos result = herder.validateConnectorConfig(config, false);
assertEquals(herder.connectorTypeForClass(config.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)), ConnectorType.SOURCE);
Map<String, String> validatedOverriddenClientConfigs = new HashMap<>();
for (ConfigInfo configInfo : result.values()) {
String configName = configInfo.configKey().name();
if (overriddenClientConfigs.contains(configName)) {
validatedOverriddenClientConfigs.put(configName, configInfo.configValue().value());
}
}
Map<String, String> rawOverriddenClientConfigs = config.entrySet().stream().filter(e -> overriddenClientConfigs.contains(e.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
assertEquals(rawOverriddenClientConfigs, validatedOverriddenClientConfigs);
verifyAll();
}
Aggregations