Search in sources :

Example 71 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testRestartTaskOwnerRedirect.

@Test
public void testRestartTaskOwnerRedirect() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    String ownerUrl = "http://owner:8083";
    expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));
    EasyMock.expect(RestClient.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=false"), EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject(), EasyMock.anyObject(WorkerConfig.class))).andReturn(new RestClient.HttpResponse<>(202, new HashMap<String, String>(), null));
    PowerMock.replayAll();
    connectorsResource.restartTask(CONNECTOR_NAME, 0, true);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) RestClient(org.apache.kafka.connect.runtime.rest.RestClient) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) NotAssignedException(org.apache.kafka.connect.runtime.distributed.NotAssignedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 72 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testRestartTaskLeaderRedirect.

@Test
public void testRestartTaskLeaderRedirect() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    expectAndCallbackNotLeaderException(cb);
    EasyMock.expect(RestClient.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=true"), EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject(), EasyMock.anyObject(WorkerConfig.class))).andReturn(new RestClient.HttpResponse<>(202, new HashMap<String, String>(), null));
    PowerMock.replayAll();
    connectorsResource.restartTask(CONNECTOR_NAME, 0, null);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) RestClient(org.apache.kafka.connect.runtime.rest.RestClient) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testRestartTaskNotFound.

@Test(expected = NotFoundException.class)
public void testRestartTaskNotFound() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.restartTask(CONNECTOR_NAME, 0, FORWARD);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerderTest method testRestartTaskFailureOnStart.

@Test
public void testRestartTaskFailureOnStart() throws Exception {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    expectAdd(SourceSink.SOURCE);
    Map<String, String> connectorConfig = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, connectorConfig);
    worker.stopAndAwaitTask(taskId);
    EasyMock.expectLastCall();
    worker.startTask(taskId, connectorConfig, taskConfig(SourceSink.SOURCE), herder, TargetState.STARTED);
    EasyMock.expectLastCall().andReturn(false);
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, connectorConfig, false, createCallback);
    FutureCallback<Void> cb = new FutureCallback<>();
    herder.restartTask(taskId, cb);
    try {
        cb.get(1000L, TimeUnit.MILLISECONDS);
        fail("Expected restart callback to raise an exception");
    } catch (ExecutionException exception) {
        assertEquals(ConnectException.class, exception.getCause().getClass());
    }
    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) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(org.apache.kafka.connect.util.FutureCallback) ConnectException(org.apache.kafka.connect.errors.ConnectException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 75 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerderTest method testPutConnectorConfig.

@Test
public void testPutConnectorConfig() throws Exception {
    Map<String, String> connConfig = connectorConfig(SourceSink.SOURCE);
    Map<String, String> newConnConfig = new HashMap<>(connConfig);
    newConnConfig.put("foo", "bar");
    Callback<Map<String, String>> connectorConfigCb = PowerMock.createMock(Callback.class);
    Callback<Herder.Created<ConnectorInfo>> putConnectorConfigCb = PowerMock.createMock(Callback.class);
    // Create
    connector = PowerMock.createMock(BogusSourceConnector.class);
    expectAdd(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, connConfig);
    // Should get first config
    connectorConfigCb.onCompletion(null, connConfig);
    EasyMock.expectLastCall();
    // Update config, which requires stopping and restarting
    worker.stopConnector(CONNECTOR_NAME);
    EasyMock.expectLastCall().andReturn(true);
    Capture<Map<String, String>> capturedConfig = EasyMock.newCapture();
    worker.startConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(capturedConfig), EasyMock.<ConnectorContext>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONNECTOR_NAME)).andReturn(true);
    // Generate same task config, which should result in no additional action to restart tasks
    EasyMock.expect(worker.connectorTaskConfigs(CONNECTOR_NAME, new SourceConnectorConfig(plugins, newConnConfig))).andReturn(singletonList(taskConfig(SourceSink.SOURCE)));
    worker.isSinkConnector(CONNECTOR_NAME);
    EasyMock.expectLastCall().andReturn(false);
    ConnectorInfo newConnInfo = new ConnectorInfo(CONNECTOR_NAME, newConnConfig, Arrays.asList(new ConnectorTaskId(CONNECTOR_NAME, 0)), ConnectorType.SOURCE);
    putConnectorConfigCb.onCompletion(null, new Herder.Created<>(false, newConnInfo));
    EasyMock.expectLastCall();
    // Should get new config
    expectConfigValidation(connectorMock, false, newConnConfig);
    connectorConfigCb.onCompletion(null, newConnConfig);
    EasyMock.expectLastCall();
    EasyMock.expect(worker.getPlugins()).andReturn(plugins).anyTimes();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, connConfig, false, createCallback);
    herder.connectorConfig(CONNECTOR_NAME, connectorConfigCb);
    herder.putConnectorConfig(CONNECTOR_NAME, newConnConfig, true, putConnectorConfigCb);
    assertEquals("bar", capturedConfig.getValue().get("foo"));
    herder.connectorConfig(CONNECTOR_NAME, connectorConfigCb);
    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) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) SourceConnectorConfig(org.apache.kafka.connect.runtime.SourceConnectorConfig) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)111 Test (org.junit.Test)59 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)45 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 Map (java.util.Map)18 FutureCallback (org.apache.kafka.connect.util.FutureCallback)16 ConnectException (org.apache.kafka.connect.errors.ConnectException)15 Callback (org.apache.kafka.connect.util.Callback)15 Connector (org.apache.kafka.connect.connector.Connector)13 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)12 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)12 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)12 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)11 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)11 SourceConnector (org.apache.kafka.connect.source.SourceConnector)11 Herder (org.apache.kafka.connect.runtime.Herder)10 List (java.util.List)9 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)9 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)8