Search in sources :

Example 46 with FutureCallback

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

the class StandaloneHerderTest method testRestartConnector.

@Test
public void testRestartConnector() throws Exception {
    expectAdd(SourceSink.SOURCE);
    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, config);
    worker.stopAndAwaitConnector(CONNECTOR_NAME);
    EasyMock.expectLastCall();
    Capture<Callback<TargetState>> onStart = EasyMock.newCapture();
    worker.startConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(config), 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, config, false, createCallback);
    Herder.Created<ConnectorInfo> connectorInfo = createCallback.get(1000L, TimeUnit.SECONDS);
    assertEquals(createdInfo(SourceSink.SOURCE), connectorInfo.result());
    FutureCallback<Void> restartCallback = new FutureCallback<>();
    herder.restartConnector(CONNECTOR_NAME, restartCallback);
    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) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) HerderConnectorContext(org.apache.kafka.connect.runtime.HerderConnectorContext) Herder(org.apache.kafka.connect.runtime.Herder) FutureCallback(org.apache.kafka.connect.util.FutureCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FutureCallback (org.apache.kafka.connect.util.FutureCallback)46 Test (org.junit.Test)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)24 Herder (org.apache.kafka.connect.runtime.Herder)23 Connector (org.apache.kafka.connect.connector.Connector)18 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)18 SourceConnector (org.apache.kafka.connect.source.SourceConnector)18 ExecutionException (java.util.concurrent.ExecutionException)17 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)17 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)13 HashMap (java.util.HashMap)11 Path (javax.ws.rs.Path)11 RestartRequest (org.apache.kafka.connect.runtime.RestartRequest)11 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)11 Map (java.util.Map)9 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)9 POST (javax.ws.rs.POST)7 ConnectException (org.apache.kafka.connect.errors.ConnectException)7 URI (java.net.URI)6