Search in sources :

Example 41 with ConnectorTaskId

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

the class WorkerCoordinatorTest method setup.

@Before
public void setup() {
    LogContext logContext = new LogContext();
    this.time = new MockTime();
    this.metadata = new Metadata(0, Long.MAX_VALUE, logContext, new ClusterResourceListeners());
    this.client = new MockClient(time, metadata);
    this.client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, Collections.singletonMap("topic", 1)));
    this.node = metadata.fetch().nodes().get(0);
    this.consumerClient = new ConsumerNetworkClient(logContext, client, metadata, time, 100, 1000, heartbeatIntervalMs);
    this.metrics = new Metrics(time);
    this.rebalanceListener = new MockRebalanceListener();
    this.configStorage = PowerMock.createMock(KafkaConfigBackingStore.class);
    this.rebalanceConfig = new GroupRebalanceConfig(sessionTimeoutMs, rebalanceTimeoutMs, heartbeatIntervalMs, groupId, Optional.empty(), retryBackoffMs, true);
    this.coordinator = new WorkerCoordinator(rebalanceConfig, logContext, consumerClient, metrics, "consumer" + groupId, time, LEADER_URL, configStorage, rebalanceListener, compatibility, 0);
    configState1 = new ClusterConfigState(1L, null, Collections.singletonMap(connectorId1, 1), Collections.singletonMap(connectorId1, new HashMap<>()), Collections.singletonMap(connectorId1, TargetState.STARTED), Collections.singletonMap(taskId1x0, new HashMap<>()), Collections.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<>());
    configState2ConnectorConfigs.put(connectorId2, new HashMap<>());
    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<>());
    configState2TaskConfigs.put(taskId1x1, new HashMap<>());
    configState2TaskConfigs.put(taskId2x0, new HashMap<>());
    configState2 = new ClusterConfigState(2L, null, configState2ConnectorTaskCounts, configState2ConnectorConfigs, configState2TargetStates, configState2TaskConfigs, Collections.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<>());
    configStateSingleTaskConnectorsConnectorConfigs.put(connectorId2, new HashMap<>());
    configStateSingleTaskConnectorsConnectorConfigs.put(connectorId3, new HashMap<>());
    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<>());
    configStateSingleTaskConnectorsTaskConfigs.put(taskId2x0, new HashMap<>());
    configStateSingleTaskConnectorsTaskConfigs.put(taskId3x0, new HashMap<>());
    configStateSingleTaskConnectors = new ClusterConfigState(2L, null, configStateSingleTaskConnectorsConnectorTaskCounts, configStateSingleTaskConnectorsConnectorConfigs, configStateSingleTaskConnectorsTargetStates, configStateSingleTaskConnectorsTaskConfigs, Collections.emptySet());
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) Metadata(org.apache.kafka.clients.Metadata) LogContext(org.apache.kafka.common.utils.LogContext) KafkaConfigBackingStore(org.apache.kafka.connect.storage.KafkaConfigBackingStore) GroupRebalanceConfig(org.apache.kafka.clients.GroupRebalanceConfig) Metrics(org.apache.kafka.common.metrics.Metrics) ConsumerNetworkClient(org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient) HashMap(java.util.HashMap) Map(java.util.Map) MockTime(org.apache.kafka.common.utils.MockTime) MockClient(org.apache.kafka.clients.MockClient) Before(org.junit.Before)

Example 42 with ConnectorTaskId

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

the class ErrorReporterTest method setup.

@Before
public void setup() {
    metrics = new MockConnectMetrics();
    errorHandlingMetrics = new ErrorHandlingMetrics(new ConnectorTaskId("connector-", 1), metrics);
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) MockConnectMetrics(org.apache.kafka.connect.runtime.MockConnectMetrics) Before(org.junit.Before)

Example 43 with ConnectorTaskId

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

the class DistributedHerderTest method testDoRestartConnectorAndTasksOnlyTasks.

