Search in sources :

Example 26 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class DistributedHerderTest method testRestartUnknownTask.

@Test
public void testRestartUnknownTask() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>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)

Example 27 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testDeleteConnectorNotFound.

// Not found exceptions should pass through to caller so they can be processed for 404s
@Test(expected = NotFoundException.class)
public void testDeleteConnectorNotFound() throws Throwable {
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.deleteConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.destroyConnector(CONNECTOR_NAME, FORWARD);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testPutConnectorTaskConfigsConnectorNotFound.

@Test(expected = NotFoundException.class)
public void testPutConnectorTaskConfigsConnectorNotFound() throws Throwable {
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.putTaskConfigs(CONNECTOR_NAME, FORWARD, TASK_CONFIGS);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class ConnectorsResourceTest method testRestartTaskNotFound.

@Test(expected = NotFoundException.class)
public void testRestartTaskNotFound() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));
    PowerMock.replayAll();
    connectorsResource.restartTask(CONNECTOR_NAME, 0, FORWARD);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with NotFoundException

use of org.apache.kafka.connect.errors.NotFoundException in project apache-kafka-on-k8s by banzaicloud.

the class StandaloneHerderTest method testDestroyConnector.

@Test
public void testDestroyConnector() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    expectAdd(SourceSink.SOURCE);
    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(SourceConnector.class);
    expectConfigValidation(connectorMock, true, config);
    EasyMock.expect(statusBackingStore.getAll(CONNECTOR_NAME)).andReturn(Collections.<TaskStatus>emptyList());
    statusBackingStore.put(new ConnectorStatus(CONNECTOR_NAME, AbstractStatus.State.DESTROYED, WORKER_ID, 0));
    expectDestroy();
    PowerMock.replayAll();
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    FutureCallback<Herder.Created<ConnectorInfo>> futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    futureCb.get(1000L, TimeUnit.MILLISECONDS);
    // Second deletion should fail since the connector is gone
    futureCb = new FutureCallback<>();
    herder.deleteConnectorConfig(CONNECTOR_NAME, futureCb);
    try {
        futureCb.get(1000L, TimeUnit.MILLISECONDS);
        fail("Should have thrown NotFoundException");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }
    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) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) 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

NotFoundException (org.apache.kafka.connect.errors.NotFoundException)48 Test (org.junit.Test)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 Callback (org.apache.kafka.connect.util.Callback)14 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 ConnectException (org.apache.kafka.connect.errors.ConnectException)9 ExecutionException (java.util.concurrent.ExecutionException)8 FutureCallback (org.apache.kafka.connect.util.FutureCallback)8 ArrayList (java.util.ArrayList)7 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)7 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)6 TaskInfo (org.apache.kafka.connect.runtime.rest.entities.TaskInfo)6 NoSuchElementException (java.util.NoSuchElementException)5 TimeoutException (java.util.concurrent.TimeoutException)5 WakeupException (org.apache.kafka.common.errors.WakeupException)5 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)5 RestartRequest (org.apache.kafka.connect.runtime.RestartRequest)5 Herder (org.apache.kafka.connect.runtime.Herder)4 BadRequestException (org.apache.kafka.connect.runtime.rest.errors.BadRequestException)4 Connector (org.apache.kafka.connect.connector.Connector)3