use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.
the class AbstractHerderTest method taskStatus.
@Test
public void taskStatus() {
ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
String workerId = "workerId";
AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
EasyMock.expect(herder.generation()).andStubReturn(5);
final Capture<TaskStatus> statusCapture = EasyMock.newCapture();
statusStore.putSafe(EasyMock.capture(statusCapture));
EasyMock.expectLastCall();
EasyMock.expect(statusStore.get(taskId)).andAnswer(statusCapture::getValue);
replayAll();
herder.onFailure(taskId, new RuntimeException());
ConnectorStateInfo.TaskState taskState = herder.taskStatus(taskId);
assertEquals(workerId, taskState.workerId());
assertEquals("FAILED", taskState.state());
assertEquals(0, taskState.id());
assertNotNull(taskState.trace());
verifyAll();
}
use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.
the class AbstractHerderTest method testConfigValidationPredicatesExtendResults.
@Test()
public void testConfigValidationPredicatesExtendResults() {
AbstractHerder herder = createConfigValidationHerder(TestSourceConnector.class, noneConnectorClientConfigOverridePolicy);
// 2 transform aliases defined -> 2 plugin lookups
Set<PluginDesc<Transformation<?>>> transformations = new HashSet<>();
transformations.add(transformationPluginDesc());
EasyMock.expect(plugins.transformations()).andReturn(transformations).times(1);
Set<PluginDesc<Predicate<?>>> predicates = new HashSet<>();
predicates.add(predicatePluginDesc());
EasyMock.expect(plugins.predicates()).andReturn(predicates).times(2);
replayAll();
// Define 2 transformations. One has a class defined and so can get embedded configs, the other is missing
// class info that should generate an error.
Map<String, String> config = new HashMap<>();
config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, TestSourceConnector.class.getName());
config.put(ConnectorConfig.NAME_CONFIG, "connector-name");
config.put(ConnectorConfig.TRANSFORMS_CONFIG, "xformA");
config.put(ConnectorConfig.TRANSFORMS_CONFIG + ".xformA.type", SampleTransformation.class.getName());
config.put(ConnectorConfig.TRANSFORMS_CONFIG + ".xformA.predicate", "predX");
config.put(ConnectorConfig.PREDICATES_CONFIG, "predX,predY");
config.put(ConnectorConfig.PREDICATES_CONFIG + ".predX.type", SamplePredicate.class.getName());
// connector required config
config.put("required", "value");
ConfigInfos result = herder.validateConnectorConfig(config, false);
assertEquals(herder.connectorTypeForClass(config.get(ConnectorConfig.CONNECTOR_CLASS_CONFIG)), ConnectorType.SOURCE);
// We expect there to be errors due to the missing name and .... Note that these assertions depend heavily on
// the config fields for SourceConnectorConfig, but we expect these to change rarely.
assertEquals(TestSourceConnector.class.getName(), result.name());
// Each transform also gets its own group
List<String> expectedGroups = Arrays.asList(ConnectorConfig.COMMON_GROUP, ConnectorConfig.TRANSFORMS_GROUP, ConnectorConfig.PREDICATES_GROUP, ConnectorConfig.ERROR_GROUP, SourceConnectorConfig.TOPIC_CREATION_GROUP, "Transforms: xformA", "Predicates: predX", "Predicates: predY");
assertEquals(expectedGroups, result.groups());
assertEquals(2, result.errorCount());
Map<String, ConfigInfo> infos = result.values().stream().collect(Collectors.toMap(info -> info.configKey().name(), Function.identity()));
assertEquals(24, infos.size());
// Should get 2 type fields from the transforms, first adds its own config since it has a valid class
assertEquals("transforms.xformA.type", infos.get("transforms.xformA.type").configValue().name());
assertTrue(infos.get("transforms.xformA.type").configValue().errors().isEmpty());
assertEquals("transforms.xformA.subconfig", infos.get("transforms.xformA.subconfig").configValue().name());
assertEquals("transforms.xformA.predicate", infos.get("transforms.xformA.predicate").configValue().name());
assertTrue(infos.get("transforms.xformA.predicate").configValue().errors().isEmpty());
assertEquals("transforms.xformA.negate", infos.get("transforms.xformA.negate").configValue().name());
assertTrue(infos.get("transforms.xformA.negate").configValue().errors().isEmpty());
assertEquals("predicates.predX.type", infos.get("predicates.predX.type").configValue().name());
assertEquals("predicates.predX.predconfig", infos.get("predicates.predX.predconfig").configValue().name());
assertEquals("predicates.predY.type", infos.get("predicates.predY.type").configValue().name());
assertFalse(infos.get("predicates.predY.type").configValue().errors().isEmpty());
verifyAll();
}
use of org.apache.kafka.connect.connector.policy.NoneConnectorClientConfigOverridePolicy in project kafka by apache.
the class AbstractHerderTest method testBuildRestartPlanForNoRestart.
@Test
public void testBuildRestartPlanForNoRestart() {
RestartRequest restartRequest = new RestartRequest(connector, true, false);
ConnectorTaskId taskId1 = new ConnectorTaskId(connector, 1);
ConnectorTaskId taskId2 = new ConnectorTaskId(connector, 2);
List<TaskStatus> taskStatuses = new ArrayList<>();
taskStatuses.add(new TaskStatus(taskId1, AbstractStatus.State.RUNNING, workerId, generation));
taskStatuses.add(new TaskStatus(taskId2, AbstractStatus.State.FAILED, workerId, generation));
AbstractHerder herder = partialMockBuilder(AbstractHerder.class).withConstructor(Worker.class, String.class, String.class, StatusBackingStore.class, ConfigBackingStore.class, ConnectorClientConfigOverridePolicy.class).withArgs(worker, workerId, kafkaClusterId, statusStore, configStore, noneConnectorClientConfigOverridePolicy).addMockedMethod("generation").createMock();
EasyMock.expect(herder.generation()).andStubReturn(generation);
EasyMock.expect(herder.rawConfig(connector)).andReturn(null);
EasyMock.expect(statusStore.get(connector)).andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));
EasyMock.expect(statusStore.getAll(connector)).andReturn(taskStatuses);
EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
replayAll();
Optional<RestartPlan> mayBeRestartPlan = herder.buildRestartPlan(restartRequest);
assertTrue(mayBeRestartPlan.isPresent());
RestartPlan restartPlan = mayBeRestartPlan.get();
assertFalse(restartPlan.shouldRestartConnector());
assertFalse(restartPlan.shouldRestartTasks());
assertTrue(restartPlan.taskIdsToRestart().isEmpty());
PowerMock.verifyAll();
}
Aggregations