Github user jiangxb1987 commented on a diff in the pull request: https://github.com/apache/spark/pull/18084#discussion_r118376781 --- Diff: core/src/test/scala/org/apache/spark/deploy/master/MasterSuite.scala --- @@ -499,4 +500,103 @@ class MasterSuite extends SparkFunSuite assert(receivedMasterAddress === RpcAddress("localhost2", 10000)) } } + + test("SPARK-19900: there should be a corresponding driver for the app after relaunching driver") { + val conf = new SparkConf().set("spark.worker.timeout", "1") + val master = makeMaster(conf) + master.rpcEnv.setupEndpoint(Master.ENDPOINT_NAME, master) + eventually(timeout(10.seconds)) { + val masterState = master.self.askSync[MasterStateResponse](RequestMasterState) + assert(masterState.status === RecoveryState.ALIVE, "Master is not alive") + } + + val app = DeployTestUtils.createAppDesc() + var appId = "" + val driverEnv1 = RpcEnv.create("driver1", "localhost", 22344, conf, new SecurityManager(conf)) + val fakeDriver1 = driverEnv1.setupEndpoint("driver", new RpcEndpoint { + override val rpcEnv: RpcEnv = driverEnv1 + override def receive: PartialFunction[Any, Unit] = { + case RegisteredApplication(id, _) => appId = id + } + }) + val drivers = new HashMap[String, String] + val workerEnv1 = RpcEnv.create("worker1", "localhost", 12344, conf, new SecurityManager(conf)) + val fakeWorker1 = workerEnv1.setupEndpoint("worker", new RpcEndpoint { + override val rpcEnv: RpcEnv = workerEnv1 + override def receive: PartialFunction[Any, Unit] = { + case RegisteredWorker(masterRef, _, _) => + masterRef.send(WorkerLatestState("1", Nil, drivers.keys.toSeq)) + case LaunchDriver(id, desc) => + drivers(id) = id + master.self.send(RegisterApplication(app, fakeDriver1)) + case KillDriver(driverId) => + master.self.send(DriverStateChanged(driverId, DriverState.KILLED, None)) + drivers.remove(driverId) + } + }) + val worker1 = RegisterWorker( + "1", + "localhost", + 9999, + fakeWorker1, + 10, + 1024, + "http://localhost:8080", + RpcAddress("localhost2", 10000)) + master.self.send(worker1) + val driver = DeployTestUtils.createDriverDesc().copy(supervise = true) + master.self.askSync[SubmitDriverResponse](RequestSubmitDriver(driver)) + + eventually(timeout(10.seconds)) { + assert(!appId.isEmpty) + } + + eventually(timeout(10.seconds)) { + val masterState = master.self.askSync[MasterStateResponse](RequestMasterState) + assert(masterState.workers(0).state == WorkerState.DEAD) + } + + val driverEnv2 = RpcEnv.create("driver2", "localhost", 22345, conf, new SecurityManager(conf)) + val fakeDriver2 = driverEnv2.setupEndpoint("driver", new RpcEndpoint { --- End diff -- I believe these duplicate code can be combined.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org