use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.
the class StrimziPodSetControllerMockTest method beforeEach.
@BeforeEach
public void beforeEach() {
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withStrimziPodSetCrd().withPodController().build();
mockKube.start();
vertx = Vertx.vertx();
kafkaOperator = new CrdOperator<>(vertx, client, Kafka.class, KafkaList.class, Kafka.RESOURCE_KIND);
podSetOperator = new StrimziPodSetOperator(vertx, client, 10_000L);
podOperator = new PodOperator(vertx, client);
kafkaOp().inNamespace(NAMESPACE).create(kafka(KAFKA_NAME, MATCHING_LABELS));
kafkaOp().inNamespace(NAMESPACE).create(kafka(OTHER_KAFKA_NAME, OTHER_LABELS));
startController();
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.
the class TopicOperatorMockTest method setup.
@BeforeEach
public void setup(VertxTestContext context) throws Exception {
// Create cluster in @BeforeEach instead of @BeforeAll as once the checkpoints causing premature success were fixed,
// tests were failing due to topic "my-topic" already existing, and trying to delete the topics at the end of the test was timing out occasionally.
// So works best when the cluster is recreated for each test to avoid shared state
Map<String, String> config = new HashMap<>();
config.put("zookeeper.connect", "zookeeper:2181");
kafkaCluster = new StrimziKafkaCluster(1, 1, config);
kafkaCluster.start();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaTopicCrd().build();
mockKube.start();
// Configure the namespace
client.getConfiguration().setNamespace(NAMESPACE);
adminClient = AdminClient.create(Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCluster.getBootstrapServers()));
Config topicConfig = new Config(Map.of(Config.KAFKA_BOOTSTRAP_SERVERS.key, kafkaCluster.getBootstrapServers(), Config.ZOOKEEPER_CONNECT.key, kafkaCluster.getZookeeper().getHost() + ":" + kafkaCluster.getZookeeper().getFirstMappedPort(), Config.ZOOKEEPER_CONNECTION_TIMEOUT_MS.key, "30000", Config.NAMESPACE.key, NAMESPACE, Config.CLIENT_ID.key, "myproject-client-id", Config.FULL_RECONCILIATION_INTERVAL_MS.key, "10000"));
session = new Session(client, topicConfig);
Checkpoint async = context.checkpoint();
vertx.deployVerticle(session, ar -> {
if (ar.succeeded()) {
deploymentId = ar.result();
topicsConfigWatcher = session.topicConfigsWatcher;
topicWatcher = session.topicWatcher;
topicsWatcher = session.topicsWatcher;
metrics = session.metricsRegistry;
metrics.forEachMeter(meter -> metrics.remove(meter));
async.flag();
} else {
ar.cause().printStackTrace();
context.failNow(new Throwable("Failed to deploy session"));
}
});
if (!context.awaitCompletion(60, TimeUnit.SECONDS)) {
context.failNow(new Throwable("Test timeout"));
}
int timeout = 30_000;
waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicWatcher.started());
waitFor("Topic configs watcher not started", 1_000, timeout, () -> this.topicsConfigWatcher.started());
waitFor("Topic watcher not started", 1_000, timeout, () -> this.topicsWatcher.started());
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.
the class ConnectorMockTest method setup.
@SuppressWarnings({ "checkstyle:MethodLength" })
@BeforeEach
public void setup(VertxTestContext testContext) {
vertx = Vertx.vertx();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaConnectCrd().withKafkaConnectorCrd().withDeploymentController().build();
mockKube.start();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_18);
setupMockConnectAPI();
metricsProvider = ResourceUtils.metricsProvider();
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
() -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), metricsProvider, pfa, 10_000);
ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(map(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, Long.toString(Long.MAX_VALUE)), KafkaVersionTestUtils.getKafkaVersionLookup());
kafkaConnectOperator = spy(new KafkaConnectAssemblyOperator(vertx, pfa, ros, config, x -> api));
Checkpoint async = testContext.checkpoint();
// Fail test if watcher closes for any reason
kafkaConnectOperator.createWatch(NAMESPACE, e -> testContext.failNow(e)).onComplete(testContext.succeeding()).compose(watch -> {
connectWatch = watch;
return AbstractConnectOperator.createConnectorWatch(kafkaConnectOperator, NAMESPACE, null);
}).compose(watch -> {
connectorWatch = watch;
// async.flag();
return Future.succeededFuture();
}).onComplete(testContext.succeeding(v -> async.flag()));
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.
the class ConnectorMockTest method testConnectorResourceMetricsScaledToZero.
// MockKube2 does not support "In" selector => https://github.com/strimzi/strimzi-kafka-operator/issues/6740
@Disabled
@Test
void testConnectorResourceMetricsScaledToZero(VertxTestContext context) {
String connectName = "cluster";
String connectorName = "connector";
KafkaConnect kafkaConnect = new KafkaConnectBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectName).addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().withNewSpec().withReplicas(0).endSpec().build();
Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).create(kafkaConnect);
waitForConnectReady(connectName);
KafkaConnector connector = defaultKafkaConnectorBuilder().editMetadata().withName(connectorName).addToLabels(Labels.STRIMZI_CLUSTER_LABEL, connectName).addToAnnotations(Annotations.ANNO_STRIMZI_IO_PAUSE_RECONCILIATION, "true").endMetadata().build();
Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).create(connector);
waitForConnectorNotReady(connectorName, "RuntimeException", "Kafka Connect cluster 'cluster' in namespace ns has 0 replicas.");
MeterRegistry meterRegistry = metricsProvider.meterRegistry();
Tags tags = Tags.of("kind", KafkaConnector.RESOURCE_KIND, "namespace", NAMESPACE);
Promise<Void> reconciled = Promise.promise();
kafkaConnectOperator.reconcileAll("test", NAMESPACE, ignored -> reconciled.complete());
Checkpoint async = context.checkpoint();
reconciled.future().onComplete(context.succeeding(v -> context.verify(() -> {
Gauge resources = meterRegistry.get("strimzi.resources").tags(tags).gauge();
assertThat(resources.value(), is(1.0));
// to create metric, otherwise MeterNotFoundException will be thrown
kafkaConnectOperator.pausedConnectorsResourceCounter(NAMESPACE);
Gauge resourcesPaused = meterRegistry.get("strimzi.resources.paused").tags(tags).gauge();
assertThat(resourcesPaused.value(), is(0.0));
async.flag();
})));
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockTest method init.
/*
* init is equivalent to a @BeforeEach method
* since this is a parameterized set, the tests params are only available at test start
* This must be called before each test
*/
private void init(Params params) {
setFields(params);
cluster = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withNewSpec().withNewKafka().withReplicas(kafkaReplicas).withStorage(kafkaStorage).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withResources(resources).endKafka().withNewZookeeper().withReplicas(zkReplicas).withStorage(zkStorage).endZookeeper().withNewEntityOperator().withNewTopicOperator().endTopicOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
mockKube.start();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, kubernetesVersion);
ResourceOperatorSupplier supplier = supplierWithMocks();
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
}
Aggregations