Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit bf62649

Browse files
committed
mock shuffleManager
1 parent 631402e commit bf62649

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/kubernetes/ExecutorPodFactorySuite.scala

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ import scala.collection.JavaConverters._
2020

2121
import io.fabric8.kubernetes.api.model._
2222
import io.fabric8.kubernetes.client.KubernetesClient
23-
import org.mockito.MockitoAnnotations
23+
import io.fabric8.kubernetes.api.model.{Pod, Volume, VolumeBuilder, VolumeMount, VolumeMountBuilder}
24+
2425
import org.scalatest.BeforeAndAfter
26+
import org.mockito.{AdditionalAnswers, ArgumentCaptor, Mock, MockitoAnnotations}
27+
import org.mockito.Matchers.{any, eq => mockitoEq}
28+
import org.mockito.Mockito.{doNothing, never, times, verify, when, mock}
29+
import org.scalatest.mock.MockitoSugar._
30+
31+
import org.apache.commons.io.FilenameUtils
2532

2633
import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite}
2734
import org.apache.spark.deploy.kubernetes.{constants, SparkPodInitContainerBootstrapImpl}
@@ -49,7 +56,7 @@ class ExecutorPodFactoryImplSuite extends SparkFunSuite with BeforeAndAfter {
4956
.endStatus()
5057
.build()
5158
private var baseConf: SparkConf = _
52-
private var sc: SparkContext = _
59+
//private var sc: SparkContext = mock(classOf[SparkContext])
5360

5461
before {
5562
SparkContext.clearActiveContext()
@@ -58,7 +65,7 @@ class ExecutorPodFactoryImplSuite extends SparkFunSuite with BeforeAndAfter {
5865
.set(KUBERNETES_DRIVER_POD_NAME, driverPodName)
5966
.set(KUBERNETES_EXECUTOR_POD_NAME_PREFIX, executorPrefix)
6067
.set(EXECUTOR_DOCKER_IMAGE, executorImage)
61-
sc = new SparkContext("local", "test")
68+
//sc = new SparkContext("local", "test")
6269
}
6370
private var kubernetesClient: KubernetesClient = _
6471

@@ -170,12 +177,32 @@ class ExecutorPodFactoryImplSuite extends SparkFunSuite with BeforeAndAfter {
170177
conf.set(KUBERNETES_SHUFFLE_NAMESPACE, "default")
171178
conf.set(KUBERNETES_SHUFFLE_DIR, "/tmp")
172179

180+
/*
173181
val kubernetesExternalShuffleClient = new KubernetesExternalShuffleClientImpl(
174182
SparkTransportConf.fromSparkConf(conf, "shuffle"),
175183
sc.env.securityManager,
176184
sc.env.securityManager.isAuthenticationEnabled())
177185
val shuffleManager = new KubernetesExternalShuffleManagerImpl(
178186
conf, kubernetesClient, kubernetesExternalShuffleClient)
187+
*/
188+
189+
val shuffleManager = mock(classOf[KubernetesExternalShuffleManager])
190+
when(shuffleManager.getExecutorShuffleDirVolumesWithMounts).thenReturn({
191+
val shuffleDirs = Seq("/tmp")
192+
shuffleDirs.zipWithIndex.map { case (shuffleDir, shuffleDirIndex) =>
193+
val volumeName = s"$shuffleDirIndex-${FilenameUtils.getBaseName(shuffleDir)}"
194+
val volume = new VolumeBuilder()
195+
.withName(volumeName)
196+
.withNewHostPath(shuffleDir)
197+
.build()
198+
val volumeMount = new VolumeMountBuilder()
199+
.withName(volumeName)
200+
.withMountPath(shuffleDir)
201+
.build()
202+
(volume, volumeMount)
203+
}
204+
})
205+
179206
val factory = new ExecutorPodFactoryImpl(
180207
conf,
181208
NodeAffinityExecutorPodModifierImpl,

0 commit comments

Comments
 (0)