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