use of org.apache.kafka.connect.connector.Connector in project kafka by apache.
the class WorkerTest method testAddConnectorByAlias.
@Test
public void testAddConnectorByAlias() throws Exception {
expectStartStorage();
// Create
Connector connector = PowerMock.createMock(Connector.class);
ConnectorContext ctx = PowerMock.createMock(ConnectorContext.class);
EasyMock.expect(connectorFactory.newConnector("WorkerTestConnector")).andReturn(connector);
EasyMock.expect(connector.version()).andReturn("1.0");
Map<String, String> props = new HashMap<>();
props.put(SinkConnectorConfig.TOPICS_CONFIG, "foo,bar");
props.put(ConnectorConfig.TASKS_MAX_CONFIG, "1");
props.put(ConnectorConfig.NAME_CONFIG, CONNECTOR_ID);
props.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, "WorkerTestConnector");
connector.initialize(EasyMock.anyObject(ConnectorContext.class));
EasyMock.expectLastCall();
connector.start(props);
EasyMock.expectLastCall();
connectorStatusListener.onStartup(CONNECTOR_ID);
EasyMock.expectLastCall();
// Remove
connector.stop();
EasyMock.expectLastCall();
connectorStatusListener.onShutdown(CONNECTOR_ID);
EasyMock.expectLastCall();
expectStopStorage();
PowerMock.replayAll();
worker = new Worker(WORKER_ID, new MockTime(), connectorFactory, config, offsetBackingStore);
worker.start();
assertEquals(Collections.emptySet(), worker.connectorNames());
worker.startConnector(CONNECTOR_ID, props, ctx, connectorStatusListener, TargetState.STARTED);
assertEquals(new HashSet<>(Arrays.asList(CONNECTOR_ID)), worker.connectorNames());
worker.stopConnector(CONNECTOR_ID);
assertEquals(Collections.emptySet(), worker.connectorNames());
// Nothing should be left, so this should effectively be a nop
worker.stop();
PowerMock.verifyAll();
}
use of org.apache.kafka.connect.connector.Connector 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.connect.connector.Connector 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.connect.connector.Connector 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.connect.connector.Connector in project kafka by apache.
the class AbstractHerder method getConnector.
protected Connector getConnector(String connType) {
if (tempConnectors.containsKey(connType)) {
return tempConnectors.get(connType);
} else {
Connector connector = worker.getConnectorFactory().newConnector(connType);
tempConnectors.put(connType, connector);
return connector;
}
}
Aggregations