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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations