Search in sources :

Example 86 with KafkaException

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

the class AbstractConfigTest method testInvalidInputs.

private void testInvalidInputs(String configValue) {
    Properties props = new Properties();
    props.put(TestConfig.METRIC_REPORTER_CLASSES_CONFIG, configValue);
    TestConfig config = new TestConfig(props);
    try {
        config.getConfiguredInstances(TestConfig.METRIC_REPORTER_CLASSES_CONFIG, MetricsReporter.class);
        fail("Expected a config exception due to invalid props :" + props);
    } catch (KafkaException e) {
    // this is good
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) Properties(java.util.Properties)

Example 87 with KafkaException

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

the class SaslAuthenticatorTest method testInvalidLoginModule.

/**
 * Tests that connections cannot be created if the login module class is unavailable.
 */
@Test
public void testInvalidLoginModule() throws Exception {
    TestJaasConfig jaasConfig = configureMechanisms("PLAIN", Arrays.asList("PLAIN"));
    jaasConfig.createOrUpdateEntry(TestJaasConfig.LOGIN_CONTEXT_CLIENT, "InvalidLoginModule", TestJaasConfig.defaultClientOptions());
    SecurityProtocol securityProtocol = SecurityProtocol.SASL_SSL;
    server = createEchoServer(securityProtocol);
    try {
        createSelector(securityProtocol, saslClientConfigs);
        fail("SASL/PLAIN channel created without valid login module");
    } catch (KafkaException e) {
    // Expected exception
    }
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.jupiter.api.Test)

Example 88 with KafkaException

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

the class SaslAuthenticatorTest method testServerLoginCallbackOverride.

/**
 * Tests SASL server login callback class override.
 */
@Test
public void testServerLoginCallbackOverride() throws Exception {
    SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT;
    TestJaasConfig jaasConfig = configureMechanisms("PLAIN", Collections.singletonList("PLAIN"));
    jaasConfig.createOrUpdateEntry(TestJaasConfig.LOGIN_CONTEXT_SERVER, TestPlainLoginModule.class.getName(), Collections.emptyMap());
    jaasConfig.setClientOptions("PLAIN", TestServerCallbackHandler.USERNAME, TestServerCallbackHandler.PASSWORD);
    ListenerName listenerName = ListenerName.forSecurityProtocol(securityProtocol);
    String prefix = listenerName.saslMechanismConfigPrefix("PLAIN");
    saslServerConfigs.put(prefix + BrokerSecurityConfigs.SASL_SERVER_CALLBACK_HANDLER_CLASS, TestServerCallbackHandler.class);
    Class<?> loginCallback = TestLoginCallbackHandler.class;
    try {
        createEchoServer(securityProtocol);
        fail("Should have failed to create server with default login handler");
    } catch (KafkaException e) {
    // Expected exception
    }
    try {
        saslServerConfigs.put(SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS, loginCallback);
        createEchoServer(securityProtocol);
        fail("Should have failed to create server with login handler config without listener+mechanism prefix");
    } catch (KafkaException e) {
        // Expected exception
        saslServerConfigs.remove(SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS);
    }
    try {
        saslServerConfigs.put("plain." + SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS, loginCallback);
        createEchoServer(securityProtocol);
        fail("Should have failed to create server with login handler config without listener prefix");
    } catch (KafkaException e) {
        // Expected exception
        saslServerConfigs.remove("plain." + SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS);
    }
    try {
        saslServerConfigs.put(listenerName.configPrefix() + SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS, loginCallback);
        createEchoServer(securityProtocol);
        fail("Should have failed to create server with login handler config without mechanism prefix");
    } catch (KafkaException e) {
        // Expected exception
        saslServerConfigs.remove("plain." + SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS);
    }
    // Connection should succeed using login callback override for mechanism
    saslServerConfigs.put(prefix + SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS, loginCallback);
    server = createEchoServer(securityProtocol);
    createAndCheckClientConnection(securityProtocol, "1");
}
Also used : SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) KafkaException(org.apache.kafka.common.KafkaException) ListenerName(org.apache.kafka.common.network.ListenerName) Test(org.junit.jupiter.api.Test)

Example 89 with KafkaException

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

the class KafkaAdminClientTest method testDefaultApiTimeoutAndRequestTimeoutConflicts.

@Test
public void testDefaultApiTimeoutAndRequestTimeoutConflicts() {
    final AdminClientConfig config = newConfMap(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, "500");
    KafkaException exception = assertThrows(KafkaException.class, () -> KafkaAdminClient.createInternal(config, null));
    assertTrue(exception.getCause() instanceof ConfigException);
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) ConfigException(org.apache.kafka.common.config.ConfigException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 90 with KafkaException

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

the class ListTransactionsResultTest method testPartialFailure.

@Test
public void testPartialFailure() throws Exception {
    KafkaFutureImpl<Collection<TransactionListing>> future1 = new KafkaFutureImpl<>();
    KafkaFutureImpl<Collection<TransactionListing>> future2 = new KafkaFutureImpl<>();
    Map<Integer, KafkaFutureImpl<Collection<TransactionListing>>> brokerFutures = new HashMap<>();
    brokerFutures.put(1, future1);
    brokerFutures.put(2, future2);
    future.complete(brokerFutures);
    List<TransactionListing> broker1Listings = asList(new TransactionListing("foo", 12345L, TransactionState.ONGOING), new TransactionListing("bar", 98765L, TransactionState.PREPARE_ABORT));
    future1.complete(broker1Listings);
    future2.completeExceptionally(new KafkaException());
    Map<Integer, KafkaFuture<Collection<TransactionListing>>> resultBrokerFutures = result.byBrokerId().get();
    // Ensure that the future for broker 1 completes successfully
    assertEquals(Utils.mkSet(1, 2), resultBrokerFutures.keySet());
    assertEquals(broker1Listings, resultBrokerFutures.get(1).get());
    // Everything else should fail
    assertFutureThrows(result.all(), KafkaException.class);
    assertFutureThrows(result.allByBrokerId(), KafkaException.class);
    assertFutureThrows(resultBrokerFutures.get(2), KafkaException.class);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) Collection(java.util.Collection) KafkaException(org.apache.kafka.common.KafkaException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) 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