Search in sources :

Example 26 with RestartRequest

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

the class StandaloneHerderTest method testRestartConnectorAndTasksOnlyConnector.

@Test
public void testRestartConnectorAndTasksOnlyConnector() throws Exception {
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, false, true);
    RestartPlan restartPlan = PowerMock.createMock(RestartPlan.class);
    ConnectorStateInfo connectorStateInfo = PowerMock.createMock(ConnectorStateInfo.class);
    EasyMock.expect(restartPlan.shouldRestartConnector()).andReturn(true).anyTimes();
    EasyMock.expect(restartPlan.shouldRestartTasks()).andReturn(false).anyTimes();
    EasyMock.expect(restartPlan.restartConnectorStateInfo()).andReturn(connectorStateInfo).anyTimes();
    EasyMock.expect(herder.buildRestartPlan(restartRequest)).andReturn(Optional.of(restartPlan)).anyTimes();
    herder.onRestart(CONNECTOR_NAME);
    EasyMock.expectLastCall();
    connector = PowerMock.createMock(BogusSinkConnector.class);
    expectAdd(SourceSink.SINK);
    Map<String, String> connectorConfig = connectorConfig(SourceSink.SINK);
    Connector connectorMock = PowerMock.createMock(SinkConnector.class);
    expectConfigValidation(connectorMock, true, connectorConfig);
    worker.stopAndAwaitConnector(CONNECTOR_NAME);
    EasyMock.expectLastCall();
    Capture<Callback<TargetState>> onStart = EasyMock.newCapture();
    worker.startConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(connectorConfig), EasyMock.anyObject(HerderConnectorContext.class), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED), EasyMock.capture(onStart));
    EasyMock.expectLastCall().andAnswer(() -> {
        onStart.getValue().onCompletion(null, TargetState.STARTED);
        return true;
    });
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, connectorConfig, false, createCallback);
    Herder.Created<ConnectorInfo> connectorInfo = createCallback.get(1000L, TimeUnit.SECONDS);
    assertEquals(createdInfo(SourceSink.SINK), connectorInfo.result());
    FutureCallback<ConnectorStateInfo> restartCallback = new FutureCallback<>();
    herder.restartConnectorAndTasks(restartRequest, restartCallback);
    assertEquals(connectorStateInfo, restartCallback.get(1000L, TimeUnit.MILLISECONDS));
    PowerMock.verifyAll();
}
Also used : SourceConnector(org.apache.kafka.connect.source.SourceConnector) WorkerConnector(org.apache.kafka.connect.runtime.WorkerConnector) Connector(org.apache.kafka.connect.connector.Connector) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Callback(org.apache.kafka.connect.util.Callback) RestartPlan(org.apache.kafka.connect.runtime.RestartPlan) HerderConnectorContext(org.apache.kafka.connect.runtime.HerderConnectorContext) Herder(org.apache.kafka.connect.runtime.Herder) 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 27 with RestartRequest

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

the class ConnectorsResourceTest method testRestartConnectorAndTasksConnectorNotFound.

@Test
public void testRestartConnectorAndTasksConnectorNotFound() {
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, true, false);
    final Capture<Callback<ConnectorStateInfo>> cb = Capture.newInstance();
    herder.restartConnectorAndTasks(EasyMock.eq(restartRequest), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    assertThrows(NotFoundException.class, () -> connectorsResource.restartConnector(CONNECTOR_NAME, NULL_HEADERS, restartRequest.includeTasks(), restartRequest.onlyFailed(), FORWARD));
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with RestartRequest

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

the class ConnectorsResourceTest method testRestartConnectorAndTasksRequestAccepted.

@Test
public void testRestartConnectorAndTasksRequestAccepted() throws Throwable {
    ConnectorStateInfo.ConnectorState state = new ConnectorStateInfo.ConnectorState(AbstractStatus.State.RESTARTING.name(), "foo", null);
    ConnectorStateInfo connectorStateInfo = new ConnectorStateInfo(CONNECTOR_NAME, state, Collections.emptyList(), ConnectorType.SOURCE);
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, true, false);
    final Capture<Callback<ConnectorStateInfo>> cb = Capture.newInstance();
    herder.restartConnectorAndTasks(EasyMock.eq(restartRequest), EasyMock.capture(cb));
    expectAndCallbackResult(cb, connectorStateInfo);
    PowerMock.replayAll();
    Response response = connectorsResource.restartConnector(CONNECTOR_NAME, NULL_HEADERS, restartRequest.includeTasks(), restartRequest.onlyFailed(), FORWARD);
    assertEquals(CONNECTOR_NAME, ((ConnectorStateInfo) response.getEntity()).name());
    assertEquals(state.state(), ((ConnectorStateInfo) response.getEntity()).connector().state());
    assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
    PowerMock.verifyAll();
}
Also used : Response(javax.ws.rs.core.Response) Callback(org.apache.kafka.connect.util.Callback) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with RestartRequest

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

the class ConnectorsResourceTest method testRestartConnectorAndTasksRebalanceNeeded.

@Test
public void testRestartConnectorAndTasksRebalanceNeeded() {
    RestartRequest restartRequest = new RestartRequest(CONNECTOR_NAME, true, false);
    final Capture<Callback<ConnectorStateInfo>> cb = Capture.newInstance();
    herder.restartConnectorAndTasks(EasyMock.eq(restartRequest), EasyMock.capture(cb));
    expectAndCallbackException(cb, new RebalanceNeededException("Request cannot be completed because a rebalance is expected"));
    PowerMock.replayAll();
    ConnectRestException ex = assertThrows(ConnectRestException.class, () -> connectorsResource.restartConnector(CONNECTOR_NAME, NULL_HEADERS, restartRequest.includeTasks(), restartRequest.onlyFailed(), FORWARD));
    assertEquals(Response.Status.CONFLICT.getStatusCode(), ex.statusCode());
    PowerMock.verifyAll();
}
Also used : ConnectRestException(org.apache.kafka.connect.runtime.rest.errors.ConnectRestException) Callback(org.apache.kafka.connect.util.Callback) RebalanceNeededException(org.apache.kafka.connect.runtime.distributed.RebalanceNeededException) 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