use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class PluginsTest method shouldShareStaticValuesBetweenSamePlugin.
@Test
public void shouldShareStaticValuesBetweenSamePlugin() {
// Plugins are not isolated from other instances of their own class.
TestPlugins.assertAvailable();
Converter firstPlugin = plugins.newPlugin(TestPlugins.ALIASED_STATIC_FIELD, new AbstractConfig(new ConfigDef(), Collections.emptyMap()), Converter.class);
assertInstanceOf(SamplingTestPlugin.class, firstPlugin, "Cannot collect samples");
Converter secondPlugin = plugins.newPlugin(TestPlugins.ALIASED_STATIC_FIELD, new AbstractConfig(new ConfigDef(), Collections.emptyMap()), Converter.class);
assertInstanceOf(SamplingTestPlugin.class, secondPlugin, "Cannot collect samples");
assertSame(((SamplingTestPlugin) firstPlugin).otherSamples(), ((SamplingTestPlugin) secondPlugin).otherSamples());
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class PluginsTest method newPluginShouldInstantiateWithPluginClassLoader.
@Test
public void newPluginShouldInstantiateWithPluginClassLoader() {
TestPlugins.assertAvailable();
Converter plugin = plugins.newPlugin(TestPlugins.ALIASED_STATIC_FIELD, new AbstractConfig(new ConfigDef(), Collections.emptyMap()), Converter.class);
assertInstanceOf(SamplingTestPlugin.class, plugin, "Cannot collect samples");
Map<String, SamplingTestPlugin> samples = ((SamplingTestPlugin) plugin).flatten();
assertPluginClassLoaderAlwaysActive(samples);
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class PluginsTest method shouldThrowIfPluginThrows.
@Test
public void shouldThrowIfPluginThrows() {
TestPlugins.assertAvailable();
assertThrows(ConnectException.class, () -> plugins.newPlugin(TestPlugins.ALWAYS_THROW_EXCEPTION, new AbstractConfig(new ConfigDef(), Collections.emptyMap()), Converter.class));
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class StandaloneHerderTest method testCorruptConfig.
@Test
public void testCorruptConfig() throws Throwable {
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME);
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, BogusSinkConnector.class.getName());
config.put(SinkConnectorConfig.TOPICS_CONFIG, TOPICS_LIST_STR);
Connector connectorMock = PowerMock.createMock(SinkConnector.class);
String error = "This is an error in your config!";
List<String> errors = new ArrayList<>(singletonList(error));
String key = "foo.invalid.key";
EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(Arrays.asList(new ConfigValue(key, null, Collections.emptyList(), errors))));
ConfigDef configDef = new ConfigDef();
configDef.define(key, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "");
EasyMock.expect(worker.configTransformer()).andReturn(transformer).times(2);
final Capture<Map<String, String>> configCapture = EasyMock.newCapture();
EasyMock.expect(transformer.transform(EasyMock.capture(configCapture))).andAnswer(configCapture::getValue);
EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(3);
EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
EasyMock.expect(plugins.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andStubReturn(configDef);
EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
PowerMock.replayAll();
herder.putConnectorConfig(CONNECTOR_NAME, config, true, createCallback);
try {
createCallback.get(1000L, TimeUnit.SECONDS);
fail("Should have failed to configure connector");
} catch (ExecutionException e) {
assertNotNull(e.getCause());
Throwable cause = e.getCause();
assertTrue(cause instanceof BadRequestException);
assertEquals(cause.getMessage(), "Connector configuration is invalid and contains the following 1 error(s):\n" + error + "\n" + "You can also find the above list of errors at the endpoint `/connector-plugins/{connectorType}/config/validate`");
}
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class ConnectorPluginsResourceTest method testValidateConfigWithSimpleName.
@Test
public void testValidateConfigWithSimpleName() throws Throwable {
Capture<Callback<ConfigInfos>> configInfosCallback = EasyMock.newCapture();
herder.validateConnectorConfig(EasyMock.eq(props), EasyMock.capture(configInfosCallback), EasyMock.anyBoolean());
PowerMock.expectLastCall().andAnswer((IAnswer<ConfigInfos>) () -> {
ConfigDef connectorConfigDef = ConnectorConfig.configDef();
List<ConfigValue> connectorConfigValues = connectorConfigDef.validate(props);
Connector connector = new ConnectorPluginsResourceTestConnector();
Config config = connector.validate(props);
ConfigDef configDef = connector.config();
Map<String, ConfigDef.ConfigKey> configKeys = configDef.configKeys();
List<ConfigValue> configValues = config.configValues();
Map<String, ConfigDef.ConfigKey> resultConfigKeys = new HashMap<>(configKeys);
resultConfigKeys.putAll(connectorConfigDef.configKeys());
configValues.addAll(connectorConfigValues);
ConfigInfos configInfos = AbstractHerder.generateResult(ConnectorPluginsResourceTestConnector.class.getName(), resultConfigKeys, configValues, Collections.singletonList("Test"));
configInfosCallback.getValue().onCompletion(null, configInfos);
return null;
});
PowerMock.replayAll();
// make a request to connector-plugins resource using just the simple class name.
ConfigInfos configInfos = connectorPluginsResource.validateConfigs(ConnectorPluginsResourceTestConnector.class.getSimpleName(), props);
assertEquals(CONFIG_INFOS.name(), configInfos.name());
assertEquals(0, configInfos.errorCount());
assertEquals(CONFIG_INFOS.groups(), configInfos.groups());
assertEquals(new HashSet<>(CONFIG_INFOS.values()), new HashSet<>(configInfos.values()));
PowerMock.verifyAll();
}
Aggregations