Search in sources :

Example 1 with AuthorizationException

use of org.apache.kafka.common.errors.AuthorizationException in project kafka by apache.

the class AbstractTaskTest method shouldThrowProcessorStateExceptionOnInitializeOffsetsWhenAuthorizationException.

@Test(expected = ProcessorStateException.class)
public void shouldThrowProcessorStateExceptionOnInitializeOffsetsWhenAuthorizationException() throws Exception {
    final Consumer consumer = mockConsumer(new AuthorizationException("blah"));
    final AbstractTask task = createTask(consumer);
    task.initializeOffsetLimits();
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) AuthorizationException(org.apache.kafka.common.errors.AuthorizationException) Test(org.junit.Test)

Example 2 with AuthorizationException

use of org.apache.kafka.common.errors.AuthorizationException in project kafka by apache.

the class AbstractTask method initializeOffsetLimits.

protected void initializeOffsetLimits() {
    for (TopicPartition partition : partitions) {
        try {
            // TODO: batch API?
            OffsetAndMetadata metadata = consumer.committed(partition);
            stateMgr.putOffsetLimit(partition, metadata != null ? metadata.offset() : 0L);
        } catch (AuthorizationException e) {
            throw new ProcessorStateException(String.format("task [%s] AuthorizationException when initializing offsets for %s", id, partition), e);
        } catch (WakeupException e) {
            throw e;
        } catch (KafkaException e) {
            throw new ProcessorStateException(String.format("task [%s] Failed to initialize offsets for %s", id, partition), e);
        }
    }
}
Also used : AuthorizationException(org.apache.kafka.common.errors.AuthorizationException) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) KafkaException(org.apache.kafka.common.KafkaException) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) WakeupException(org.apache.kafka.common.errors.WakeupException)

Aggregations

AuthorizationException (org.apache.kafka.common.errors.AuthorizationException)2 Consumer (org.apache.kafka.clients.consumer.Consumer)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 KafkaException (org.apache.kafka.common.KafkaException)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 WakeupException (org.apache.kafka.common.errors.WakeupException)1 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)1 Test (org.junit.Test)1