@Test
public void testDoRestartConnectorAndTasksOnlyTasks() {
    ConnectorTaskId taskId = new ConnectorTaskId(CONN1, 0);
    RestartRequest restartRequest = new RestartRequest(CONN1, false, true);
    RestartPlan restartPlan = PowerMock.createMock(RestartPlan.class);
    EasyMock.expect(restartPlan.shouldRestartConnector()).andReturn(true).anyTimes();
    EasyMock.expect(restartPlan.shouldRestartTasks()).andReturn(true).anyTimes();
    EasyMock.expect(restartPlan.taskIdsToRestart()).andReturn(Collections.singletonList(taskId)).anyTimes();
    EasyMock.expect(restartPlan.restartTaskCount()).andReturn(1).anyTimes();
    EasyMock.expect(restartPlan.totalTaskCount()).andReturn(1).anyTimes();
    EasyMock.expect(herder.buildRestartPlan(restartRequest)).andReturn(Optional.of(restartPlan)).anyTimes();
    herder.assignment = PowerMock.createMock(ExtendedAssignment.class);
    EasyMock.expect(herder.assignment.connectors()).andReturn(Collections.emptyList()).anyTimes();
    EasyMock.expect(herder.assignment.tasks()).andReturn(Collections.singletonList(taskId)).anyTimes();
    worker.stopAndAwaitTasks(Collections.singletonList(taskId));
    PowerMock.expectLastCall();
    herder.onRestart(taskId);
    EasyMock.expectLastCall();
    worker.startTask(EasyMock.eq(TASK0), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.eq(herder), EasyMock.anyObject(TargetState.class));
    PowerMock.expectLastCall().andReturn(true);
    PowerMock.replayAll();
    herder.doRestartConnectorAndTasks(restartRequest);
    PowerMock.verifyAll();
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) RestartPlan(org.apache.kafka.connect.runtime.RestartPlan) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with ConnectorTaskId

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

the class DistributedHerderTest method testDoRestartConnectorAndTasksOnlyConnector.

@Test
public void testDoRestartConnectorAndTasksOnlyConnector() {
    ConnectorTaskId taskId = new ConnectorTaskId(CONN1, 0);
    RestartRequest restartRequest = new RestartRequest(CONN1, false, true);
    RestartPlan restartPlan = PowerMock.createMock(RestartPlan.class);
    EasyMock.expect(restartPlan.shouldRestartConnector()).andReturn(true).anyTimes();
    EasyMock.expect(restartPlan.shouldRestartTasks()).andReturn(true).anyTimes();
    EasyMock.expect(restartPlan.taskIdsToRestart()).andReturn(Collections.singletonList(taskId)).anyTimes();
    EasyMock.expect(herder.buildRestartPlan(restartRequest)).andReturn(Optional.of(restartPlan)).anyTimes();
    herder.assignment = PowerMock.createMock(ExtendedAssignment.class);
    EasyMock.expect(herder.assignment.connectors()).andReturn(Collections.singletonList(CONN1)).anyTimes();
    EasyMock.expect(herder.assignment.tasks()).andReturn(Collections.emptyList()).anyTimes();
    worker.stopAndAwaitConnector(CONN1);
    PowerMock.expectLastCall();
    Capture<Callback<TargetState>> stateCallback = newCapture();
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.eq(herder), EasyMock.anyObject(TargetState.class), capture(stateCallback));
    herder.onRestart(CONN1);
    EasyMock.expectLastCall();
    PowerMock.replayAll();
    herder.doRestartConnectorAndTasks(restartRequest);
    PowerMock.verifyAll();
}
Also used : TargetState(org.apache.kafka.connect.runtime.TargetState) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) RestartPlan(org.apache.kafka.connect.runtime.RestartPlan) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with ConnectorTaskId

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

the class DistributedHerderTest method testRestartUnknownTask.

@Test
public void testRestartUnknownTask() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    expectRebalance(1, Collections.emptyList(), Collections.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();
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) FutureCallback(org.apache.kafka.connect.util.FutureCallback) 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