|
| 1 | +package org.apache.spark.k8s.operator.config; |
| 2 | + |
| 3 | +import static org.apache.spark.k8s.operator.config.SparkOperatorConf.RECONCILER_INTERVAL_SECONDS; |
| 4 | +import static org.assertj.core.api.Assertions.assertThat; |
| 5 | +import static org.awaitility.Awaitility.await; |
| 6 | +import static org.mockito.Mockito.mock; |
| 7 | + |
| 8 | +import java.util.Map; |
| 9 | +import java.util.function.Function; |
| 10 | + |
| 11 | +import io.fabric8.kubeapitest.junit.EnableKubeAPIServer; |
| 12 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 13 | +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 14 | +import io.fabric8.kubernetes.client.KubernetesClient; |
| 15 | +import io.javaoperatorsdk.operator.Operator; |
| 16 | +import org.junit.jupiter.api.AfterEach; |
| 17 | +import org.junit.jupiter.api.BeforeEach; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +@EnableKubeAPIServer |
| 21 | +class SparkOperatorConfigMapReconcilerTest { |
| 22 | + |
| 23 | + public static final Long TARGET_RECONCILER_INTERVAL = 60L; |
| 24 | + static KubernetesClient client; |
| 25 | + |
| 26 | + Operator operator; |
| 27 | + |
| 28 | + @BeforeEach |
| 29 | + void startController() { |
| 30 | + var namespaceUpdater = mock(Function.class); |
| 31 | + var watchedNamespaceGetter = mock(Function.class); |
| 32 | + |
| 33 | + var reconciler = new SparkOperatorConfigMapReconciler(namespaceUpdater, watchedNamespaceGetter); |
| 34 | + operator = new Operator(o -> o.withKubernetesClient(client)); |
| 35 | + operator.register(reconciler); |
| 36 | + operator.start(); |
| 37 | + } |
| 38 | + |
| 39 | + @AfterEach |
| 40 | + void stopController() { |
| 41 | + operator.stop(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void sanityTest() { |
| 46 | + client.resource(testConfigMap()).create(); |
| 47 | + |
| 48 | + await() |
| 49 | + .untilAsserted( |
| 50 | + () -> { |
| 51 | + assertThat(RECONCILER_INTERVAL_SECONDS.getValue()).isEqualTo(60L); |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + ConfigMap testConfigMap() { |
| 56 | + ConfigMap configMap = new ConfigMap(); |
| 57 | + configMap.setMetadata( |
| 58 | + new ObjectMetaBuilder().withName("spark-conf").withNamespace("default").build()); |
| 59 | + configMap.setData( |
| 60 | + Map.of(RECONCILER_INTERVAL_SECONDS.getKey(), TARGET_RECONCILER_INTERVAL.toString())); |
| 61 | + return configMap; |
| 62 | + } |
| 63 | +} |
0 commit comments