Search in sources :

Example 1 with ErrorReporter

use of org.apache.kafka.connect.runtime.errors.ErrorReporter in project kafka by apache.

the class ErrorHandlingTaskTest method testSourceTasksCloseErrorReporters.

@Test
public void testSourceTasksCloseErrorReporters() {
    ErrorReporter reporter = EasyMock.mock(ErrorReporter.class);
    RetryWithToleranceOperator retryWithToleranceOperator = operator();
    retryWithToleranceOperator.metrics(errorHandlingMetrics);
    retryWithToleranceOperator.reporters(singletonList(reporter));
    createSourceTask(initialState, retryWithToleranceOperator);
    expectClose();
    reporter.close();
    EasyMock.expectLastCall();
    PowerMock.replayAll();
    workerSourceTask.initialize(TASK_CONFIG);
    workerSourceTask.close();
    PowerMock.verifyAll();
}
Also used : ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) RetryWithToleranceOperator(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator) ParameterizedTest(org.apache.kafka.connect.util.ParameterizedTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ErrorReporter

use of org.apache.kafka.connect.runtime.errors.ErrorReporter in project kafka by apache.

the class ErrorHandlingTaskTest method testSinkTasksCloseErrorReporters.

@Test
public void testSinkTasksCloseErrorReporters() throws Exception {
    ErrorReporter reporter = EasyMock.mock(ErrorReporter.class);
    RetryWithToleranceOperator retryWithToleranceOperator = operator();
    retryWithToleranceOperator.metrics(errorHandlingMetrics);
    retryWithToleranceOperator.reporters(singletonList(reporter));
    createSinkTask(initialState, retryWithToleranceOperator);
    expectInitializeTask();
    reporter.close();
    EasyMock.expectLastCall();
    sinkTask.stop();
    EasyMock.expectLastCall();
    consumer.close();
    EasyMock.expectLastCall();
    PowerMock.replayAll();
    workerSinkTask.initialize(TASK_CONFIG);
    workerSinkTask.initializeAndStart();
    workerSinkTask.close();
    PowerMock.verifyAll();
}
Also used : ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) RetryWithToleranceOperator(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator) ParameterizedTest(org.apache.kafka.connect.util.ParameterizedTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ErrorReporter

use of org.apache.kafka.connect.runtime.errors.ErrorReporter in project kafka by apache.

the class ErrorHandlingTaskTest method testCloseErrorReportersExceptionPropagation.

@Test
public void testCloseErrorReportersExceptionPropagation() {
    ErrorReporter reporterA = EasyMock.mock(ErrorReporter.class);
    ErrorReporter reporterB = EasyMock.mock(ErrorReporter.class);
    RetryWithToleranceOperator retryWithToleranceOperator = operator();
    retryWithToleranceOperator.metrics(errorHandlingMetrics);
    retryWithToleranceOperator.reporters(Arrays.asList(reporterA, reporterB));
    createSourceTask(initialState, retryWithToleranceOperator);
    expectClose();
    // Even though the reporters throw exceptions, they should both still be closed.
    reporterA.close();
    EasyMock.expectLastCall().andThrow(new RuntimeException());
    reporterB.close();
    EasyMock.expectLastCall().andThrow(new RuntimeException());
    PowerMock.replayAll();
    workerSourceTask.initialize(TASK_CONFIG);
    workerSourceTask.close();
    PowerMock.verifyAll();
}
Also used : ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) RetryWithToleranceOperator(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator) ParameterizedTest(org.apache.kafka.connect.util.ParameterizedTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ErrorReporter

use of org.apache.kafka.connect.runtime.errors.ErrorReporter in project kafka by apache.

the class Worker method sinkTaskReporters.

private List<ErrorReporter> sinkTaskReporters(ConnectorTaskId id, SinkConnectorConfig connConfig, ErrorHandlingMetrics errorHandlingMetrics, Class<? extends Connector> connectorClass) {
    ArrayList<ErrorReporter> reporters = new ArrayList<>();
    LogReporter logReporter = new LogReporter(id, connConfig, errorHandlingMetrics);
    reporters.add(logReporter);
    // check if topic for dead letter queue exists
    String topic = connConfig.dlqTopicName();
    if (topic != null && !topic.isEmpty()) {
        Map<String, Object> producerProps = producerConfigs(id, "connector-dlq-producer-" + id, config, connConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId);
        Map<String, Object> adminProps = adminConfigs(id, "connector-dlq-adminclient-", config, connConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId);
        DeadLetterQueueReporter reporter = DeadLetterQueueReporter.createAndSetup(adminProps, id, connConfig, producerProps, errorHandlingMetrics);
        reporters.add(reporter);
    }
    return reporters;
}
Also used : ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) DeadLetterQueueReporter(org.apache.kafka.connect.runtime.errors.DeadLetterQueueReporter) ArrayList(java.util.ArrayList) LogReporter(org.apache.kafka.connect.runtime.errors.LogReporter)

Example 5 with ErrorReporter

use of org.apache.kafka.connect.runtime.errors.ErrorReporter in project kafka by apache.

the class Worker method sourceTaskReporters.

private List<ErrorReporter> sourceTaskReporters(ConnectorTaskId id, ConnectorConfig connConfig, ErrorHandlingMetrics errorHandlingMetrics) {
    List<ErrorReporter> reporters = new ArrayList<>();
    LogReporter logReporter = new LogReporter(id, connConfig, errorHandlingMetrics);
    reporters.add(logReporter);
    return reporters;
}
Also used : ErrorReporter(org.apache.kafka.connect.runtime.errors.ErrorReporter) ArrayList(java.util.ArrayList) LogReporter(org.apache.kafka.connect.runtime.errors.LogReporter)

Aggregations

ErrorReporter (org.apache.kafka.connect.runtime.errors.ErrorReporter)5 RetryWithToleranceOperator (org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator)3 ParameterizedTest (org.apache.kafka.connect.util.ParameterizedTest)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 ArrayList (java.util.ArrayList)2 LogReporter (org.apache.kafka.connect.runtime.errors.LogReporter)2 DeadLetterQueueReporter (org.apache.kafka.connect.runtime.errors.DeadLetterQueueReporter)1