jerrypeng commented on code in PR #56008:
URL: https://github.com/apache/spark/pull/56008#discussion_r3308005657


##########
core/src/test/scala/org/apache/spark/StreamingShuffleOutputTrackerSuite.scala:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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
+
+import org.scalatest.BeforeAndAfter
+import org.scalatest.matchers.should.Matchers
+
+import 
org.apache.spark.internal.config.SHUFFLE_MAPOUTPUT_DISPATCHER_NUM_THREADS
+import org.apache.spark.rpc.RpcEnv
+
+class StreamingShuffleOutputTrackerSuite
+  extends SparkFunSuite
+  with LocalSparkContext
+  with ThreadAudit
+  with BeforeAndAfter
+  with Matchers {
+
+  before {
+    doThreadPreAudit()
+  }
+
+  after {
+    doThreadPostAudit()
+  }
+
+  protected val conf = new SparkConf
+
+  protected def newTrackerMaster(sparkConf: SparkConf = conf) = {
+    new StreamingShuffleOutputTrackerMaster(sparkConf)
+  }
+
+  protected def newTrackerWorker(
+      sparkConf: SparkConf = conf): StreamingShuffleOutputTrackerWorker = {
+    new StreamingShuffleOutputTrackerWorker(sparkConf)
+  }
+
+  def createRpcEnv(
+      name: String,
+      host: String = "localhost",
+      port: Int = 0,
+      securityManager: SecurityManager = new SecurityManager(conf)): RpcEnv = {
+    RpcEnv.create(name, host, port, conf, securityManager)
+  }
+
+  test("master start and stop") {
+    val rpcEnv = createRpcEnv("test")
+    val tracker = newTrackerMaster()
+    tracker.trackerEndpoint = rpcEnv.setupEndpoint(
+      StreamingShuffleOutputTracker.ENDPOINT_NAME,
+      new StreamingShuffleOutputTrackerMasterEndpoint(rpcEnv, tracker, conf))
+    tracker.stop()
+    rpcEnv.shutdown()
+  }
+
+  test("test tracker workflow") {
+    val master = newTrackerMaster()
+    val worker = newTrackerWorker()
+
+    val rpcEnv = createRpcEnv("test")
+    val rpcEndpoint = rpcEnv.setupEndpoint(
+      StreamingShuffleOutputTracker.ENDPOINT_NAME,
+      new StreamingShuffleOutputTrackerMasterEndpoint(rpcEnv, master, conf))
+
+    master.trackerEndpoint = rpcEndpoint
+    worker.trackerEndpoint = rpcEndpoint
+
+    val shuffleId = 0
+    val numMaps = 2
+    val numReduces = 2
+    val jobId = 0
+    val taskMap =
+      Map(
+        0 -> StreamingShuffleTaskLocation("executor-1", "host-1", 0),
+        1 -> StreamingShuffleTaskLocation("executor-2", "host-2", 0))
+    master.registerShuffle(shuffleId, numMaps, numReduces, jobId)
+    // register one shuffle write task
+    worker.registerShuffleWriterTask(shuffleId, 0, taskMap(0))
+    // Get all shuffle write task location information.  Should return None 
since
+    // only one of the shuffle writers have registered
+    worker.getAllShuffleWriterTaskLocations(shuffleId) should be(None)
+    // register the next shuffle write task
+    worker.registerShuffleWriterTask(shuffleId, 1, taskMap(1))
+    // should get all the shuffle task location information now
+    worker.getAllShuffleWriterTaskLocations(shuffleId) should be(Some(taskMap))
+
+    // should be a no-op for the worker
+    worker.unregisterShuffle(shuffleId)
+    master.unregisterShuffle(shuffleId)
+
+    master.getShuffleInfo(shuffleId) should be(None)
+    worker.stop()
+    master.stop()
+  }
+
+  test("register task for shuffle that doesn't exist") {
+    val master = newTrackerMaster()
+    val worker = newTrackerWorker()
+
+    val rpcEnv = createRpcEnv("test")
+    val rpcEndpoint = rpcEnv.setupEndpoint(
+      StreamingShuffleOutputTracker.ENDPOINT_NAME,
+      new StreamingShuffleOutputTrackerMasterEndpoint(rpcEnv, master, conf))
+
+    master.trackerEndpoint = rpcEndpoint
+    worker.trackerEndpoint = rpcEndpoint
+
+    worker.registerShuffleWriterTask(
+      0,
+      0,
+      StreamingShuffleTaskLocation("executor-1", "host-1", 0)) should be(false)
+
+    worker.stop()
+    master.stop()
+  }
+
+  test("get task location for shuffle that doesn't exist") {
+    val master = newTrackerMaster()
+    val worker = newTrackerWorker()
+
+    val rpcEnv = createRpcEnv("test")
+    val rpcEndpoint = rpcEnv.setupEndpoint(
+      StreamingShuffleOutputTracker.ENDPOINT_NAME,
+      new StreamingShuffleOutputTrackerMasterEndpoint(rpcEnv, master, conf))
+
+    master.trackerEndpoint = rpcEndpoint
+    worker.trackerEndpoint = rpcEndpoint
+
+    worker.getAllShuffleWriterTaskLocations(0) should be(None)
+
+    worker.stop()
+    master.stop()
+  }
+
+  test("StreamingShuffleOutputTrackerMaster - register shuffle") {
+    val conf = new SparkConf(false)
+    val tracker = new StreamingShuffleOutputTrackerMaster(conf)

Review Comment:
   Fixed by centralizing teardown in the suite's after block: tracker creation 
now goes through the existing newTrackerMaster / newTrackerWorker helpers, 
which register the instance in a private trackersToStop ArrayBuffer. The after 
block stops every registered tracker before doThreadPostAudit() runs, so a 
thread leak in any test will now be caught by the audit and the leak itself 
can't accumulate across tests in the suite.
   
   I also routed the few new StreamingShuffleOutputTrackerMaster(conf) call 
sites through newTrackerMaster(conf) so they participate in the cleanup. Same 
change addresses the RpcEnv  shutdown comment below.
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to