use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicSerializationTest method testErrorInConfigInvalidValueWrongType.
@Test
public void testErrorInConfigInvalidValueWrongType() {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap("foo", new Object())).endSpec().build();
try {
TopicSerialization.fromTopicResource(kafkaTopic);
fail("Should throw");
} catch (InvalidTopicException e) {
assertThat(e.getMessage(), is("KafkaTopic's spec.config has invalid entry: The key 'foo' of the topic config is invalid: The value corresponding to the key must have a string, number or boolean value but was of type java.lang.Object"));
}
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicOperatorBaseIT method alterTopicNumPartitions.
protected void alterTopicNumPartitions(String topicName, String resourceName) throws InterruptedException, ExecutionException, TimeoutException {
int changedValue = 2;
NewPartitions newPartitions = NewPartitions.increaseTo(changedValue);
Map<String, NewPartitions> map = new HashMap<>(1);
map.put(topicName, newPartitions);
CreatePartitionsResult createPartitionsResult = adminClient.createPartitions(map);
createPartitionsResult.all().get();
// Wait for the resource to be modified
waitFor(() -> {
KafkaTopic topic = operation().inNamespace(NAMESPACE).withName(resourceName).get();
LOGGER.info("Polled topic {}, waiting for partitions change", resourceName);
int gotValue = TopicSerialization.fromTopicResource(topic).getNumPartitions();
LOGGER.info("Expected value {}, got value {}", changedValue, gotValue);
return changedValue == gotValue;
}, "Expected the topic " + topicName + "to have " + changedValue + " partitions by now");
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicOperatorBaseIT method clearKafkaTopics.
protected final void clearKafkaTopics(final boolean deletionEnabled) throws TimeoutException, InterruptedException {
if (deletionEnabled && kubeClient != null && operation().inNamespace(NAMESPACE).list().getItems() != null) {
List<KafkaTopic> items = operation().inNamespace(NAMESPACE).list().getItems();
// Wait for the operator to delete all the existing topics in Kafka
for (KafkaTopic item : items) {
String mdName = item.getMetadata().getName();
String topicName = new TopicName(item).toString();
// TODO FIXME !!
if (topicName.startsWith("__"))
continue;
LOGGER.info("Deleting {} from Kube", mdName);
operation().inNamespace(NAMESPACE).withName(mdName).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
LOGGER.info("Awaiting deletion of {} in Kafka", mdName);
waitForTopicInKafka(topicName, false);
waitForTopicInKube(mdName, false);
}
}
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicOperatorBaseIT method assertStatusReady.
protected void assertStatusReady(String topicName) throws InterruptedException, ExecutionException, TimeoutException {
waitFor(() -> {
KafkaTopic kafkaTopic = operation().inNamespace(NAMESPACE).withName(topicName).get();
if (kafkaTopic != null) {
KafkaTopicStatus status = kafkaTopic.getStatus();
if (status != null && Objects.equals(status.getObservedGeneration(), kafkaTopic.getMetadata().getGeneration()) && status.getConditions() != null) {
List<Condition> conditions = status.getConditions();
assertThat(conditions.size() > 0, is(true));
if (conditions.stream().anyMatch(condition -> "Ready".equals(condition.getType()) && "True".equals(condition.getStatus()))) {
return true;
} else {
LOGGER.info(conditions);
}
}
} else {
LOGGER.info("{} does not exist", topicName);
}
return false;
}, "status ready for topic " + topicName);
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicOperatorBaseIT method awaitTopicConfigInKube.
protected void awaitTopicConfigInKube(String resourceName, String key, String expectedValue) throws TimeoutException, InterruptedException {
// Wait for the resource to be modified
waitFor(() -> {
KafkaTopic topic = operation().inNamespace(NAMESPACE).withName(resourceName).get();
LOGGER.info("Polled topic {}, waiting for config change", resourceName);
String gotValue = TopicSerialization.fromTopicResource(topic).getConfig().get(key);
LOGGER.info("Expecting value {}, got value {}", expectedValue, gotValue);
return expectedValue.equals(gotValue);
}, "Expected the config of topic " + resourceName + " to have " + key + "=" + expectedValue + " in Kube by now");
}
Aggregations