Search in sources :

Example 6 with BadRequestException

use of org.apache.kafka.connect.runtime.rest.errors.BadRequestException in project kafka by apache.

the class DistributedHerderTest method testConnectorNameConflictsWithWorkerGroupId.

@Test
public void testConnectorNameConflictsWithWorkerGroupId() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.wakeup();
    PowerMock.expectLastCall();
    Map<String, String> config = new HashMap<>(CONN2_CONFIG);
    config.put(ConnectorConfig.NAME_CONFIG, "test-group");
    // config validation
    ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
    EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
    Connector connectorMock = PowerMock.createMock(SinkConnector.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 because the worker group id (connect-test-group) conflicts with
    // the consumer group id we would use for this sink
    Capture<Throwable> error = EasyMock.newCapture();
    putConnectorCallback.onCompletion(EasyMock.capture(error), EasyMock.isNull(Herder.Created.class));
    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();
}
Also used : SourceConnector(org.apache.kafka.connect.source.SourceConnector) Connector(org.apache.kafka.connect.connector.Connector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) ConfigValue(org.apache.kafka.common.config.ConfigValue) ConnectorFactory(org.apache.kafka.connect.runtime.ConnectorFactory) HashMap(java.util.HashMap) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) ConnectorConfig(org.apache.kafka.connect.runtime.ConnectorConfig) Config(org.apache.kafka.common.config.Config) SinkConnectorConfig(org.apache.kafka.connect.runtime.SinkConnectorConfig) TaskConfig(org.apache.kafka.connect.runtime.TaskConfig) BadRequestException(org.apache.kafka.connect.runtime.rest.errors.BadRequestException) ConfigDef(org.apache.kafka.common.config.ConfigDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)6 Config (org.apache.kafka.common.config.Config)4 ConfigDef (org.apache.kafka.common.config.ConfigDef)4 ConfigValue (org.apache.kafka.common.config.ConfigValue)4 Connector (org.apache.kafka.connect.connector.Connector)4 SourceConnector (org.apache.kafka.connect.source.SourceConnector)4 HashMap (java.util.HashMap)3 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)3 ConnectorFactory (org.apache.kafka.connect.runtime.ConnectorFactory)3 SinkConnectorConfig (org.apache.kafka.connect.runtime.SinkConnectorConfig)3 TaskConfig (org.apache.kafka.connect.runtime.TaskConfig)3 WorkerConfig (org.apache.kafka.connect.runtime.WorkerConfig)3 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)3 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)2 ConnectException (org.apache.kafka.connect.errors.ConnectException)2 Herder (org.apache.kafka.connect.runtime.Herder)2 ConfigInfos (org.apache.kafka.connect.runtime.rest.entities.ConfigInfos)2