Search in sources :

Example 51 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class KafkaAdminClient method getMembersFromGroup.

private List<MemberIdentity> getMembersFromGroup(String groupId) {
    Collection<MemberDescription> members;
    try {
        members = describeConsumerGroups(Collections.singleton(groupId)).describedGroups().get(groupId).get().members();
    } catch (Exception ex) {
        throw new KafkaException("Encounter exception when trying to get members from group: " + groupId, ex);
    }
    List<MemberIdentity> membersToRemove = new ArrayList<>();
    for (final MemberDescription member : members) {
        if (member.groupInstanceId().isPresent()) {
            membersToRemove.add(new MemberIdentity().setGroupInstanceId(member.groupInstanceId().get()));
        } else {
            membersToRemove.add(new MemberIdentity().setMemberId(member.consumerId()));
        }
    }
    return membersToRemove;
}
Also used : MemberIdentity(org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity) ArrayList(java.util.ArrayList) KafkaException(org.apache.kafka.common.KafkaException) ThrottlingQuotaExceededException(org.apache.kafka.common.errors.ThrottlingQuotaExceededException) KafkaException(org.apache.kafka.common.KafkaException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) UnacceptableCredentialException(org.apache.kafka.common.errors.UnacceptableCredentialException) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) KafkaStorageException(org.apache.kafka.common.errors.KafkaStorageException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) ConfigException(org.apache.kafka.common.config.ConfigException) DisconnectException(org.apache.kafka.common.errors.DisconnectException) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) RetriableException(org.apache.kafka.common.errors.RetriableException) UnsupportedSaslMechanismException(org.apache.kafka.common.errors.UnsupportedSaslMechanismException) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) StaleMetadataException(org.apache.kafka.clients.StaleMetadataException) ApiException(org.apache.kafka.common.errors.ApiException)

Example 52 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class Metadata method clearErrorsAndMaybeThrowException.

private void clearErrorsAndMaybeThrowException(Supplier<KafkaException> recoverableExceptionSupplier) {
    KafkaException metadataException = Optional.ofNullable(fatalException).orElseGet(recoverableExceptionSupplier);
    fatalException = null;
    clearRecoverableErrors();
    if (metadataException != null)
        throw metadataException;
}
Also used : KafkaException(org.apache.kafka.common.KafkaException)

Example 53 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ListSerializerTest method testListValueSerializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidClass.

@Test
public void testListValueSerializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidClass() {
    props.put(CommonClientConfigs.DEFAULT_LIST_VALUE_SERDE_INNER_CLASS, new FakeObject());
    final KafkaException exception = assertThrows(KafkaException.class, () -> listSerializer.configure(props, false));
    assertEquals("Could not create a serializer class instance using \"" + CommonClientConfigs.DEFAULT_LIST_VALUE_SERDE_INNER_CLASS + "\" property.", exception.getMessage());
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.jupiter.api.Test)

Example 54 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ListSerializerTest method testListKeySerializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidClass.

@Test
public void testListKeySerializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidClass() {
    props.put(CommonClientConfigs.DEFAULT_LIST_KEY_SERDE_INNER_CLASS, new FakeObject());
    final KafkaException exception = assertThrows(KafkaException.class, () -> listSerializer.configure(props, true));
    assertEquals("Could not create a serializer class instance using \"" + CommonClientConfigs.DEFAULT_LIST_KEY_SERDE_INNER_CLASS + "\" property.", exception.getMessage());
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.jupiter.api.Test)

Example 55 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ListDeserializerTest method testListKeyDeserializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidInnerClass.

@Test
public void testListKeyDeserializerNoArgConstructorsShouldThrowKafkaExceptionDueInvalidInnerClass() {
    props.put(CommonClientConfigs.DEFAULT_LIST_KEY_SERDE_TYPE_CLASS, ArrayList.class);
    props.put(CommonClientConfigs.DEFAULT_LIST_KEY_SERDE_INNER_CLASS, new FakeObject());
    final KafkaException exception = assertThrows(KafkaException.class, () -> listDeserializer.configure(props, true));
    assertEquals("Could not determine the inner serde class instance using " + "\"" + CommonClientConfigs.DEFAULT_LIST_KEY_SERDE_INNER_CLASS + "\" property.", exception.getMessage());
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaException (org.apache.kafka.common.KafkaException)262 Test (org.junit.Test)69 TopicPartition (org.apache.kafka.common.TopicPartition)56 Test (org.junit.jupiter.api.Test)47 HashMap (java.util.HashMap)40 IOException (java.io.IOException)39 StreamsException (org.apache.kafka.streams.errors.StreamsException)34 Map (java.util.Map)32 TimeoutException (org.apache.kafka.common.errors.TimeoutException)28 ArrayList (java.util.ArrayList)27 List (java.util.List)21 ByteBuffer (java.nio.ByteBuffer)19 ExecutionException (java.util.concurrent.ExecutionException)19 ConfigException (org.apache.kafka.common.config.ConfigException)16 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)11