Skip to content

Commit 9cbe14c

Browse files
committed
Use TestMemoryManager for test to not have to mock object field
1 parent e22ac78 commit 9cbe14c

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ import org.scalatest.mockito.MockitoSugar
4141
import org.apache.spark._
4242
import org.apache.spark.TaskState.TaskState
4343
import org.apache.spark.internal.config._
44-
import org.apache.spark.memory.MemoryManager
45-
import org.apache.spark.metrics.{JVMHeapMemory, JVMOffHeapMemory, MetricsSystem}
44+
import org.apache.spark.memory.TestMemoryManager
45+
import org.apache.spark.metrics.MetricsSystem
4646
import org.apache.spark.rdd.RDD
4747
import org.apache.spark.rpc.{RpcEndpointRef, RpcEnv, RpcTimeout}
4848
import org.apache.spark.scheduler.{FakeTask, ResultTask, Task, TaskDescription}
4949
import org.apache.spark.serializer.{JavaSerializer, SerializerManager}
5050
import org.apache.spark.shuffle.FetchFailedException
5151
import org.apache.spark.storage.{BlockManager, BlockManagerId}
52-
import org.apache.spark.util.{LongAccumulator, UninterruptibleThread, Utils}
52+
import org.apache.spark.util.{LongAccumulator, UninterruptibleThread}
5353

5454
class ExecutorSuite extends SparkFunSuite
5555
with LocalSparkContext with MockitoSugar with Eventually with PrivateMethodTester {
@@ -274,15 +274,6 @@ class ExecutorSuite extends SparkFunSuite
274274
new Executor("id", "localhost", SparkEnv.get, userClassPath = Nil, isLocal = true)
275275
val executorClass = classOf[Executor]
276276

277-
// Set ExecutorMetricType.values to be a minimal set to avoid get null exceptions
278-
val metricClass =
279-
Utils.classForName(classOf[org.apache.spark.metrics.ExecutorMetricType].getName() + "$")
280-
val metricTypeValues = metricClass.getDeclaredField("values")
281-
metricTypeValues.setAccessible(true)
282-
metricTypeValues.set(
283-
org.apache.spark.metrics.ExecutorMetricType,
284-
IndexedSeq(JVMHeapMemory, JVMOffHeapMemory))
285-
286277
// Save all heartbeats sent into an ArrayBuffer for verification
287278
val heartbeats = ArrayBuffer[Heartbeat]()
288279
val mockReceiver = mock[RpcEndpointRef]
@@ -356,14 +347,13 @@ class ExecutorSuite extends SparkFunSuite
356347
val mockEnv = mock[SparkEnv]
357348
val mockRpcEnv = mock[RpcEnv]
358349
val mockMetricsSystem = mock[MetricsSystem]
359-
val mockMemoryManager = mock[MemoryManager]
360350
val mockBlockManager = mock[BlockManager]
361351
when(mockEnv.conf).thenReturn(conf)
362352
when(mockEnv.serializer).thenReturn(serializer)
363353
when(mockEnv.serializerManager).thenReturn(mock[SerializerManager])
364354
when(mockEnv.rpcEnv).thenReturn(mockRpcEnv)
365355
when(mockEnv.metricsSystem).thenReturn(mockMetricsSystem)
366-
when(mockEnv.memoryManager).thenReturn(mockMemoryManager)
356+
when(mockEnv.memoryManager).thenReturn(new TestMemoryManager(conf))
367357
when(mockEnv.closureSerializer).thenReturn(serializer)
368358
when(mockBlockManager.blockManagerId).thenReturn(BlockManagerId("1", "hostA", 1234))
369359
when(mockEnv.blockManager).thenReturn(mockBlockManager)

0 commit comments

Comments
 (0)