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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations