use of io.fabric8.mockwebserver.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.mockwebserver.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.mockwebserver.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);
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerIT method deleteTopic.
private void deleteTopic(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
LOGGER.info("Deleting topic {} (ConfigMap {})", topicName, configMapName);
// Now we can delete the topic
DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
dlt.all().get();
LOGGER.info("Deleted topic {}", topicName);
// Wait for the configmap to be deleted
waitFor(context, () -> {
ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
LOGGER.info("Polled configmap {}, got {}, waiting for deletion", configMapName, cm);
return cm == null;
}, timeout, "Expected the configmap to have been deleted by now");
}
use of io.fabric8.mockwebserver.Context in project strimzi by strimzi.
the class ControllerIT method waitForEvent.
private void waitForEvent(TestContext context, ConfigMap cm, String expectedMessage, Controller.EventType expectedType) {
waitFor(context, () -> {
List<Event> items = kubeClient.events().inNamespace(NAMESPACE).withLabels(cmPredicate.labels()).list().getItems();
List<Event> filtered = items.stream().filter(evt -> !preExistingEvents.contains(evt.getMetadata().getUid()) && "ConfigMap".equals(evt.getInvolvedObject().getKind()) && cm.getMetadata().getName().equals(evt.getInvolvedObject().getName())).collect(Collectors.toList());
LOGGER.debug("Waiting for events: {}", filtered.stream().map(evt -> evt.getMessage()).collect(Collectors.toList()));
if (!filtered.isEmpty()) {
assertEquals(1, filtered.size());
Event event = filtered.get(0);
assertEquals(expectedMessage, event.getMessage());
assertEquals(expectedType.name, event.getType());
assertNotNull(event.getInvolvedObject());
assertEquals("ConfigMap", event.getInvolvedObject().getKind());
assertEquals(cm.getMetadata().getName(), event.getInvolvedObject().getName());
return true;
} else {
return false;
}
}, timeout, "Expected an error event");
}
Aggregations