use of io.strimzi.api.kafka.model.KafkaTopicBuilder 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.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorIT method testKafkaTopicModifiedNameChanged.
@Test
public void testKafkaTopicModifiedNameChanged() throws Exception {
// create the topicResource
String topicName = "test-kafkatopic-modified-name-changed";
KafkaTopic topicResource = createKafkaTopicResource(topicName);
// now change the topicResource
String changedName = topicName.toUpperCase(Locale.ENGLISH);
LOGGER.info("Changing Topic Resource spec.topicName from {} to {}", topicName, changedName);
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).get()).editOrNewSpec().withTopicName(changedName).endSpec().build();
operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).replace(changedTopic);
// We expect this to cause a warning event
waitForEvent(topicResource, "Kafka topics cannot be renamed, but KafkaTopic's spec.topicName has changed.", TopicOperator.EventType.WARNING);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorIT method testCreateTwoResourcesManagingOneTopic.
@Test
public void testCreateTwoResourcesManagingOneTopic() throws InterruptedException, ExecutionException, TimeoutException {
String topicName = "two-resources-one-topic";
Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
KafkaTopic topicResource = TopicSerialization.toTopicResource(topic, labels);
KafkaTopic topicResource2 = new KafkaTopicBuilder(topicResource).withMetadata(new ObjectMetaBuilder(topicResource.getMetadata()).withName(topicName + "-1").build()).build();
// create one
createKafkaTopicResource(topicResource2);
// create another
operation().inNamespace(NAMESPACE).create(topicResource);
waitForEvent(topicResource, "Failure processing KafkaTopic watch event ADDED on resource two-resources-one-topic with labels \\{.*\\}: " + "Topic 'two-resources-one-topic' is already managed via KafkaTopic 'two-resources-one-topic-1' it cannot also be managed via the KafkaTopic 'two-resources-one-topic'", TopicOperator.EventType.WARNING);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorIT method testKafkaTopicModifiedWithBadData.
@Test
public void testKafkaTopicModifiedWithBadData() throws Exception {
// create the topicResource
String topicName = "test-kafkatopic-modified-with-bad-data";
KafkaTopic topicResource = createKafkaTopicResource(topicName);
// now change the topicResource
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).get()).editOrNewSpec().withPartitions(-1).endSpec().build();
try {
operation().inNamespace(NAMESPACE).withName(topicResource.getMetadata().getName()).replace(changedTopic);
} catch (KubernetesClientException e) {
assertThat(e.getMessage().contains("spec.partitions in body should be greater than or equal to 1"), is(true));
}
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testReconciliationPaused.
@Test
public void testReconciliationPaused(VertxTestContext context) throws InterruptedException, ExecutionException {
LOGGER.info("Test started");
int retention = 100_000_000;
KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").addToLabels(Labels.KUBERNETES_NAME_LABEL, "topic-operator").withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).endMetadata().withNewSpec().withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
testNotCreatedInKube(context, kt);
}
Aggregations