use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.
the class ControllerTest method testOnConfigMapAdded_TopicExistsException.
/**
* 1. controller is notified that a ConfigMap is created
* 2. error when creating topic in kafka
*/
@Test
public void testOnConfigMapAdded_TopicExistsException(TestContext context) {
Exception createException = new TopicExistsException("");
configMapAdded(context, createException, null);
// TODO check a k8s event got created
// TODO what happens when we subsequently reconcile?
}
use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.
the class ControllerIT method testConfigMapDeleted.
@Test
public void testConfigMapDeleted(TestContext context) {
// create the cm
String topicName = "test-configmap-deleted";
ConfigMap cm = createCm(context, topicName);
// can now delete the cm
kubeClient.configMaps().inNamespace(NAMESPACE).withName(cm.getMetadata().getName()).delete();
// Wait for the topic to be deleted
waitFor(context, () -> {
try {
adminClient.describeTopics(singletonList(topicName)).values().get(topicName).get();
return false;
} catch (ExecutionException e) {
if (e.getCause() instanceof UnknownTopicOrPartitionException) {
return true;
} else {
throw new RuntimeException(e);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}, timeout, "Expected topic to be deleted by now");
}
use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.
the class ControllerIT method testConfigMapModifiedWithBadData.
@Test
public void testConfigMapModifiedWithBadData(TestContext context) throws Exception {
// create the cm
String topicName = "test-configmap-modified-with-bad-data";
ConfigMap cm = createCm(context, topicName);
// now change the cm
kubeClient.configMaps().inNamespace(NAMESPACE).withName(cm.getMetadata().getName()).edit().addToData(TopicSerialization.CM_KEY_PARTITIONS, "foo").done();
// Wait for that to be reflected in the topic
waitForEvent(context, cm, "ConfigMap test-configmap-modified-with-bad-data has an invalid 'data' section: " + "ConfigMap's 'data' section has invalid key 'partitions': " + "should be a strictly positive integer but was 'foo'", Controller.EventType.WARNING);
}
use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.
the class ControllerIT method setup.
@Before
public void setup(TestContext context) throws Exception {
LOGGER.info("Setting up test");
Runtime.getRuntime().addShutdownHook(kafkaHook);
kafkaCluster = new KafkaCluster();
kafkaCluster.addBrokers(1);
kafkaCluster.deleteDataPriorToStartup(true);
kafkaCluster.deleteDataUponShutdown(true);
kafkaCluster.usingDirectory(Files.createTempDirectory("controller-integration-test").toFile());
kafkaCluster.startup();
kubeClient = new DefaultKubernetesClient().inNamespace(NAMESPACE);
LOGGER.info("Using namespace {}", NAMESPACE);
Map<String, String> m = new HashMap();
m.put(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.brokerList());
m.put(Config.ZOOKEEPER_CONNECT.key, "localhost:" + zkPort(kafkaCluster));
m.put(Config.NAMESPACE.key, NAMESPACE);
session = new Session(kubeClient, new Config(m));
Async async = context.async();
vertx.deployVerticle(session, ar -> {
if (ar.succeeded()) {
deploymentId = ar.result();
adminClient = session.adminClient;
topicsConfigWatcher = session.topicConfigsWatcher;
topicWatcher = session.topicWatcher;
topicsWatcher = session.topicsWatcher;
async.complete();
} else {
context.fail("Failed to deploy session");
}
});
async.await();
waitFor(context, () -> this.topicsWatcher.started(), timeout, "Topics watcher not started");
waitFor(context, () -> this.topicsConfigWatcher.started(), timeout, "Topic configs watcher not started");
waitFor(context, () -> this.topicWatcher.started(), timeout, "Topic watcher not started");
// We can't delete events, so record the events which exist at the start of the test
// and then waitForEvents() can ignore those
preExistingEvents = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems().stream().map(evt -> evt.getMetadata().getUid()).collect(Collectors.toSet());
LOGGER.info("Finished setting up test");
}
use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.
the class ControllerIT method createCm.
private ConfigMap createCm(TestContext context, String topicName) {
Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap()).build();
ConfigMap cm = TopicSerialization.toConfigMap(topic, cmPredicate);
return createCm(context, cm);
}
Aggregations