Search in sources :

Example 51 with ConnectorInfo

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

the class DistributedHerderTest method testAccessors.

@Test
public void testAccessors() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    EasyMock.expect(worker.getPlugins()).andReturn(plugins).anyTimes();
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.wakeup();
    PowerMock.expectLastCall().anyTimes();
    // list connectors, get connector info, get connector config, get task configs
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    FutureCallback<Collection<String>> listConnectorsCb = new FutureCallback<>();
    herder.connectors(listConnectorsCb);
    FutureCallback<ConnectorInfo> connectorInfoCb = new FutureCallback<>();
    herder.connectorInfo(CONN1, connectorInfoCb);
    FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();
    herder.connectorConfig(CONN1, connectorConfigCb);
    FutureCallback<List<TaskInfo>> taskConfigsCb = new FutureCallback<>();
    herder.taskConfigs(CONN1, taskConfigsCb);
    herder.tick();
    assertTrue(listConnectorsCb.isDone());
    assertEquals(Collections.singleton(CONN1), listConnectorsCb.get());
    assertTrue(connectorInfoCb.isDone());
    ConnectorInfo info = new ConnectorInfo(CONN1, CONN1_CONFIG, Arrays.asList(TASK0, TASK1, TASK2), ConnectorType.SOURCE);
    assertEquals(info, connectorInfoCb.get());
    assertTrue(connectorConfigCb.isDone());
    assertEquals(CONN1_CONFIG, connectorConfigCb.get());
    assertTrue(taskConfigsCb.isDone());
    assertEquals(Arrays.asList(new TaskInfo(TASK0, TASK_CONFIG), new TaskInfo(TASK1, TASK_CONFIG), new TaskInfo(TASK2, TASK_CONFIG)), taskConfigsCb.get());
    PowerMock.verifyAll();
}
Also used : TaskInfo(org.apache.kafka.connect.runtime.rest.entities.TaskInfo) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Collection(java.util.Collection) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 52 with ConnectorInfo

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

the class ConnectorsResourceTest method testDeleteConnectorNotFound.

// Not found exceptions should pass through to caller so they can be processed for 404s
@Test(expected = NotFoundException.class)
public void testDeleteConnectorNotFound() throws Throwable {
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.deleteConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.destroyConnector(CONNECTOR_NAME, FORWARD);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 53 with ConnectorInfo

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

the class ConnectorsResourceTest method testPutConnectorConfigWithSpecialCharsInName.

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

Example 54 with ConnectorInfo

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

the class ConnectorsResourceTest method testGetConnector.

@Test
public void testGetConnector() throws Throwable {
    final Capture<Callback<ConnectorInfo>> cb = Capture.newInstance();
    herder.connectorInfo(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE));
    PowerMock.replayAll();
    ConnectorInfo connInfo = connectorsResource.getConnector(CONNECTOR_NAME, FORWARD);
    assertEquals(new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE), connInfo);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 55 with ConnectorInfo

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

the class ConnectorsResourceTest method testCreateConnectorNameAllWhitespaces.

@Test
public void testCreateConnectorNameAllWhitespaces() 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_ALL_WHITESPACES, 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)

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