use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.
the class Worker method awaitStopTasks.
private void awaitStopTasks(Collection<ConnectorTaskId> ids) {
long now = time.milliseconds();
long deadline = now + config.getLong(WorkerConfig.TASK_SHUTDOWN_GRACEFUL_TIMEOUT_MS_CONFIG);
for (ConnectorTaskId id : ids) {
long remaining = Math.max(0, deadline - time.milliseconds());
awaitStopTask(id, remaining);
}
}
use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.
the class WorkerTaskTest method cancelBeforeStopping.
@Test
public void cancelBeforeStopping() throws Exception {
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();
final CountDownLatch stopped = new CountDownLatch(1);
final Thread thread = new Thread() {
@Override
public void run() {
try {
stopped.await();
} catch (Exception e) {
}
}
};
workerTask.initialize(TASK_CONFIG);
EasyMock.expectLastCall();
workerTask.execute();
expectLastCall().andAnswer(new IAnswer<Void>() {
@Override
public Void answer() throws Throwable {
thread.start();
return null;
}
});
statusListener.onStartup(taskId);
expectLastCall();
workerTask.close();
expectLastCall();
workerTask.releaseResources();
EasyMock.expectLastCall();
// there should be no call to onShutdown()
replay(workerTask);
workerTask.initialize(TASK_CONFIG);
workerTask.run();
workerTask.stop();
workerTask.cancel();
stopped.countDown();
thread.join();
verify(workerTask);
}
use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.
the class WorkerTaskTest method standardStartup.
@Test
public void standardStartup() {
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);
expectLastCall();
workerTask.execute();
expectLastCall();
statusListener.onStartup(taskId);
expectLastCall();
workerTask.close();
expectLastCall();
workerTask.releaseResources();
EasyMock.expectLastCall();
statusListener.onShutdown(taskId);
expectLastCall();
replay(workerTask);
workerTask.initialize(TASK_CONFIG);
workerTask.run();
workerTask.stop();
workerTask.awaitStop(1000L);
verify(workerTask);
}
use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.
the class DistributedHerderTest method testRestartUnknownTask.
@Test
public void testRestartUnknownTask() throws Exception {
// get the initial assignment
EasyMock.expect(member.memberId()).andStubReturn("member");
expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
expectPostRebalanceCatchup(SNAPSHOT);
member.poll(EasyMock.anyInt());
PowerMock.expectLastCall();
member.wakeup();
PowerMock.expectLastCall();
member.ensureActive();
PowerMock.expectLastCall();
member.poll(EasyMock.anyInt());
PowerMock.expectLastCall();
PowerMock.replayAll();
FutureCallback<Void> callback = new FutureCallback<>();
herder.tick();
herder.restartTask(new ConnectorTaskId("blah", 0), callback);
herder.tick();
try {
callback.get(1000L, TimeUnit.MILLISECONDS);
fail("Expected NotLeaderException to be raised");
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof NotFoundException);
}
PowerMock.verifyAll();
}
use of org.apache.kafka.connect.util.ConnectorTaskId in project apache-kafka-on-k8s by banzaicloud.
the class WorkerCoordinatorTest method setup.
@Before
public void setup() {
LogContext loggerFactory = new LogContext();
this.time = new MockTime();
this.client = new MockClient(time);
this.metadata = new Metadata(0, Long.MAX_VALUE, true);
this.metadata.update(cluster, Collections.<String>emptySet(), time.milliseconds());
this.consumerClient = new ConsumerNetworkClient(loggerFactory, client, metadata, time, 100, 1000, heartbeatIntervalMs);
this.metrics = new Metrics(time);
this.rebalanceListener = new MockRebalanceListener();
this.configStorage = PowerMock.createMock(KafkaConfigBackingStore.class);
client.setNode(node);
this.coordinator = new WorkerCoordinator(loggerFactory, consumerClient, groupId, rebalanceTimeoutMs, sessionTimeoutMs, heartbeatIntervalMs, metrics, "consumer" + groupId, time, retryBackoffMs, LEADER_URL, configStorage, rebalanceListener);
configState1 = new ClusterConfigState(1L, Collections.singletonMap(connectorId1, 1), Collections.singletonMap(connectorId1, (Map<String, String>) new HashMap<String, String>()), Collections.singletonMap(connectorId1, TargetState.STARTED), Collections.singletonMap(taskId1x0, (Map<String, String>) new HashMap<String, String>()), Collections.<String>emptySet());
Map<String, Integer> configState2ConnectorTaskCounts = new HashMap<>();
configState2ConnectorTaskCounts.put(connectorId1, 2);
configState2ConnectorTaskCounts.put(connectorId2, 1);
Map<String, Map<String, String>> configState2ConnectorConfigs = new HashMap<>();
configState2ConnectorConfigs.put(connectorId1, new HashMap<String, String>());
configState2ConnectorConfigs.put(connectorId2, new HashMap<String, String>());
Map<String, TargetState> configState2TargetStates = new HashMap<>();
configState2TargetStates.put(connectorId1, TargetState.STARTED);
configState2TargetStates.put(connectorId2, TargetState.STARTED);
Map<ConnectorTaskId, Map<String, String>> configState2TaskConfigs = new HashMap<>();
configState2TaskConfigs.put(taskId1x0, new HashMap<String, String>());
configState2TaskConfigs.put(taskId1x1, new HashMap<String, String>());
configState2TaskConfigs.put(taskId2x0, new HashMap<String, String>());
configState2 = new ClusterConfigState(2L, configState2ConnectorTaskCounts, configState2ConnectorConfigs, configState2TargetStates, configState2TaskConfigs, Collections.<String>emptySet());
Map<String, Integer> configStateSingleTaskConnectorsConnectorTaskCounts = new HashMap<>();
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId1, 1);
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId2, 1);
configStateSingleTaskConnectorsConnectorTaskCounts.put(connectorId3, 1);
Map<String, Map<String, String>> configStateSingleTaskConnectorsConnectorConfigs = new HashMap<>();
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId1, new HashMap<String, String>());
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId2, new HashMap<String, String>());
configStateSingleTaskConnectorsConnectorConfigs.put(connectorId3, new HashMap<String, String>());
Map<String, TargetState> configStateSingleTaskConnectorsTargetStates = new HashMap<>();
configStateSingleTaskConnectorsTargetStates.put(connectorId1, TargetState.STARTED);
configStateSingleTaskConnectorsTargetStates.put(connectorId2, TargetState.STARTED);
configStateSingleTaskConnectorsTargetStates.put(connectorId3, TargetState.STARTED);
Map<ConnectorTaskId, Map<String, String>> configStateSingleTaskConnectorsTaskConfigs = new HashMap<>();
configStateSingleTaskConnectorsTaskConfigs.put(taskId1x0, new HashMap<String, String>());
configStateSingleTaskConnectorsTaskConfigs.put(taskId2x0, new HashMap<String, String>());
configStateSingleTaskConnectorsTaskConfigs.put(taskId3x0, new HashMap<String, String>());
configStateSingleTaskConnectors = new ClusterConfigState(2L, configStateSingleTaskConnectorsConnectorTaskCounts, configStateSingleTaskConnectorsConnectorConfigs, configStateSingleTaskConnectorsTargetStates, configStateSingleTaskConnectorsTaskConfigs, Collections.<String>emptySet());
}
Aggregations