Search in sources :

Example 16 with RestartRequest

use of org.apache.kafka.connect.runtime.RestartRequest in project kafka by apache.

the class DistributedHerderTest method testRestartConnectorAndTasksNotLeader.

@Test
public void testRestartConnectorAndTasksNotLeader() throws Exception {
    RestartRequest restartRequest = new RestartRequest(CONN1, false, true);
    // 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();
    // now handle the connector restart
    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    herder.tick();
    FutureCallback<ConnectorStateInfo> callback = new FutureCallback<>();
    herder.restartConnectorAndTasks(restartRequest, callback);
    herder.tick();
    ExecutionException ee = assertThrows(ExecutionException.class, () -> callback.get(1000L, TimeUnit.MILLISECONDS));
    assertTrue(ee.getCause() instanceof NotLeaderException);
    PowerMock.verifyAll();
}
Also used : RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) ExecutionException(java.util.concurrent.ExecutionException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with RestartRequest

use of org.apache.kafka.connect.runtime.RestartRequest in project kafka by apache.

the class KafkaConfigBackingStoreTest method testRecordToRestartRequestIncludeTasksInconsistent.

@Test
public void testRecordToRestartRequestIncludeTasksInconsistent() {
    ConsumerRecord<String, byte[]> record = new ConsumerRecord<>(TOPIC, 0, 0, 0L, TimestampType.CREATE_TIME, 0, 0, RESTART_CONNECTOR_KEYS.get(0), CONFIGS_SERIALIZED.get(0), new RecordHeaders(), Optional.empty());
    Struct struct = INLUDE_TASKS_MISSING_STRUCT;
    SchemaAndValue schemaAndValue = new SchemaAndValue(struct.schema(), structToMap(struct));
    RestartRequest restartRequest = configStorage.recordToRestartRequest(record, schemaAndValue);
    assertEquals(CONNECTOR_1_NAME, restartRequest.connectorName());
    assertFalse(restartRequest.includeTasks());
    assertEquals(struct.getBoolean(ONLY_FAILED_FIELD_NAME), restartRequest.onlyFailed());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Struct(org.apache.kafka.connect.data.Struct) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with RestartRequest

use of org.apache.kafka.connect.runtime.RestartRequest in project kafka by apache.

the class DistributedHerderTest method testDoRestartConnectorAndTasksNoAssignments.

@Test
public void testDoRestartConnectorAndTasksNoAssignments() {
    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();
    PowerMock.replayAll();
    herder.assignment = ExtendedAssignment.empty();
    herder.doRestartConnectorAndTasks(restartRequest);
    PowerMock.verifyAll();
}
Also used : 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 19 with RestartRequest

use of org.apache.kafka.connect.runtime.RestartRequest in project kafka by apache.

the class DistributedHerderTest method testRestartConnectorAndTasksUnknownConnector.

@Test
public void testRestartConnectorAndTasksUnknownConnector() throws Exception {
    String connectorName = "UnknownConnector";
    RestartRequest restartRequest = new RestartRequest(connectorName, false, true);
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    EasyMock.expect(member.currentProtocolVersion()).andStubReturn(CONNECT_PROTOCOL_V0);
    expectRebalance(1, Collections.emptyList(), Collections.emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // now handle the connector restart
    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    PowerMock.replayAll();
    herder.tick();
    FutureCallback<ConnectorStateInfo> callback = new FutureCallback<>();
    herder.restartConnectorAndTasks(restartRequest, callback);
    herder.tick();
    ExecutionException ee = assertThrows(ExecutionException.class, () -> callback.get(1000L, TimeUnit.MILLISECONDS));
    assertTrue(ee.getCause() instanceof NotFoundException);
    assertTrue(ee.getMessage().contains("Unknown connector:"));
    PowerMock.verifyAll();
}
Also used : RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with RestartRequest

use of org.apache.kafka.connect.runtime.RestartRequest in project kafka by apache.

the class DistributedHerderTest method testDoRestartConnectorAndTasksBoth.

@Test
public void testDoRestartConnectorAndTasksBoth() {
    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.singletonList(CONN1)).anyTimes();
    EasyMock.expect(herder.assignment.tasks()).andReturn(Collections.singletonList(taskId)).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();
    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) 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)

Aggregations

RestartRequest (org.apache.kafka.connect.runtime.RestartRequest)29 Test (org.junit.Test)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)13 FutureCallback (org.apache.kafka.connect.util.FutureCallback)13 RestartPlan (org.apache.kafka.connect.runtime.RestartPlan)10 Callback (org.apache.kafka.connect.util.Callback)9 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)7 Connector (org.apache.kafka.connect.connector.Connector)6 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)6 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)6 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)6 ExecutionException (java.util.concurrent.ExecutionException)5 Herder (org.apache.kafka.connect.runtime.Herder)5 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)5 SourceConnector (org.apache.kafka.connect.source.SourceConnector)5 TargetState (org.apache.kafka.connect.runtime.TargetState)4 HashMap (java.util.HashMap)3 Response (javax.ws.rs.core.Response)3 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)3