Search in sources :

Example 1 with CreateConnectorRequest

use of org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest 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 2 with CreateConnectorRequest

use of org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest 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 3 with CreateConnectorRequest

use of org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest in project kafka by apache.

the class ConnectorsResourceTest method testCreateConnectorNotLeader.

@Test
public void testCreateConnectorNotLeader() 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));
    expectAndCallbackNotLeaderException(cb);
    // Should forward request
    EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors?forward=false"), EasyMock.eq("POST"), EasyMock.eq(body), EasyMock.<TypeReference>anyObject())).andReturn(new RestServer.HttpResponse<>(201, new HashMap<String, List<String>>(), new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));
    PowerMock.replayAll();
    connectorsResource.createConnector(FORWARD, body);
    PowerMock.verifyAll();
}
Also used : RestServer(org.apache.kafka.connect.runtime.rest.RestServer) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) HashMap(java.util.HashMap) 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 4 with CreateConnectorRequest

use of org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest in project kafka by apache.

the class ConnectorsResourceTest method testCreateConnector.

@Test
public void testCreateConnector() 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));
    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)

Aggregations

Herder (org.apache.kafka.connect.runtime.Herder)4 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)4 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)4 Callback (org.apache.kafka.connect.util.Callback)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)1 AlreadyExistsException (org.apache.kafka.connect.errors.AlreadyExistsException)1 RestServer (org.apache.kafka.connect.runtime.rest.RestServer)1