use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicOperatorTest method testReconcile_noResource_withKafka_noPrivate.
/**
* Test reconciliation when a topic has been created while the operator wasn't running
*/
@Test
public void testReconcile_noResource_withKafka_noPrivate(VertxTestContext context) throws InterruptedException {
Topic kubeTopic = null;
Topic kafkaTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar"), metadata).build();
Topic privateTopic = null;
CountDownLatch topicCreatedInKafka = new CountDownLatch(1);
mockTopicStore.setCreateTopicResponse(topicName, null);
mockK8s.setCreateResponse(topicName.asKubeName(), null);
mockKafka.setCreateTopicResponse(topicName -> Future.succeededFuture());
mockKafka.createTopic(Reconciliation.DUMMY_RECONCILIATION, kafkaTopic).onComplete(ar -> topicCreatedInKafka.countDown());
topicCreatedInKafka.await();
LogContext logContext = LogContext.periodic(topicName.toString(), topicOperator.getNamespace(), topicName.toString());
CountDownLatch async = new CountDownLatch(2);
topicOperator.reconcile(reconciliation(logContext), logContext, null, kubeTopic, kafkaTopic, privateTopic).onComplete(reconcileResult -> {
assertSucceeded(context, reconcileResult);
mockTopicStore.assertExists(context, topicName);
mockK8s.assertExists(context, topicName.asKubeName());
mockKafka.assertExists(context, topicName);
mockK8s.assertNoEvents(context);
mockTopicStore.read(topicName).onComplete(readResult -> {
assertSucceeded(context, readResult);
context.verify(() -> assertThat(readResult.result(), is(kafkaTopic)));
async.countDown();
});
mockK8s.getFromName(topicName.asKubeName()).onComplete(readResult -> {
assertSucceeded(context, readResult);
context.verify(() -> assertThat(TopicSerialization.fromTopicResource(readResult.result()), is(kafkaTopic)));
async.countDown();
});
try {
async.await(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
context.verify(() -> assertThat(mockKafka.getTopicState(topicName), is(kafkaTopic)));
context.verify(() -> {
MeterRegistry registry = metrics.meterRegistry();
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations").tag("kind", "KafkaTopic").counter().count(), is(1.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.successful").tag("kind", "KafkaTopic").counter().count(), is(1.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.failed").tag("kind", "KafkaTopic").counter().count(), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.locked").tag("kind", "KafkaTopic").counter().count(), is(0.0));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().count(), is(1L));
assertThat(registry.get(TopicOperator.METRICS_PREFIX + "reconciliations.duration").tag("kind", "KafkaTopic").timer().totalTime(TimeUnit.MILLISECONDS), greaterThan(0.0));
});
context.completeNow();
});
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.
the class TopicSerializationTest method testErrorInReplicas.
@Test
public void testErrorInReplicas() {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(-1).withPartitions(1).withConfig(emptyMap()).endSpec().build();
try {
TopicSerialization.fromTopicResource(kafkaTopic);
fail("Should throw");
} catch (InvalidTopicException e) {
assertThat(e.getMessage(), is("KafkaTopic's spec.replicas should be between 1 and 32767 inclusive"));
}
}
use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator 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-kafka-operator 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-kafka-operator by strimzi.
the class TopicSerializationTest method testErrorInPartitions.
@Test
public void testErrorInPartitions() {
KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(-1).withConfig(emptyMap()).endSpec().build();
try {
TopicSerialization.fromTopicResource(kafkaTopic);
fail("Should throw");
} catch (InvalidTopicException e) {
assertThat(e.getMessage(), is("KafkaTopic's spec.partitions should be strictly greater than 0"));
}
}
Aggregations