morhidi commented on code in PR #351:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/351#discussion_r955077692


##########
flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/diff/SpecDiffTest.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.kubernetes.operator.reconciler.diff;
+
+import org.apache.flink.configuration.CoreOptions;
+import org.apache.flink.kubernetes.operator.TestUtils;
+import org.apache.flink.kubernetes.operator.crd.spec.AbstractFlinkSpec;
+import org.apache.flink.kubernetes.operator.crd.spec.FlinkDeploymentSpec;
+import org.apache.flink.kubernetes.operator.crd.spec.FlinkSessionJobSpec;
+import org.apache.flink.kubernetes.operator.crd.spec.UpgradeMode;
+import org.apache.flink.kubernetes.operator.reconciler.ReconciliationUtils;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.kubernetes.operator.config.KubernetesOperatorConfigOptions.OPERATOR_RECONCILE_INTERVAL;
+import static 
org.apache.flink.kubernetes.operator.metrics.KubernetesOperatorMetricOptions.SCOPE_NAMING_KUBERNETES_OPERATOR;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
+
+/** Spec diff test. */
+public class SpecDiffTest {
+
+    @ParameterizedTest
+    @MethodSource("applicationTestParams")
+    public void testIgnore(AbstractFlinkSpec left, AbstractFlinkSpec right) {
+        var diff = left.diff(right);
+        assertEquals(DiffType.IGNORE, diff.getType());
+        assertEquals(0, diff.getNumDiffs());
+        if (right.getJob() != null) {
+            right.getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
+            right.getJob().setAllowNonRestoredState(true);
+            right.getJob().setInitialSavepointPath("local:///tmp");
+            right.getJob().setSavepointTriggerNonce(123L);
+            diff = left.diff(right);
+            assertEquals(DiffType.IGNORE, diff.getType());
+            assertEquals(4, diff.getNumDiffs());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("applicationTestParams")
+    public void testScale(AbstractFlinkSpec left, AbstractFlinkSpec right) {
+        var diff = left.diff(right);
+        assertEquals(DiffType.IGNORE, diff.getType());
+        assertEquals(0, diff.getNumDiffs());
+
+        if (right.getJob() != null) {
+            right.getJob().setParallelism(100);
+            diff = left.diff(right);
+            assertEquals(DiffType.SCALE, diff.getType());
+            assertEquals(1, diff.getNumDiffs());
+
+            right.getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
+            right.getJob().setAllowNonRestoredState(true);
+            right.getJob().setInitialSavepointPath("local:///tmp");
+            right.getJob().setSavepointTriggerNonce(123L);
+            diff = left.diff(right);
+            assertEquals(DiffType.SCALE, diff.getType());
+            assertEquals(5, diff.getNumDiffs());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("applicationTestParams")
+    public void testReconcile(AbstractFlinkSpec left, AbstractFlinkSpec right) 
{
+        var diff = left.diff(right);
+        assertEquals(DiffType.IGNORE, diff.getType());
+        assertEquals(0, diff.getNumDiffs());
+
+        if (left instanceof FlinkDeploymentSpec) {
+            ((FlinkDeploymentSpec) right).setImage("flink:greatest");
+            assertEquals(DiffType.UPGRADE, left.diff(right).getType());
+            diff = left.diff(right);
+            assertEquals(DiffType.UPGRADE, diff.getType());
+            assertEquals(1, diff.getNumDiffs());
+        }
+
+        if (left instanceof FlinkSessionJobSpec) {
+            ((FlinkSessionJobSpec) right).setDeploymentName("does-non-exist");
+            assertEquals(DiffType.UPGRADE, left.diff(right).getType());
+            diff = left.diff(right);
+            assertEquals(DiffType.UPGRADE, diff.getType());
+            assertEquals(1, diff.getNumDiffs());
+        }
+
+        if (right.getJob() != null) {
+            right.getJob().setParallelism(100);
+            right.getJob().setUpgradeMode(UpgradeMode.LAST_STATE);
+            assertEquals(DiffType.UPGRADE, left.diff(right).getType());
+            diff = left.diff(right);
+            assertEquals(DiffType.UPGRADE, diff.getType());
+            assertEquals(3, diff.getNumDiffs());
+        }

Review Comment:
   Added some more advanced structures. Please note that we do a deep diff on 
Diffable objects only, the rest is a just plain equals.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to