use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicSerializationTest method testErrorInTopicName.
@Test
public void testErrorInTopicName() {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("foo").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(emptyMap()).withTopicName("An invalid topic name!").endSpec().build();
try {
TopicSerialization.fromTopicResource(kafkaTopic);
fail("Should throw");
} catch (InvalidTopicException e) {
assertThat(e.getMessage(), is("KafkaTopics's spec.topicName property is invalid as a topic name: Topic name \"An invalid topic name!\" is illegal, it contains a character other than ASCII alphanumerics, '.', '_' and '-'"));
}
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicSerializationTest method testErrorInDefaultTopicName.
@Test
public void testErrorInDefaultTopicName() {
// The problem with this resource name is it's too long to be a legal topic name
String illegalAsATopicName = "012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789";
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName(illegalAsATopicName).build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(emptyMap()).endSpec().build();
try {
TopicSerialization.fromTopicResource(kafkaTopic);
fail("Should throw");
} catch (InvalidTopicException e) {
assertThat(e.getMessage(), is("KafkaTopics's spec.topicName property is absent and KafkaTopics's metadata.name is invalid as a topic name: " + "Topic name is illegal, it can't be longer than 249 characters, Topic name: " + illegalAsATopicName));
}
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorBaseIT method alterTopicConfigInKube.
protected String alterTopicConfigInKube(String resourceName, String key, Function<String, String> mutator) {
// now change the topic resource
Object retention = operation().inNamespace(NAMESPACE).withName(resourceName).get().getSpec().getConfig().getOrDefault(key, "12341233");
String currentValue = retention instanceof Integer ? retention.toString() : (String) retention;
String newValue = mutator.apply(currentValue);
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig(key, newValue).endSpec().build();
operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
return newValue;
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorIT method testTopicNumPartitionsDecreased.
@Test
public void testTopicNumPartitionsDecreased() throws Exception {
String topicName = "topic-partitions-decreased-in-kube";
String resourceName = createTopic(topicName, new NewTopic(topicName, 2, (short) 1));
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().withPartitions(1).endSpec().build();
KafkaTopic replaced = operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
assertStatusNotReady(topicName, PartitionDecreaseException.class, "Number of partitions cannot be decreased");
Long generation = operation().inNamespace(NAMESPACE).withName(resourceName).get().getMetadata().getGeneration();
// Now modify Kafka-side to cause another reconciliation: We want the same status.
alterTopicConfigInKafka(topicName, "compression.type", value -> "snappy".equals(value) ? "lz4" : "snappy");
// Wait for a periodic reconciliation
Thread.sleep(RECONCILIATION_INTERVAL + 10_000);
assertStatusNotReady(topicName, PartitionDecreaseException.class, "Number of partitions cannot be decreased");
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorIT method testInvalidConfig.
@Test
public void testInvalidConfig() throws Exception {
String topicName = "topic-invalid-config";
String expectedMessage = "Invalid config value for resource ConfigResource(type=TOPIC, name='" + topicName + "'): Invalid value x for configuration min.insync.replicas: Not a number of type INT";
String resourceName = createTopic(topicName, new NewTopic(topicName, 2, (short) 1));
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().addToConfig("min.insync.replicas", "x").endSpec().build();
KafkaTopic replaced = operation().inNamespace(NAMESPACE).withName(resourceName).replace(changedTopic);
assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
// Now modify Kafka-side to cause another reconciliation: We want the same status.
alterTopicConfigInKafka(topicName, "compression.type", value -> "snappy".equals(value) ? "lz4" : "snappy");
// Wait for a periodic reconciliation
Thread.sleep(RECONCILIATION_INTERVAL + 10_000);
assertStatusNotReady(topicName, InvalidRequestException.class, expectedMessage);
}
Aggregations