use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerTest method testOnConfigMapAdded_ignorable.
/**
* Test what happens when a non-topic config map gets created in kubernetes
*/
@Test
public void testOnConfigMapAdded_ignorable(TestContext context) {
ConfigMap cm = new ConfigMapBuilder().withNewMetadata().withName("non-topic").endMetadata().build();
Async async = context.async();
controller.onConfigMapAdded(cm, ar -> {
assertSucceeded(context, ar);
mockKafka.assertEmpty(context);
mockTopicStore.assertEmpty(context);
async.complete();
});
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerTest method testOnConfigMapRemoved_NoSuchEntityExistsException.
@Test
public void testOnConfigMapRemoved_NoSuchEntityExistsException(TestContext context) {
Exception deleteTopicException = null;
Exception storeException = new TopicStore.NoSuchEntityExistsException();
configMapRemoved(context, deleteTopicException, storeException);
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerTest method testReconcile_withCm_withKafka_noPrivate_configsReconcilable.
/**
* Test reconciliation when a cm has been added both in kafka and in k8s while the controller was down, and
* the topics are irreconcilably different: Kafka wins
*/
@Test
public void testReconcile_withCm_withKafka_noPrivate_configsReconcilable(TestContext context) {
Topic kubeTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar")).build();
Topic kafkaTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("unclean.leader.election.enable", "true")).build();
Topic privateTopic = null;
Topic mergedTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("unclean.leader.election.enable", "true", "cleanup.policy", "bar")).build();
Async async0 = context.async(2);
mockKafka.setCreateTopicResponse(topicName -> Future.succeededFuture());
mockKafka.createTopic(kafkaTopic, ar -> async0.countDown());
mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
mockK8s.setCreateResponse(topicName.asMapName(), null);
mockK8s.createConfigMap(cm, ar -> async0.countDown());
mockK8s.setModifyResponse(topicName.asMapName(), null);
mockTopicStore.setCreateTopicResponse(topicName, null);
async0.await();
Async async = context.async(2);
controller.reconcile(cm, kubeTopic, kafkaTopic, privateTopic, reconcileResult -> {
assertSucceeded(context, reconcileResult);
mockTopicStore.assertExists(context, topicName);
mockK8s.assertExists(context, topicName.asMapName());
mockKafka.assertExists(context, topicName);
mockTopicStore.read(topicName, readResult -> {
assertSucceeded(context, readResult);
context.assertEquals(mergedTopic, readResult.result());
async.countDown();
});
mockK8s.getFromName(topicName.asMapName(), readResult -> {
assertSucceeded(context, readResult);
context.assertEquals(mergedTopic, TopicSerialization.fromConfigMap(readResult.result()));
async.countDown();
});
context.assertEquals(mergedTopic, mockKafka.getTopicState(topicName));
});
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerTest method testOnConfigMapRemoved_UnknownTopicOrPartitionException.
@Test
public void testOnConfigMapRemoved_UnknownTopicOrPartitionException(TestContext context) {
Exception deleteTopicException = new UnknownTopicOrPartitionException();
Exception storeException = null;
configMapRemoved(context, deleteTopicException, storeException);
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerTest method testOnConfigMapChanged.
@Test
public void testOnConfigMapChanged(TestContext context) {
Topic kubeTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "baz")).build();
Topic kafkaTopic = new Topic.Builder(topicName, mapName, 10, (short) 2, map("cleanup.policy", "bar")).build();
Topic privateTopic = kafkaTopic;
ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
mockKafka.setCreateTopicResponse(topicName.toString(), null).createTopic(kafkaTopic, ar -> {
});
mockKafka.setTopicMetadataResponse(topicName, Utils.getTopicMetadata(kafkaTopic), null);
mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
mockTopicStore.setCreateTopicResponse(topicName, null).create(privateTopic, ar -> {
});
mockTopicStore.setUpdateTopicResponse(topicName, null);
mockK8s.setModifyResponse(mapName, null);
Async async = context.async(3);
controller.onConfigMapModified(cm, ar -> {
assertSucceeded(context, ar);
context.assertEquals("baz", mockKafka.getTopicState(topicName).getConfig().get("cleanup.policy"));
mockTopicStore.read(topicName, ar2 -> {
assertSucceeded(context, ar2);
context.assertEquals("baz", ar2.result().getConfig().get("cleanup.policy"));
async.countDown();
});
mockK8s.getFromName(mapName, ar2 -> {
assertSucceeded(context, ar2);
context.assertEquals("baz", TopicSerialization.fromConfigMap(ar2.result()).getConfig().get("cleanup.policy"));
async.countDown();
});
async.countDown();
});
}
Aggregations