Search in sources :

Example 1 with PrincipalConnectorClientConfigOverridePolicy

use of org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy in project kafka by apache.

the class AbstractHerderTest method testConfigValidationPrincipalOnlyOverride.

@Test()
public void testConfigValidationPrincipalOnlyOverride() {
    AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, new PrincipalConnectorClientConfigOverridePolicy());
    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");
    String ackConfigKey = producerOverrideKey(ProducerConfig.ACKS_CONFIG);
    String saslConfigKey = producerOverrideKey(SaslConfigs.SASL_JAAS_CONFIG);
    config.put(ackConfigKey, "none");
    config.put(saslConfigKey, "jaas_config");
    ConfigInfos result = herder.validateConnectorConfig(config, false);
    assertEquals(herder.connectorTypeForClass(config.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)), ConnectorType.SOURCE);
    // We expect there to be errors due to now allowed override policy for ACKS.... Note that these assertions depend heavily on
    // the config fields for SourceConnectorConfig, but we expect these to change rarely.
    assertEquals(TestSourceConnector.class.getName(), result.name());
    // Each transform also gets its own group
    List<String> expectedGroups = Arrays.asList(ConnectorConfig.COMMON_GROUP, ConnectorConfig.TRANSFORMS_GROUP, ConnectorConfig.PREDICATES_GROUP, ConnectorConfig.ERROR_GROUP, SourceConnectorConfig.TOPIC_CREATION_GROUP);
    assertEquals(expectedGroups, result.groups());
    assertEquals(1, result.errorCount());
    // Base connector config has 14 fields, connector's configs add 2, and 2 producer overrides
    assertEquals(19, result.values().size());
    assertTrue(result.values().stream().anyMatch(configInfo -> ackConfigKey.equals(configInfo.configValue().name()) && !configInfo.configValue().errors().isEmpty()));
    assertTrue(result.values().stream().anyMatch(configInfo -> saslConfigKey.equals(configInfo.configValue().name()) && configInfo.configValue().errors().isEmpty()));
    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) PrincipalConnectorClientConfigOverridePolicy(org.apache.kafka.connect.connector.policy.PrincipalConnectorClientConfigOverridePolicy) 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