Github user mccheah commented on a diff in the pull request:
https://github.com/apache/spark/pull/22760#discussion_r233257218
--- Diff:
resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/features/HadoopConfExecutorFeatureStepSuite.scala
---
@@ -0,0 +1,68 @@
+/*
+ * 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.spark.deploy.k8s.features
+
+import org.mockito.{Mock, MockitoAnnotations}
+import org.mockito.Matchers.{eq => Eq}
+import org.mockito.Mockito.when
+import org.mockito.invocation.InvocationOnMock
+import org.mockito.stubbing.Answer
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.deploy.k8s.{KubernetesConf,
KubernetesExecutorSpecificConf, SparkPod}
+import org.apache.spark.deploy.k8s.Constants.HADOOP_CONFIG_MAP_NAME
+import org.apache.spark.deploy.k8s.features.hadooputils.HadoopBootstrapUtil
+
+class HadoopConfExecutorFeatureStepSuite extends SparkFunSuite with
BeforeAndAfter {
+ private val hadoopConfMapName = "HADOOP_CONF_NAME"
+ private val sparkPod = SparkPod.initialPod()
+
+ @Mock
+ private var kubernetesConf:
KubernetesConf[KubernetesExecutorSpecificConf] = _
+
+ @Mock
+ private var hadoopBootstrapUtil: HadoopBootstrapUtil = _
+
+ before {
+ MockitoAnnotations.initMocks(this)
+ val sparkConf = new SparkConf(false)
+ .set(HADOOP_CONFIG_MAP_NAME, hadoopConfMapName)
+ when(kubernetesConf.sparkConf).thenReturn(sparkConf)
+ }
+
+ test("bootstrapHadoopConf being applied to a base spark pod") {
+ when(hadoopBootstrapUtil.bootstrapHadoopConfDir(
--- End diff --
There is a point of over-mocking, I agree. I think `KubernetesConf`
shouldn't be mocked in most cases because it's just a structure. This is
similar to not mocking something like a case class or a hash map. I also don't
think we need to use Mockito Answers here - that could be done with stub
implementations of the submodule. I didn't have a strong enough conviction of
not using Mockito answers, but in general I think we should favor stub
implementations over `Answer`; it's more readable.
I think it's fine though that we want to test "We're calling this submodule
with these parameters", because the rest of the module's correctness is
unit-test covered in the unit tests of that submodule. The general premise we'd
like to follow is that a unit test should only execute code that is in the
class under test. In other words, in this concrete case, since
`HadoopBootstrapUtil` is a separate class, no code in `HadoopBootstrapUtil`
should be run as part of the test. The class under test is responsible for
calling the utility submodule with certain arguments but is not concerned about
what that submodule actually does. Thus the test also doesn't have to be
concerned here about what that submodule actually does, but should check that
the submodule was actually called. If we want to check the submodule's
correctness, we unit test the submodule.
Now - did we need a submodule to begin with? We could have, for example,
kept HadoopBootstrapUtil not really be a submodule at all, but just a `static`
call on a utility method. I think that's debatable - it makes each test need to
cover a larger amount of code; that is, we no longer test the utility method in
isolation, which is what we get here. Therefore it's unclear if
HadoopBootstrapUtil being its own object that can be stubbed, is the right
approach.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]