use of org.apache.kafka.common.config.ConfigResource in project kafka by apache.
the class InternalTopicManagerTest method shouldThrowWhenDescribeConfigsThrowsUnexpectedExceptionDuringValidation.
@Test
public void shouldThrowWhenDescribeConfigsThrowsUnexpectedExceptionDuringValidation() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
final KafkaFutureImpl<Config> configDescriptionFailFuture = new KafkaFutureImpl<>();
configDescriptionFailFuture.completeExceptionally(new IllegalStateException("Nobody expects the Spanish inquisition"));
final ConfigResource topicResource = new ConfigResource(Type.TOPIC, topic1);
EasyMock.expect(admin.describeConfigs(Collections.singleton(topicResource))).andStubAnswer(() -> new MockDescribeConfigsResult(mkMap(mkEntry(topicResource, configDescriptionFailFuture))));
EasyMock.replay(admin);
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
assertThrows(Throwable.class, () -> topicManager.validate(Collections.singletonMap(topic1, internalTopicConfig)));
}
use of org.apache.kafka.common.config.ConfigResource in project kafka by apache.
the class ClientCompatibilityTest method testDescribeConfigsMethod.
private void testDescribeConfigsMethod(final Admin client) throws Throwable {
tryFeature("describeConfigsSupported", testConfig.describeConfigsSupported, () -> {
try {
Collection<Node> nodes = client.describeCluster().nodes().get();
final ConfigResource configResource = new ConfigResource(ConfigResource.Type.BROKER, nodes.iterator().next().idString());
Map<ConfigResource, Config> brokerConfig = client.describeConfigs(Collections.singleton(configResource)).all().get();
if (brokerConfig.get(configResource).entries().isEmpty()) {
throw new KafkaException("Expected to see config entries, but got zero entries");
}
} catch (ExecutionException e) {
throw e.getCause();
}
});
}
use of org.apache.kafka.common.config.ConfigResource in project kafka by apache.
the class MockController method legacyAlterConfigs.
@Override
public CompletableFuture<Map<ConfigResource, ApiError>> legacyAlterConfigs(Map<ConfigResource, Map<String, String>> newConfigs, boolean validateOnly) {
Map<ConfigResource, ApiError> results = new HashMap<>();
if (!validateOnly) {
for (Entry<ConfigResource, Map<String, String>> entry : newConfigs.entrySet()) {
ConfigResource resource = entry.getKey();
Map<String, String> map = configs.computeIfAbsent(resource, __ -> new HashMap<>());
map.clear();
map.putAll(entry.getValue());
}
}
CompletableFuture<Map<ConfigResource, ApiError>> future = new CompletableFuture<>();
future.complete(results);
return future;
}
use of org.apache.kafka.common.config.ConfigResource in project kafka by apache.
the class ReplicationControlManagerTest method assertCreatedTopicConfigs.
private void assertCreatedTopicConfigs(ReplicationControlTestContext ctx, String topic, CreateTopicsRequestData.CreateableTopicConfigCollection requestConfigs) {
Map<String, String> configs = ctx.configurationControl.getConfigs(new ConfigResource(ConfigResource.Type.TOPIC, topic));
assertEquals(requestConfigs.size(), configs.size());
for (CreateTopicsRequestData.CreateableTopicConfig requestConfig : requestConfigs) {
String value = configs.get(requestConfig.name());
assertEquals(requestConfig.value(), value);
}
}
use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.
the class ControllerIT method alterTopicConfig.
private void alterTopicConfig(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
// Get the topic config
ConfigResource configResource = topicConfigResource(topicName);
org.apache.kafka.clients.admin.Config config = getTopicConfig(configResource);
String key = "compression.type";
Map<String, ConfigEntry> m = new HashMap<>();
for (ConfigEntry entry : config.entries()) {
m.put(entry.name(), entry);
}
final String changedValue;
if ("snappy".equals(m.get(key).value())) {
changedValue = "lz4";
} else {
changedValue = "snappy";
}
m.put(key, new ConfigEntry(key, changedValue));
LOGGER.info("Changing topic config {} to {}", key, changedValue);
// Update the topic config
AlterConfigsResult cgf = adminClient.alterConfigs(singletonMap(configResource, new org.apache.kafka.clients.admin.Config(m.values())));
cgf.all().get();
// Wait for the configmap to be modified
waitFor(context, () -> {
ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
LOGGER.info("Polled configmap {}, waiting for config change", configMapName);
String gotValue = TopicSerialization.fromConfigMap(cm).getConfig().get(key);
LOGGER.info("Got value {}", gotValue);
return changedValue.equals(gotValue);
}, timeout, "Expected the configmap to have been deleted by now");
}
Aggregations