use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class DistributedHerderTest method testCreateConnectorFailedCustomValidation.
@Test
public void testCreateConnectorFailedCustomValidation() throws Exception {
EasyMock.expect(member.memberId()).andStubReturn("leader");
expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
expectPostRebalanceCatchup(SNAPSHOT);
member.wakeup();
PowerMock.expectLastCall();
// config validation
ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
Connector connectorMock = PowerMock.createMock(Connector.class);
EasyMock.expect(connectorFactoryMock.newConnector(EasyMock.anyString())).andReturn(connectorMock);
ConfigDef configDef = new ConfigDef();
configDef.define("foo.bar", ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "foo.bar doc");
EasyMock.expect(connectorMock.config()).andReturn(configDef);
ConfigValue validatedValue = new ConfigValue("foo.bar");
validatedValue.addErrorMessage("Failed foo.bar validation");
EasyMock.expect(connectorMock.validate(CONN2_CONFIG)).andReturn(new Config(singletonList(validatedValue)));
// CONN2 creation should fail
Capture<Throwable> error = EasyMock.newCapture();
putConnectorCallback.onCompletion(EasyMock.capture(error), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
PowerMock.expectLastCall();
member.poll(EasyMock.anyInt());
PowerMock.expectLastCall();
// No immediate action besides this -- change will be picked up via the config log
PowerMock.replayAll();
herder.putConnectorConfig(CONN2, CONN2_CONFIG, false, putConnectorCallback);
herder.tick();
assertTrue(error.hasCaptured());
assertTrue(error.getValue() instanceof BadRequestException);
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class DistributedHerderTest method testCreateConnectorFailedBasicValidation.
@Test
public void testCreateConnectorFailedBasicValidation() throws Exception {
EasyMock.expect(member.memberId()).andStubReturn("leader");
expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
expectPostRebalanceCatchup(SNAPSHOT);
HashMap<String, String> config = new HashMap<>(CONN2_CONFIG);
config.remove(ConnectorConfig.NAME_CONFIG);
member.wakeup();
PowerMock.expectLastCall();
// config validation
ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
Connector connectorMock = PowerMock.createMock(Connector.class);
EasyMock.expect(connectorFactoryMock.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andReturn(new ConfigDef());
EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(Collections.<ConfigValue>emptyList()));
// CONN2 creation should fail
Capture<Throwable> error = EasyMock.newCapture();
putConnectorCallback.onCompletion(EasyMock.capture(error), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
PowerMock.expectLastCall();
member.poll(EasyMock.anyInt());
PowerMock.expectLastCall();
// No immediate action besides this -- change will be picked up via the config log
PowerMock.replayAll();
herder.putConnectorConfig(CONN2, config, false, putConnectorCallback);
herder.tick();
assertTrue(error.hasCaptured());
assertTrue(error.getValue() instanceof BadRequestException);
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class StandaloneHerderTest method testCreateConnectorFailedBasicValidation.
@Test
public void testCreateConnectorFailedBasicValidation() throws Exception {
connector = PowerMock.createMock(BogusSourceConnector.class);
Map<String, String> config = connectorConfig(SourceSink.SOURCE);
config.remove(ConnectorConfig.NAME_CONFIG);
ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
Connector connectorMock = PowerMock.createMock(Connector.class);
EasyMock.expect(connectorFactoryMock.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andStubReturn(new ConfigDef());
EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(Collections.<ConfigValue>emptyList()));
createCallback.onCompletion(EasyMock.<BadRequestException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
PowerMock.expectLastCall();
PowerMock.replayAll();
herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class ConnectorConfig method enrich.
/**
* Returns an enriched {@link ConfigDef} building upon the {@code ConfigDef}, using the current configuration specified in {@code props} as an input.
* <p>
* {@code requireFullConfig} specifies whether required config values that are missing should cause an exception to be thrown.
*/
public static ConfigDef enrich(ConfigDef baseConfigDef, Map<String, String> props, boolean requireFullConfig) {
final List<String> transformAliases = (List<String>) ConfigDef.parseType(TRANSFORMS_CONFIG, props.get(TRANSFORMS_CONFIG), Type.LIST);
if (transformAliases == null || transformAliases.isEmpty()) {
return baseConfigDef;
}
final ConfigDef newDef = new ConfigDef(baseConfigDef);
for (String alias : new LinkedHashSet<>(transformAliases)) {
final String prefix = TRANSFORMS_CONFIG + "." + alias + ".";
final String group = TRANSFORMS_GROUP + ": " + alias;
int orderInGroup = 0;
final String transformationTypeConfig = prefix + "type";
final ConfigDef.Validator typeValidator = new ConfigDef.Validator() {
@Override
public void ensureValid(String name, Object value) {
getConfigDefFromTransformation(transformationTypeConfig, (Class) value);
}
};
newDef.define(transformationTypeConfig, Type.CLASS, ConfigDef.NO_DEFAULT_VALUE, typeValidator, Importance.HIGH, "Class for the '" + alias + "' transformation.", group, orderInGroup++, Width.LONG, "Transformation type for " + alias, Collections.<String>emptyList(), new TransformationClassRecommender());
final ConfigDef transformationConfigDef;
try {
final String className = props.get(transformationTypeConfig);
final Class<?> cls = (Class<?>) ConfigDef.parseType(transformationTypeConfig, className, Type.CLASS);
transformationConfigDef = getConfigDefFromTransformation(transformationTypeConfig, cls);
} catch (ConfigException e) {
if (requireFullConfig) {
throw e;
} else {
continue;
}
}
newDef.embed(prefix, group, orderInGroup, transformationConfigDef);
}
return newDef;
}
use of org.apache.kafka.common.config.ConfigDef in project apache-kafka-on-k8s by banzaicloud.
the class DistributedHerderTest method testCreateConnector.
@Test
public void testCreateConnector() throws Exception {
EasyMock.expect(member.memberId()).andStubReturn("leader");
expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
expectPostRebalanceCatchup(SNAPSHOT);
member.wakeup();
PowerMock.expectLastCall();
// config validation
Connector connectorMock = PowerMock.createMock(SourceConnector.class);
EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(3);
EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
EasyMock.expect(plugins.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andReturn(new ConfigDef());
EasyMock.expect(connectorMock.validate(CONN2_CONFIG)).andReturn(new Config(Collections.<ConfigValue>emptyList()));
EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
// CONN2 is new, should succeed
configBackingStore.putConnectorConfig(CONN2, CONN2_CONFIG);
PowerMock.expectLastCall();
ConnectorInfo info = new ConnectorInfo(CONN2, CONN2_CONFIG, Collections.<ConnectorTaskId>emptyList(), ConnectorType.SOURCE);
putConnectorCallback.onCompletion(null, new Herder.Created<>(true, info));
PowerMock.expectLastCall();
member.poll(EasyMock.anyInt());
PowerMock.expectLastCall();
// No immediate action besides this -- change will be picked up via the config log
PowerMock.replayAll();
herder.putConnectorConfig(CONN2, CONN2_CONFIG, false, putConnectorCallback);
herder.tick();
time.sleep(1000L);
assertStatistics(3, 1, 100, 1000L);
PowerMock.verifyAll();
}
Aggregations