Search in sources :

Example 16 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testCreateConnectorNotLeader.

@Test
public void testCreateConnectorNotLeader() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackNotLeaderException(cb);
    // Should forward request
    EasyMock.expect(RestClient.httpRequest(EasyMock.eq("http://leader:8083/connectors?forward=false"), EasyMock.eq("POST"), EasyMock.eq(body), EasyMock.<TypeReference>anyObject(), EasyMock.anyObject(WorkerConfig.class))).andReturn(new RestClient.HttpResponse<>(201, new HashMap<String, String>(), new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, body);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) HashMap(java.util.HashMap) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) RestClient(org.apache.kafka.connect.runtime.rest.RestClient) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testCreateConnectorNoName.

@Test
public void testCreateConnectorNoName() throws Throwable {
    // Clone CONNECTOR_CONFIG_WITHOUT_NAME Map, as createConnector changes it (puts the name in it) and this
    // will affect later tests
    Map<String, String> inputConfig = getConnectorConfig(CONNECTOR_CONFIG_WITHOUT_NAME);
    final CreateConnectorRequest bodyIn = new CreateConnectorRequest(null, inputConfig);
    final CreateConnectorRequest bodyOut = new CreateConnectorRequest("", CONNECTOR_CONFIG_WITH_EMPTY_NAME);
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(bodyOut.name()), EasyMock.eq(bodyOut.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(bodyOut.name(), bodyOut.config(), CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, bodyIn);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testCreateConnectorWithControlSequenceInName.

@Test
public void testCreateConnectorWithControlSequenceInName() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME_CONTROL_SEQUENCES1, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME_CONTROL_SEQUENCES1));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME_CONTROL_SEQUENCES1), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME_CONTROL_SEQUENCES1, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    String rspLocation = connectorsResource.createConnector(FORWARD, body).getLocation().toString();
    String decoded = new URI(rspLocation).getPath();
    Assert.assertEquals("/connectors/" + CONNECTOR_NAME_CONTROL_SEQUENCES1, decoded);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) URI(java.net.URI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testCreateConnectorNameTrimWhitespaces.

@Test
public void testCreateConnectorNameTrimWhitespaces() throws Throwable {
    // Clone CONNECTOR_CONFIG_WITHOUT_NAME Map, as createConnector changes it (puts the name in it) and this
    // will affect later tests
    Map<String, String> inputConfig = getConnectorConfig(CONNECTOR_CONFIG_WITHOUT_NAME);
    final CreateConnectorRequest bodyIn = new CreateConnectorRequest(CONNECTOR_NAME_PADDING_WHITESPACES, inputConfig);
    final CreateConnectorRequest bodyOut = new CreateConnectorRequest(CONNECTOR_NAME, CONNECTOR_CONFIG);
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(bodyOut.name()), EasyMock.eq(bodyOut.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(bodyOut.name(), bodyOut.config(), CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, bodyIn);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerderTest method testCreateConnectorFailedCustomValidation.

@Test
public void testCreateConnectorFailedCustomValidation() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    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);
    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");
    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(singletonList(validatedValue)));
    EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
    createCallback.onCompletion(EasyMock.<BadRequestException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    PowerMock.verifyAll();
}
Also used : SourceConnector(org.apache.kafka.connect.source.SourceConnector) WorkerConnector(org.apache.kafka.connect.runtime.WorkerConnector) Connector(org.apache.kafka.connect.connector.Connector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) ConfigValue(org.apache.kafka.common.config.ConfigValue) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) 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) ConfigDef(org.apache.kafka.common.config.ConfigDef) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)78 Herder (org.apache.kafka.connect.runtime.Herder)65 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)61 Callback (org.apache.kafka.connect.util.Callback)35 Connector (org.apache.kafka.connect.connector.Connector)28 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)28 SourceConnector (org.apache.kafka.connect.source.SourceConnector)28 FutureCallback (org.apache.kafka.connect.util.FutureCallback)25 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)20 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)19 HashMap (java.util.HashMap)17 URI (java.net.URI)13 Map (java.util.Map)13 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)11 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 Config (org.apache.kafka.common.config.Config)10 ConfigDef (org.apache.kafka.common.config.ConfigDef)10 ConfigValue (org.apache.kafka.common.config.ConfigValue)10 TaskConfig (org.apache.kafka.connect.runtime.TaskConfig)10