Search in sources :

Example 1 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class WorkerCoordinatorTest method testJoinLeaderCannotAssign.

@Test
public void testJoinLeaderCannotAssign() {
    // If the selected leader can't get up to the maximum offset, it will fail to assign and we should immediately
    // need to retry the join.
    // When the first round fails, we'll take an updated config snapshot
    EasyMock.expect(configStorage.snapshot()).andReturn(configState1);
    EasyMock.expect(configStorage.snapshot()).andReturn(configState2);
    PowerMock.replayAll();
    final String memberId = "member";
    client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    coordinator.ensureCoordinatorReady();
    // config mismatch results in assignment error
    client.prepareResponse(joinGroupFollowerResponse(1, memberId, "leader", Errors.NONE));
    MockClient.RequestMatcher matcher = new MockClient.RequestMatcher() {

        @Override
        public boolean matches(AbstractRequest body) {
            SyncGroupRequest sync = (SyncGroupRequest) body;
            return sync.memberId().equals(memberId) && sync.generationId() == 1 && sync.groupAssignment().isEmpty();
        }
    };
    client.prepareResponse(matcher, syncGroupResponse(ConnectProtocol.Assignment.CONFIG_MISMATCH, "leader", 10L, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(), Errors.NONE));
    client.prepareResponse(joinGroupFollowerResponse(1, memberId, "leader", Errors.NONE));
    client.prepareResponse(matcher, syncGroupResponse(ConnectProtocol.Assignment.NO_ERROR, "leader", 1L, Collections.<String>emptyList(), Collections.singletonList(taskId1x0), Errors.NONE));
    coordinator.ensureActiveGroup();
    PowerMock.verifyAll();
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) SyncGroupRequest(org.apache.kafka.common.requests.SyncGroupRequest) AbstractRequest(org.apache.kafka.common.requests.AbstractRequest) MockClient(org.apache.kafka.clients.MockClient) Test(org.junit.Test)

Example 2 with ConnectorTaskId

use of org.apache.kafka.connect.util.ConnectorTaskId in project kafka by apache.

the class ConnectorsResource method restartTask.

@POST
@Path("/{connector}/tasks/{task}/restart")
public void restartTask(@PathParam("connector") final String connector, @PathParam("task") final Integer task, @QueryParam("forward") final Boolean forward) throws Throwable {
    FutureCallback<Void> cb = new FutureCallback<>();
    ConnectorTaskId taskId = new ConnectorTaskId(connector, task);
    herder.restartTask(taskId, cb);
    completeOrForwardRequest(cb, "/connectors/" + connector + "/tasks/" + task + "/restart", "POST", null, forward);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with ConnectorTaskId

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

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndShutdown() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    ConnectMetrics metrics = new MockConnectMetrics();
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    group.onStartup(taskId);
    assertRunningMetric(group);
    group.onPause(taskId);
    assertPausedMetric(group);
    group.onResume(taskId);
    assertRunningMetric(group);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with ConnectorTaskId

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

the class WorkerTaskTest method updateMetricsOnListenerEventsForStartupPauseResumeAndFailure.

@Test
public void updateMetricsOnListenerEventsForStartupPauseResumeAndFailure() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    MockConnectMetrics metrics = new MockConnectMetrics();
    MockTime time = metrics.time();
    ConnectException error = new ConnectException("error");
    TaskMetricsGroup group = new TaskMetricsGroup(taskId, metrics, statusListener);
    statusListener.onStartup(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onPause(taskId);
    expectLastCall();
    statusListener.onResume(taskId);
    expectLastCall();
    statusListener.onFailure(taskId, error);
    expectLastCall();
    statusListener.onShutdown(taskId);
    expectLastCall();
    replay(statusListener);
    time.sleep(1000L);
    group.onStartup(taskId);
    assertRunningMetric(group);
    time.sleep(2000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(3000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(4000L);
    group.onPause(taskId);
    assertPausedMetric(group);
    time.sleep(5000L);
    group.onResume(taskId);
    assertRunningMetric(group);
    time.sleep(6000L);
    group.onFailure(taskId, error);
    assertFailedMetric(group);
    time.sleep(7000L);
    group.onShutdown(taskId);
    assertStoppedMetric(group);
    verify(statusListener);
    long totalTime = 27000L;
    double pauseTimeRatio = (double) (3000L + 5000L) / totalTime;
    double runningTimeRatio = (double) (2000L + 4000L + 6000L) / totalTime;
    assertEquals(pauseTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "pause-ratio"), 0.000001d);
    assertEquals(runningTimeRatio, metrics.currentMetricValueAsDouble(group.metricGroup(), "running-ratio"), 0.000001d);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) MockTime(org.apache.kafka.common.utils.MockTime) ConnectException(org.apache.kafka.connect.errors.ConnectException) TaskMetricsGroup(org.apache.kafka.connect.runtime.WorkerTask.TaskMetricsGroup) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ConnectorTaskId

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

the class WorkerTaskTest method stopBeforeStarting.

@Test
public void stopBeforeStarting() {
    ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
    WorkerTask workerTask = partialMockBuilder(WorkerTask.class).withConstructor(ConnectorTaskId.class, TaskStatus.Listener.class, TargetState.class, ClassLoader.class, ConnectMetrics.class).withArgs(taskId, statusListener, TargetState.STARTED, loader, metrics).addMockedMethod("initialize").addMockedMethod("execute").addMockedMethod("close").createStrictMock();
    workerTask.initialize(TASK_CONFIG);
    EasyMock.expectLastCall();
    workerTask.close();
    EasyMock.expectLastCall();
    workerTask.releaseResources();
    EasyMock.expectLastCall();
    replay(workerTask);
    workerTask.initialize(TASK_CONFIG);
    workerTask.stop();
    workerTask.awaitStop(1000L);
    // now run should not do anything
    workerTask.run();
    verify(workerTask);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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