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
}
}
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
}
}
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");
}
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);
}
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);
}
Aggregations