Search in sources :

Example 6 with GroupAuthorizationException

use of org.apache.kafka.common.errors.GroupAuthorizationException in project rest-utils by confluentinc.

the class KafkaExceptionMapperTest method testAuthorizationExceptions.

@Test
public void testAuthorizationExceptions() {
    verifyMapperResponse(new AuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
    verifyMapperResponse(new ClusterAuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
    verifyMapperResponse(new DelegationTokenAuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
    verifyMapperResponse(new GroupAuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
    verifyMapperResponse(new TopicAuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
    verifyMapperResponse(new TransactionalIdAuthorizationException("some message"), Status.FORBIDDEN, KAFKA_AUTHORIZATION_ERROR_CODE);
}
Also used : TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) DelegationTokenAuthorizationException(org.apache.kafka.common.errors.DelegationTokenAuthorizationException) AuthorizationException(org.apache.kafka.common.errors.AuthorizationException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) DelegationTokenAuthorizationException(org.apache.kafka.common.errors.DelegationTokenAuthorizationException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Test(org.junit.jupiter.api.Test)

Example 7 with GroupAuthorizationException

use of org.apache.kafka.common.errors.GroupAuthorizationException in project apache-kafka-on-k8s by banzaicloud.

the class TransactionManagerTest method testGroupAuthorizationFailureInTxnOffsetCommit.

@Test
public void testGroupAuthorizationFailureInTxnOffsetCommit() {
    final String consumerGroupId = "consumer";
    final long pid = 13131L;
    final short epoch = 1;
    final TopicPartition tp = new TopicPartition("foo", 0);
    doInitTransactions(pid, epoch);
    transactionManager.beginTransaction();
    TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp, new OffsetAndMetadata(39L)), consumerGroupId);
    prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, pid, epoch);
    // AddOffsetsToTxn Handled, TxnOffsetCommit Enqueued
    sender.run(time.milliseconds());
    // FindCoordinator Enqueued
    sender.run(time.milliseconds());
    prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.GROUP, consumerGroupId);
    // FindCoordinator Returned
    sender.run(time.milliseconds());
    prepareTxnOffsetCommitResponse(consumerGroupId, pid, epoch, singletonMap(tp, Errors.GROUP_AUTHORIZATION_FAILED));
    // TxnOffsetCommit Handled
    sender.run(time.milliseconds());
    assertTrue(transactionManager.hasError());
    assertTrue(transactionManager.lastError() instanceof GroupAuthorizationException);
    assertTrue(sendOffsetsResult.isCompleted());
    assertFalse(sendOffsetsResult.isSuccessful());
    assertTrue(sendOffsetsResult.error() instanceof GroupAuthorizationException);
    GroupAuthorizationException exception = (GroupAuthorizationException) sendOffsetsResult.error();
    assertEquals(consumerGroupId, exception.groupId());
    assertAbortableError(GroupAuthorizationException.class);
}
Also used : GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Test(org.junit.Test)

Example 8 with GroupAuthorizationException

use of org.apache.kafka.common.errors.GroupAuthorizationException in project apache-kafka-on-k8s by banzaicloud.

the class TransactionManagerTest method testGroupAuthorizationFailureInFindCoordinator.

@Test
public void testGroupAuthorizationFailureInFindCoordinator() {
    final String consumerGroupId = "consumer";
    final long pid = 13131L;
    final short epoch = 1;
    doInitTransactions(pid, epoch);
    transactionManager.beginTransaction();
    TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(new TopicPartition("foo", 0), new OffsetAndMetadata(39L)), consumerGroupId);
    prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, pid, epoch);
    // AddOffsetsToTxn Handled, TxnOffsetCommit Enqueued
    sender.run(time.milliseconds());
    // FindCoordinator Enqueued
    sender.run(time.milliseconds());
    prepareFindCoordinatorResponse(Errors.GROUP_AUTHORIZATION_FAILED, false, CoordinatorType.GROUP, consumerGroupId);
    // FindCoordinator Failed
    sender.run(time.milliseconds());
    // TxnOffsetCommit Aborted
    sender.run(time.milliseconds());
    assertTrue(transactionManager.hasError());
    assertTrue(transactionManager.lastError() instanceof GroupAuthorizationException);
    assertTrue(sendOffsetsResult.isCompleted());
    assertFalse(sendOffsetsResult.isSuccessful());
    assertTrue(sendOffsetsResult.error() instanceof GroupAuthorizationException);
    GroupAuthorizationException exception = (GroupAuthorizationException) sendOffsetsResult.error();
    assertEquals(consumerGroupId, exception.groupId());
    assertAbortableError(GroupAuthorizationException.class);
}
Also used : GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Test(org.junit.Test)

Example 9 with GroupAuthorizationException

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

the class TransactionManagerTest method testGroupAuthorizationFailureInTxnOffsetCommit.

@Test
public void testGroupAuthorizationFailureInTxnOffsetCommit() {
    final TopicPartition tp1 = new TopicPartition("foo", 0);
    doInitTransactions();
    transactionManager.beginTransaction();
    TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp1, new OffsetAndMetadata(39L)), new ConsumerGroupMetadata(consumerGroupId));
    prepareAddOffsetsToTxnResponse(Errors.NONE, consumerGroupId, producerId, epoch);
    runUntil(() -> !transactionManager.hasPartitionsToAdd());
    prepareFindCoordinatorResponse(Errors.NONE, false, CoordinatorType.GROUP, consumerGroupId);
    prepareTxnOffsetCommitResponse(consumerGroupId, producerId, epoch, singletonMap(tp1, Errors.GROUP_AUTHORIZATION_FAILED));
    runUntil(transactionManager::hasError);
    assertTrue(transactionManager.lastError() instanceof GroupAuthorizationException);
    assertTrue(sendOffsetsResult.isCompleted());
    assertFalse(sendOffsetsResult.isSuccessful());
    assertTrue(sendOffsetsResult.error() instanceof GroupAuthorizationException);
    assertFalse(transactionManager.hasPendingOffsetCommits());
    GroupAuthorizationException exception = (GroupAuthorizationException) sendOffsetsResult.error();
    assertEquals(consumerGroupId, exception.groupId());
    assertAbortableError(GroupAuthorizationException.class);
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

GroupAuthorizationException (org.apache.kafka.common.errors.GroupAuthorizationException)9 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)6 TopicPartition (org.apache.kafka.common.TopicPartition)6 Test (org.junit.jupiter.api.Test)6 Duration (java.time.Duration)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ConsumerGroupMetadata (org.apache.kafka.clients.consumer.ConsumerGroupMetadata)2 Test (org.junit.Test)2 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 KsqlGroupAuthorizationException (io.confluent.ksql.exception.KsqlGroupAuthorizationException)1 ExecutorUtil (io.confluent.ksql.util.ExecutorUtil)1 RetryBehaviour (io.confluent.ksql.util.ExecutorUtil.RetryBehaviour)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1