use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method testCreatedWithDefaultsInKube.
@Test
public void testCreatedWithDefaultsInKube(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().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 testCreatedWithDifferentTopicNameInKube.
@Test
public void testCreatedWithDifferentTopicNameInKube(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(// different to metadata.name
"DIFFERENT").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 TopicOperatorReplicationIT method testKafkaTopicModifiedChangedReplication.
@Test
public void testKafkaTopicModifiedChangedReplication() throws Exception {
// create the topicResource
String topicName = "test-kafkatopic-modified-with-changed-replication";
String resourceName = createTopic(topicName, asList(1));
// now change the topicResource
KafkaTopic changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().withReplicas(2).endSpec().build();
operation().inNamespace(NAMESPACE).withName(resourceName).patch(changedTopic);
assertStatusNotReady(topicName, "Changing 'spec.replicas' is not supported. " + "This KafkaTopic's 'spec.replicas' should be reverted to 1 and then " + "the replication should be changed directly in Kafka.");
// Now do the revert
changedTopic = new KafkaTopicBuilder(operation().inNamespace(NAMESPACE).withName(resourceName).get()).editOrNewSpec().withReplicas(1).endSpec().build();
operation().inNamespace(NAMESPACE).withName(resourceName).patch(changedTopic);
assertStatusReady(topicName);
File file = File.createTempFile(getClass().getSimpleName(), ".json");
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = new ObjectNode(mapper.getNodeFactory());
root.put("version", 1).putArray("partitions").addObject().put("topic", topicName).put("partition", 0).putArray("replicas").add(0).add(1);
mapper.writeValue(file, root);
LOGGER.info("Creating 2nd replica: {}", mapper.writeValueAsString(root));
// Now change it in Kafka
String reassignmentOutput = doReassignmentCommand("--bootstrap-server", kafkaCluster.getBootstrapServers(), "--reassignment-json-file", file.getAbsolutePath(), "--execute");
LOGGER.info(reassignmentOutput);
LOGGER.info("Waiting for reassignment completion");
waitFor(() -> {
String output = doReassignmentCommand("--bootstrap-server", kafkaCluster.getBootstrapServers(), "--reassignment-json-file", file.getAbsolutePath(), "--verify");
LOGGER.info(output);
if (output.contains("Reassignment of partition test-kafkatopic-modified-with-changed-replication-0 is still in progress")) {
return false;
} else {
assertThat("Reassignment is no longer in progress, but wasn't successful: " + output, output.contains("Reassignment of partition test-kafkatopic-modified-with-changed-replication-0 is complete"), is(true));
return true;
}
}, "reassignment completion");
// wait for reconciliation and that now replicas=2.
waitFor(() -> {
KafkaTopic kafkaTopic = Crds.topicOperation(kubeClient).inNamespace(NAMESPACE).withName(resourceName).get();
LOGGER.info(kafkaTopic == null ? "Null topic" : kafkaTopic.toString());
return kafkaTopic.getSpec().getReplicas() == 2;
}, "KafkaTopic.spec.replicas=2");
// And check that the status is ready
assertStatusReady(topicName);
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class MockK8s method createResource.
@Override
public Future<KafkaTopic> createResource(KafkaTopic topicResource) {
Promise<KafkaTopic> handler = Promise.promise();
AsyncResult<Void> response = createResponse.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 already existed: " + topicResource.getMetadata().getName()));
return handler.future();
}
}
if (response.succeeded()) {
handler.complete(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(1L).endMetadata().build());
} else {
handler.fail(response.cause());
}
return handler.future();
}
use of io.strimzi.api.kafka.model.KafkaTopicBuilder in project strimzi-kafka-operator by strimzi.
the class MockK8s method updateResourceStatus.
@Override
public Future<KafkaTopic> updateResourceStatus(Reconciliation reconciliation, KafkaTopic topicResource) {
statuses.add(new KafkaTopicStatusBuilder(topicResource.getStatus()).build());
Long generation = topicResource.getMetadata().getGeneration();
return Future.succeededFuture(new KafkaTopicBuilder(topicResource).editMetadata().withGeneration(generation == null ? 1 : generation + 1).endMetadata().build());
}
Aggregations