use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testCreatedInKube.
void testCreatedInKube(VertxTestContext context, KafkaTopic kt) throws InterruptedException, ExecutionException {
String kubeName = kt.getMetadata().getName();
String kafkaName = kt.getSpec().getTopicName() != null ? kt.getSpec().getTopicName() : kubeName;
int retention = (Integer) kt.getSpec().getConfig().get("retention.bytes");
createInKube(kt);
// Check created in Kafka
waitUntilTopicExistsInKafka(kafkaName);
LOGGER.info("Topic has been created");
Topic fromKafka = getFromKafka(kafkaName);
context.verify(() -> assertThat(fromKafka.getTopicName().toString(), is(kafkaName)));
// Reconcile after no changes
reconcile(context);
// Check things still the same
context.verify(() -> assertThat(fromKafka, is(getFromKafka(kafkaName))));
// Config change + reconcile
updateInKube(new KafkaTopicBuilder(kt).editSpec().addToConfig("retention.bytes", retention + 1).endSpec().build());
waitUntilTopicInKafka(kafkaName, config -> Integer.toString(retention + 1).equals(config.get("retention.bytes").value()));
// Another reconciliation
reconcile(context);
// Check things still the same
context.verify(() -> {
assertThat(getFromKafka(kafkaName), is(new Topic.Builder(fromKafka).withConfigEntry("retention.bytes", Integer.toString(retention + 1)).build()));
context.completeNow();
});
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testNotCreatedInKube.
void testNotCreatedInKube(VertxTestContext context, KafkaTopic kt) throws InterruptedException, ExecutionException {
String kubeName = kt.getMetadata().getName();
String kafkaName = kt.getSpec().getTopicName() != null ? kt.getSpec().getTopicName() : kubeName;
int retention = (Integer) kt.getSpec().getConfig().get("retention.bytes");
createInKube(kt);
Thread.sleep(2000);
LOGGER.info("Topic has not been created");
Topic fromKafka = getFromKafka(kafkaName);
context.verify(() -> assertThat(fromKafka, is(nullValue())));
// Reconcile after no changes
reconcile(context);
// Check things still the same
context.verify(() -> assertThat(fromKafka, is(nullValue())));
// Config change + reconcile
updateInKube(new KafkaTopicBuilder(kt).editSpec().addToConfig("retention.bytes", retention + 1).endSpec().build());
// Another reconciliation
reconcile(context);
// Check things still the same
context.verify(() -> {
assertThat(getFromKafka(kafkaName), is(nullValue()));
context.completeNow();
});
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testCreatedWithSameTopicNameInKube.
@Test
public void testCreatedWithSameTopicNameInKube(VertxTestContext context) throws InterruptedException, ExecutionException {
int retention = 100_000_000;
KafkaTopic kt = new KafkaTopicBuilder().withNewMetadata().withName("my-topic").withNamespace(NAMESPACE).addToLabels(Labels.STRIMZI_KIND_LABEL, "topic").endMetadata().withNewSpec().withTopicName(// the same as metadata.name
"my-topic").withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
testCreatedInKube(context, kt);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testCreatedWithoutTopicNameInKube.
@Test
public void testCreatedWithoutTopicNameInKube(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").endMetadata().withNewSpec().withPartitions(1).withReplicas(1).addToConfig("retention.bytes", retention).endSpec().build();
testCreatedInKube(context, kt);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class MockK8s method updateResource.
@Override
public Future<KafkaTopic> updateResource(KafkaTopic topicResource) {
Promise<KafkaTopic> handler = Promise.promise();
AsyncResult<Void> response = modifyResponse.apply(new ResourceName(topicResource));
if (response.succeeded()) {
AsyncResult<KafkaTopic> old = byName.put(new ResourceName(topicResource), Future.succeededFuture(topicResource));
if (old == null) {
handler.handle(Future.failedFuture("resource does not exist, cannot be updated: " + topicResource.getMetadata().getName()));
return handler.future();
}
}
if (response.succeeded()) {
Long generation = topicResource.getMetadata().getGeneration();
handler.complete(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(generation != null ? generation + 1 : 1).endMetadata().build());
} else {
handler.fail(response.cause());
}
return handler.future();
}
Aggregations