use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.
the class ControllerIT method testConfigMapModifiedRetentionChanged.
@Test
public void testConfigMapModifiedRetentionChanged(TestContext context) throws Exception {
// create the cm
String topicName = "test-configmap-modified-retention-changed";
ConfigMap cm = createCm(context, topicName);
// now change the cm
kubeClient.configMaps().inNamespace(NAMESPACE).withName(cm.getMetadata().getName()).edit().addToData(TopicSerialization.CM_KEY_CONFIG, "{\"retention.ms\":\"12341234\"}").done();
// Wait for that to be reflected in the topic
waitFor(context, () -> {
ConfigResource configResource = topicConfigResource(topicName);
org.apache.kafka.clients.admin.Config config = getTopicConfig(configResource);
String retention = config.get("retention.ms").value();
LOGGER.debug("retention of {}, waiting for 12341234", retention);
return "12341234".equals(retention);
}, timeout, "Expected the topic to be updated");
}
use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.
the class TopicSerializationTest method testToTopicConfig.
@Test
public void testToTopicConfig() {
Topic topic = new Topic.Builder().withTopicName("test-topic").withConfigEntry("foo", "bar").withNumPartitions(3).withNumReplicas((short) 2).withMapName("gee").build();
Map<ConfigResource, Config> config = TopicSerialization.toTopicConfig(topic);
assertEquals(1, config.size());
Map.Entry<ConfigResource, Config> c = config.entrySet().iterator().next();
assertEquals(c.getKey().type(), ConfigResource.Type.TOPIC);
assertEquals(c.getKey().name(), "test-topic");
assertEquals(1, c.getValue().entries().size());
assertEquals("foo", c.getValue().get("foo").name());
assertEquals("bar", c.getValue().get("foo").value());
}
use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.
the class TopicSerialization method toTopicConfig.
/**
* Return a singleton map from the topic {@link ConfigResource} for the given topic,
* to the {@link Config} of the given topic.
*/
public static Map<ConfigResource, Config> toTopicConfig(Topic topic) {
Set<ConfigEntry> configEntries = new HashSet<>();
for (Map.Entry<String, String> entry : topic.getConfig().entrySet()) {
configEntries.add(new ConfigEntry(entry.getKey(), entry.getValue()));
}
Config config = new Config(configEntries);
return Collections.singletonMap(new ConfigResource(ConfigResource.Type.TOPIC, topic.getTopicName().toString()), config);
}
use of org.apache.kafka.common.config.ConfigResource in project strimzi by strimzi.
the class BaseKafkaImpl method topicMetadata.
/**
* Get a topic config via the Kafka AdminClient API, calling the given handler
* (in a different thread) with the result.
*/
@Override
public void topicMetadata(TopicName topicName, Handler<AsyncResult<TopicMetadata>> handler) {
LOGGER.debug("Getting metadata for topic {}", topicName);
ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topicName.toString());
KafkaFuture<TopicDescription> descriptionFuture = adminClient.describeTopics(Collections.singleton(topicName.toString())).values().get(topicName.toString());
KafkaFuture<Config> configFuture = adminClient.describeConfigs(Collections.singleton(resource)).values().get(resource);
queueWork(new MetadataWork(descriptionFuture, configFuture, result -> handler.handle(result)));
}
use of org.apache.kafka.common.config.ConfigResource in project ksql by confluentinc.
the class KafkaTopicClientImplTest method topicConfigResponse.
private static DescribeConfigsResult topicConfigResponse(final String topicName, final ConfigEntry... entries) {
final Map<ConfigResource, Config> config = ImmutableMap.of(new ConfigResource(ConfigResource.Type.TOPIC, topicName), new Config(Arrays.asList(entries)));
final DescribeConfigsResult response = mock(DescribeConfigsResult.class);
expect(response.all()).andReturn(KafkaFuture.completedFuture(config));
replay(response);
return response;
}
Aggregations