Search in sources :

Example 6 with Callback

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

the class ConnectorsResourceTest method testCreateConnectorWithASlashInItsName.

@Test(expected = BadRequestException.class)
public void testCreateConnectorWithASlashInItsName() throws Throwable {
    String badConnectorName = CONNECTOR_NAME + "/" + "test";
    CreateConnectorRequest body = new CreateConnectorRequest(badConnectorName, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, badConnectorName));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, body);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Callback

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

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 8 with Callback

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

the class ConnectorsResourceTest method testRestartTaskOwnerRedirect.

@Test
public void testRestartTaskOwnerRedirect() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    String ownerUrl = "http://owner:8083";
    expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));
    EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=false"), EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject())).andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));
    PowerMock.replayAll();
    connectorsResource.restartTask(CONNECTOR_NAME, 0, true);
    PowerMock.verifyAll();
}
Also used : RestServer(org.apache.kafka.connect.runtime.rest.RestServer) Callback(org.apache.kafka.connect.util.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) HashMap(java.util.HashMap) NotAssignedException(org.apache.kafka.connect.runtime.distributed.NotAssignedException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Callback

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

the class ConnectorsResourceTest method testCreateConnectorExists.

@Test(expected = AlreadyExistsException.class)
public void testCreateConnectorExists() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackException(cb, new AlreadyExistsException("already exists"));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, body);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with Callback

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

the class ConnectorsResourceTest method testGetConnector.

@Test
public void testGetConnector() throws Throwable {
    final Capture<Callback<ConnectorInfo>> cb = Capture.newInstance();
    herder.connectorInfo(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES));
    PowerMock.replayAll();
    ConnectorInfo connInfo = connectorsResource.getConnector(CONNECTOR_NAME, FORWARD);
    assertEquals(new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES), connInfo);
    PowerMock.verifyAll();
}
Also used : Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Callback (org.apache.kafka.connect.util.Callback)20 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 HashMap (java.util.HashMap)8 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)6 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)6 Herder (org.apache.kafka.connect.runtime.Herder)5 RestServer (org.apache.kafka.connect.runtime.rest.RestServer)4 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)4 ByteBuffer (java.nio.ByteBuffer)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)3 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)3 Map (java.util.Map)2 NotAssignedException (org.apache.kafka.connect.runtime.distributed.NotAssignedException)2 ExecutionException (java.util.concurrent.ExecutionException)1 Response (javax.ws.rs.core.Response)1 KafkaException (org.apache.kafka.common.KafkaException)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 ByteArrayDeserializer (org.apache.kafka.common.serialization.ByteArrayDeserializer)1