Search in sources :

Example 36 with ConnectorInfo

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

the class ConnectorsResourceTest method testExpandConnectorsInfo.

@Test
public void testExpandConnectorsInfo() {
    EasyMock.expect(herder.connectors()).andReturn(Arrays.asList(CONNECTOR2_NAME, CONNECTOR_NAME));
    ConnectorInfo connector = EasyMock.mock(ConnectorInfo.class);
    ConnectorInfo connector2 = EasyMock.mock(ConnectorInfo.class);
    EasyMock.expect(herder.connectorInfo(CONNECTOR2_NAME)).andReturn(connector2);
    EasyMock.expect(herder.connectorInfo(CONNECTOR_NAME)).andReturn(connector);
    forward = EasyMock.mock(UriInfo.class);
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.putSingle("expand", "info");
    EasyMock.expect(forward.getQueryParameters()).andReturn(queryParams).anyTimes();
    EasyMock.replay(forward);
    PowerMock.replayAll();
    Map<String, Map<String, Object>> expanded = (Map<String, Map<String, Object>>) connectorsResource.listConnectors(forward, NULL_HEADERS).getEntity();
    // Ordering isn't guaranteed, compare sets
    assertEquals(new HashSet<>(Arrays.asList(CONNECTOR_NAME, CONNECTOR2_NAME)), expanded.keySet());
    assertEquals(connector2, expanded.get(CONNECTOR2_NAME).get("info"));
    assertEquals(connector, expanded.get(CONNECTOR_NAME).get("info"));
    PowerMock.verifyAll();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Map(java.util.Map) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) UriInfo(javax.ws.rs.core.UriInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with ConnectorInfo

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

the class ConnectorsResourceTest method testFullExpandConnectors.

@Test
public void testFullExpandConnectors() {
    EasyMock.expect(herder.connectors()).andReturn(Arrays.asList(CONNECTOR2_NAME, CONNECTOR_NAME));
    ConnectorInfo connectorInfo = EasyMock.mock(ConnectorInfo.class);
    ConnectorInfo connectorInfo2 = EasyMock.mock(ConnectorInfo.class);
    EasyMock.expect(herder.connectorInfo(CONNECTOR2_NAME)).andReturn(connectorInfo2);
    EasyMock.expect(herder.connectorInfo(CONNECTOR_NAME)).andReturn(connectorInfo);
    ConnectorStateInfo connector = EasyMock.mock(ConnectorStateInfo.class);
    ConnectorStateInfo connector2 = EasyMock.mock(ConnectorStateInfo.class);
    EasyMock.expect(herder.connectorStatus(CONNECTOR2_NAME)).andReturn(connector2);
    EasyMock.expect(herder.connectorStatus(CONNECTOR_NAME)).andReturn(connector);
    forward = EasyMock.mock(UriInfo.class);
    MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
    queryParams.put("expand", Arrays.asList("info", "status"));
    EasyMock.expect(forward.getQueryParameters()).andReturn(queryParams).anyTimes();
    EasyMock.replay(forward);
    PowerMock.replayAll();
    Map<String, Map<String, Object>> expanded = (Map<String, Map<String, Object>>) connectorsResource.listConnectors(forward, NULL_HEADERS).getEntity();
    // Ordering isn't guaranteed, compare sets
    assertEquals(new HashSet<>(Arrays.asList(CONNECTOR_NAME, CONNECTOR2_NAME)), expanded.keySet());
    assertEquals(connectorInfo2, expanded.get(CONNECTOR2_NAME).get("info"));
    assertEquals(connectorInfo, expanded.get(CONNECTOR_NAME).get("info"));
    assertEquals(connector2, expanded.get(CONNECTOR2_NAME).get("status"));
    assertEquals(connector, expanded.get(CONNECTOR_NAME).get("status"));
    PowerMock.verifyAll();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Map(java.util.Map) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) UriInfo(javax.ws.rs.core.UriInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with ConnectorInfo

use of org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo 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, ConnectorType.SOURCE));
    PowerMock.replayAll();
    ConnectorInfo connInfo = connectorsResource.getConnector(CONNECTOR_NAME, NULL_HEADERS, FORWARD);
    assertEquals(new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE), 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)

Example 39 with ConnectorInfo

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

the class ConnectorsResourceTest method testCompleteOrForwardWithErrorAndNoForwardUrl.

@Test
public void testCompleteOrForwardWithErrorAndNoForwardUrl() {
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.deleteConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    String leaderUrl = null;
    expectAndCallbackException(cb, new NotLeaderException("not leader", leaderUrl));
    PowerMock.replayAll();
    ConnectRestException e = assertThrows(ConnectRestException.class, () -> connectorsResource.destroyConnector(CONNECTOR_NAME, NULL_HEADERS, FORWARD));
    assertTrue(e.getMessage().contains("no known leader URL"));
    PowerMock.verifyAll();
}
Also used : ConnectRestException(org.apache.kafka.connect.runtime.rest.errors.ConnectRestException) NotLeaderException(org.apache.kafka.connect.runtime.distributed.NotLeaderException) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with ConnectorInfo

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

the class ConnectorsResourceTest method testCreateConnectorExists.

@Test
public void testCreateConnectorExists() {
    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();
    assertThrows(AlreadyExistsException.class, () -> connectorsResource.createConnector(FORWARD, NULL_HEADERS, 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)

Aggregations

ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)78 Herder (org.apache.kafka.connect.runtime.Herder)65 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)61 Callback (org.apache.kafka.connect.util.Callback)35 Connector (org.apache.kafka.connect.connector.Connector)28 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)28 SourceConnector (org.apache.kafka.connect.source.SourceConnector)28 FutureCallback (org.apache.kafka.connect.util.FutureCallback)25 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)20 CreateConnectorRequest (org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest)19 HashMap (java.util.HashMap)17 URI (java.net.URI)13 Map (java.util.Map)13 ConnectorConfig (org.apache.kafka.connect.runtime.ConnectorConfig)11 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)11 Config (org.apache.kafka.common.config.Config)10 ConfigDef (org.apache.kafka.common.config.ConfigDef)10 ConfigValue (org.apache.kafka.common.config.ConfigValue)10 TaskConfig (org.apache.kafka.connect.runtime.TaskConfig)10