@@ -26,6 +26,85 @@ import org.scalatest.mock.EasyMockSugar
2626
2727import org .apache .spark .{SparkContext , Logging , LocalSparkContext }
2828
29+ class FakeTaskSetManager (
30+ initPriority : Int ,
31+ initStageId : Int ,
32+ initNumTasks : Int ,
33+ taskScheduler : TaskSchedulerImpl ,
34+ taskSet : TaskSet )
35+ extends TaskSetManager (taskScheduler, taskSet, 0 ) {
36+
37+ parent = null
38+ weight = 1
39+ minShare = 2
40+ priority = initPriority
41+ stageId = initStageId
42+ name = " TaskSet_" + stageId
43+ override val numTasks = initNumTasks
44+ tasksSuccessful = 0
45+
46+ var numRunningTasks = 0
47+ override def runningTasks = numRunningTasks
48+
49+ def increaseRunningTasks (taskNum : Int ) {
50+ numRunningTasks += taskNum
51+ if (parent != null ) {
52+ parent.increaseRunningTasks(taskNum)
53+ }
54+ }
55+
56+ def decreaseRunningTasks (taskNum : Int ) {
57+ numRunningTasks -= taskNum
58+ if (parent != null ) {
59+ parent.decreaseRunningTasks(taskNum)
60+ }
61+ }
62+
63+ override def addSchedulable (schedulable : Schedulable ) {
64+ }
65+
66+ override def removeSchedulable (schedulable : Schedulable ) {
67+ }
68+
69+ override def getSchedulableByName (name : String ): Schedulable = {
70+ null
71+ }
72+
73+ override def executorLost (executorId : String , host : String ): Unit = {
74+ }
75+
76+ override def resourceOffer (
77+ execId : String ,
78+ host : String ,
79+ maxLocality : TaskLocality .TaskLocality )
80+ : Option [TaskDescription ] =
81+ {
82+ if (tasksSuccessful + numRunningTasks < numTasks) {
83+ increaseRunningTasks(1 )
84+ Some (new TaskDescription (0 , execId, " task 0:0" , 0 , null ))
85+ } else {
86+ None
87+ }
88+ }
89+
90+ override def checkSpeculatableTasks (): Boolean = {
91+ true
92+ }
93+
94+ def taskFinished () {
95+ decreaseRunningTasks(1 )
96+ tasksSuccessful += 1
97+ if (tasksSuccessful == numTasks) {
98+ parent.removeSchedulable(this )
99+ }
100+ }
101+
102+ def abort () {
103+ decreaseRunningTasks(numRunningTasks)
104+ parent.removeSchedulable(this )
105+ }
106+ }
107+
29108
30109class SchedulingModeSuite extends FunSuite with BeforeAndAfter with EasyMockSugar
31110 with LocalSparkContext with Logging {
0 commit comments