use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi 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 by strimzi.
the class TopicSerializationTest method testResourceSerializationRoundTripWithKubernetesLabels.
@Test
public void testResourceSerializationRoundTripWithKubernetesLabels() {
String topicName = "tom";
Topic.Builder builder = new Topic.Builder();
builder.withTopicName(topicName);
builder.withNumReplicas((short) 1);
builder.withNumPartitions(2);
builder.withConfigEntry("cleanup.policy", "bar");
ObjectMeta metadata = new ObjectMeta();
metadata.setAnnotations(new HashMap<>());
Map<String, String> kubeLabels = new HashMap<>(3);
kubeLabels.put("app.kubernetes.io/name", "kstreams");
kubeLabels.put("app.kubernetes.io/instance", "fraud-detection");
kubeLabels.put("app.kubernetes.io/managed-by", "helm");
metadata.setLabels(kubeLabels);
builder.withMetadata(metadata);
Topic wroteTopic = builder.build();
KafkaTopic kafkaTopic = TopicSerialization.toTopicResource(wroteTopic, labels);
assertThat(kafkaTopic.getMetadata().getName(), is(wroteTopic.getTopicName().toString()));
assertThat(kafkaTopic.getMetadata().getLabels().size(), is(4));
assertThat(kafkaTopic.getMetadata().getLabels().get("app"), is("strimzi"));
assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/name"), is("kstreams"));
assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/instance"), is("fraud-detection"));
assertThat(kafkaTopic.getMetadata().getLabels().get("app.kubernetes.io/managed-by"), is("helm"));
assertThat(kafkaTopic.getSpec().getTopicName(), is(wroteTopic.getTopicName().toString()));
assertThat(kafkaTopic.getSpec().getPartitions(), is(Integer.valueOf(2)));
assertThat(kafkaTopic.getSpec().getReplicas(), is(Integer.valueOf(1)));
assertThat(kafkaTopic.getSpec().getConfig(), is(singletonMap("cleanup.policy", "bar")));
Topic readTopic = TopicSerialization.fromTopicResource(kafkaTopic);
assertThat(readTopic, is(wroteTopic));
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi by strimzi.
the class TopicSerializationTest method testErrorInConfigInvalidValueNull.
@Test
public void testErrorInConfigInvalidValueNull() {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap("foo", null)).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 the value was null"));
}
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi by strimzi.
the class TopicSerializationTest method testNoConfig.
@Test
public void testNoConfig() {
KafkaTopicSpec spec = new KafkaTopicSpec();
spec.setPartitions(3);
spec.setReplicas(3);
KafkaTopic kafkaTopic = new KafkaTopic();
kafkaTopic.setMetadata(new ObjectMetaBuilder().withName("my-topic").build());
kafkaTopic.setSpec(spec);
TopicSerialization.fromTopicResource(kafkaTopic);
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi by strimzi.
the class TopicST method testCreateTopicAfterUnsupportedOperation.
@ParallelTest
@Disabled("TopicOperator allows forbidden settings - https://github.com/strimzi/strimzi-kafka-operator/issues/6884")
void testCreateTopicAfterUnsupportedOperation(ExtensionContext extensionContext) {
String topicName = "topic-with-replication-to-change";
String newTopicName = "another-topic";
KafkaTopic kafkaTopic = KafkaTopicTemplates.topic(TOPIC_CLUSTER_NAME, topicName, namespace).editSpec().withReplicas(3).withPartitions(3).endSpec().build();
resourceManager.createResource(extensionContext, kafkaTopic);
KafkaTopicResource.replaceTopicResourceInSpecificNamespace(topicName, t -> {
t.getSpec().setReplicas(1);
t.getSpec().setPartitions(1);
}, namespace);
KafkaTopicUtils.waitForKafkaTopicNotReady(namespace, topicName);
String exceptedMessage = "Number of partitions cannot be decreased";
assertThat(KafkaTopicResource.kafkaTopicClient().inNamespace(namespace).withName(topicName).get().getStatus().getConditions().get(0).getMessage(), is(exceptedMessage));
String topicCRDMessage = KafkaTopicResource.kafkaTopicClient().inNamespace(namespace).withName(topicName).get().getStatus().getConditions().get(0).getMessage();
assertThat(topicCRDMessage, containsString(exceptedMessage));
KafkaTopic newKafkaTopic = KafkaTopicTemplates.topic(TOPIC_CLUSTER_NAME, newTopicName, 1, 1).editMetadata().withNamespace(namespace).endMetadata().build();
resourceManager.createResource(extensionContext, newKafkaTopic);
assertThat("Topic exists in Kafka itself", hasTopicInKafka(topicName, TOPIC_CLUSTER_NAME));
assertThat("Topic exists in Kafka CR (Kubernetes)", hasTopicInCRK8s(kafkaTopic, topicName));
assertThat("Topic exists in Kafka itself", hasTopicInKafka(newTopicName, TOPIC_CLUSTER_NAME));
assertThat("Topic exists in Kafka CR (Kubernetes)", hasTopicInCRK8s(newKafkaTopic, newTopicName));
cmdKubeClient(namespace).deleteByName(KafkaTopic.RESOURCE_SINGULAR, topicName);
KafkaTopicUtils.waitForKafkaTopicDeletion(namespace, topicName);
cmdKubeClient(namespace).deleteByName(KafkaTopic.RESOURCE_SINGULAR, newTopicName);
KafkaTopicUtils.waitForKafkaTopicDeletion(namespace, newTopicName);
}
Aggregations