|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.spark.k8s.operator.config; |
| 21 | + |
| 22 | +import static org.apache.spark.k8s.operator.config.SparkOperatorConf.RECONCILER_INTERVAL_SECONDS; |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
| 24 | +import static org.awaitility.Awaitility.await; |
| 25 | +import static org.mockito.Mockito.mock; |
| 26 | + |
| 27 | +import java.util.Map; |
| 28 | +import java.util.function.Function; |
| 29 | + |
| 30 | +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 31 | +import io.fabric8.kubeapitest.junit.EnableKubeAPIServer; |
| 32 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 33 | +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 34 | +import io.fabric8.kubernetes.client.KubernetesClient; |
| 35 | +import io.javaoperatorsdk.operator.Operator; |
| 36 | +import org.junit.jupiter.api.AfterEach; |
| 37 | +import org.junit.jupiter.api.BeforeEach; |
| 38 | +import org.junit.jupiter.api.Test; |
| 39 | + |
| 40 | +@SuppressFBWarnings( |
| 41 | + value = {"UWF_UNWRITTEN_FIELD"}, |
| 42 | + justification = "Unwritten fields are covered by Kubernetes mock client") |
| 43 | +@EnableKubeAPIServer |
| 44 | +class SparkOperatorConfigMapReconcilerTest { |
| 45 | + |
| 46 | + public static final Long TARGET_RECONCILER_INTERVAL = 60L; |
| 47 | + |
| 48 | + private static KubernetesClient client; |
| 49 | + |
| 50 | + Operator operator; |
| 51 | + |
| 52 | + @BeforeEach |
| 53 | + @SuppressWarnings("unchecked") |
| 54 | + void startController() { |
| 55 | + var reconciler = |
| 56 | + new SparkOperatorConfigMapReconciler(mock(Function.class), mock(Function.class)); |
| 57 | + operator = new Operator(o -> o.withKubernetesClient(client)); |
| 58 | + operator.register(reconciler); |
| 59 | + operator.start(); |
| 60 | + } |
| 61 | + |
| 62 | + @AfterEach |
| 63 | + void stopController() { |
| 64 | + operator.stop(); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + @SuppressWarnings("PMD.UnitTestShouldIncludeAssert") |
| 69 | + void sanityTest() { |
| 70 | + client.resource(testConfigMap()).create(); |
| 71 | + |
| 72 | + await() |
| 73 | + .untilAsserted( |
| 74 | + () -> { |
| 75 | + assertThat(RECONCILER_INTERVAL_SECONDS.getValue()).isEqualTo(60L); |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + ConfigMap testConfigMap() { |
| 80 | + ConfigMap configMap = new ConfigMap(); |
| 81 | + configMap.setMetadata( |
| 82 | + new ObjectMetaBuilder().withName("spark-conf").withNamespace("default").build()); |
| 83 | + configMap.setData( |
| 84 | + Map.of(RECONCILER_INTERVAL_SECONDS.getKey(), TARGET_RECONCILER_INTERVAL.toString())); |
| 85 | + return configMap; |
| 86 | + } |
| 87 | +} |
0 commit comments