Search in sources :

Example 1 with AllConnectorClientConfigOverridePolicy

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();
}
Also used : Arrays(java.util.Arrays) EasyMock.strictMock(org.easymock.EasyMock.strictMock) Plugins(org.apache.kafka.connect.runtime.isolation.Plugins) Transformation(org.apache.kafka.connect.transforms.Transformation) MockStrict(org.powermock.api.easymock.annotation.MockStrict) SourceConnector(org.apache.kafka.connect.source.SourceConnector) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) Map(java.util.Map) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) PowerMock.replayAll(org.powermock.api.easymock.PowerMock.replayAll) ConfigDef(org.apache.kafka.common.config.ConfigDef) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) Collection(java.util.Collection) ConnectRecord(org.apache.kafka.connect.connector.ConnectRecord) Set(java.util.Set) ConfigValue(org.apache.kafka.common.config.ConfigValue) PowerMock(org.powermock.api.easymock.PowerMock) Collectors(java.util.stream.Collectors) EasyMock.partialMockBuilder(org.easymock.EasyMock.partialMockBuilder) ConfigValueInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigValueInfo) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) List(java.util.List) Predicate(org.apache.kafka.connect.transforms.predicates.Predicate) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) ConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy) SourceTask(org.apache.kafka.connect.source.SourceTask) Connector(org.apache.kafka.connect.connector.Connector) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ConfigBackingStore(org.apache.kafka.connect.storage.ConfigBackingStore) Function(java.util.function.Function) NoneConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy) PluginDesc(org.apache.kafka.connect.runtime.isolation.PluginDesc) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMock.verifyAll(org.powermock.api.easymock.PowerMock.verifyAll) SaslConfigs(org.apache.kafka.common.config.SaslConfigs) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Capture(org.easymock.Capture) AbstractHerder.keysWithVariableValues(org.apache.kafka.connect.runtime.AbstractHerder.keysWithVariableValues) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClusterConfigState(org.apache.kafka.connect.runtime.distributed.ClusterConfigState) ConfigTransformer(org.apache.kafka.common.config.ConfigTransformer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) ConfigException(org.apache.kafka.common.config.ConfigException) StatusBackingStore(org.apache.kafka.connect.storage.StatusBackingStore) OAuthBearerUnsecuredLoginCallbackHandler(org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredLoginCallbackHandler) Assert.assertNull(org.junit.Assert.assertNull) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) OAuthBearerUnsecuredLoginCallbackHandler(org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredLoginCallbackHandler) ConfigInfo(org.apache.kafka.connect.runtime.rest.entities.ConfigInfo) AllConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.AllConnectorClientConfigOverridePolicy) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ConfigInfos(org.apache.kafka.connect.runtime.rest.entities.ConfigInfos) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CommonClientConfigs (org.apache.kafka.clients.CommonClientConfigs)1 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)1 ConfigDef (org.apache.kafka.common.config.ConfigDef)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 ConfigTransformer (org.apache.kafka.common.config.ConfigTransformer)1 ConfigValue (org.apache.kafka.common.config.ConfigValue)1 SaslConfigs (org.apache.kafka.common.config.SaslConfigs)1 OAuthBearerUnsecuredLoginCallbackHandler (org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredLoginCallbackHandler)1