@@ -25,7 +25,7 @@ import org.mockito.Mockito._
2525import org .scalatest .{BeforeAndAfterEach , Matchers }
2626
2727import org .apache .spark .{SparkConf , SparkFunSuite }
28- import org .apache .spark .deploy .yarn .config .YARN_EXECUTOR_LAUNCH_BLACKLIST_ENABLED
28+ import org .apache .spark .deploy .yarn .config .{ YARN_EXCLUDE_NODES , YARN_EXECUTOR_LAUNCH_BLACKLIST_ENABLED }
2929import org .apache .spark .internal .config .{BLACKLIST_TIMEOUT_CONF , MAX_FAILED_EXEC_PER_NODE }
3030import org .apache .spark .util .ManualClock
3131
@@ -35,27 +35,31 @@ class YarnAllocatorBlacklistTrackerSuite extends SparkFunSuite with Matchers
3535 val BLACKLIST_TIMEOUT = 100L
3636 val MAX_FAILED_EXEC_PER_NODE_VALUE = 2
3737
38+ var sparkConf : SparkConf = _
3839 var amClientMock : AMRMClient [ContainerRequest ] = _
39- var yarnBlacklistTracker : YarnAllocatorBlacklistTracker = _
40- var failureTracker : FailureTracker = _
4140 var clock : ManualClock = _
4241
4342 override def beforeEach (): Unit = {
44- val sparkConf = new SparkConf ()
43+ sparkConf = new SparkConf ()
4544 sparkConf.set(BLACKLIST_TIMEOUT_CONF , BLACKLIST_TIMEOUT )
4645 sparkConf.set(YARN_EXECUTOR_LAUNCH_BLACKLIST_ENABLED , true )
4746 sparkConf.set(MAX_FAILED_EXEC_PER_NODE , MAX_FAILED_EXEC_PER_NODE_VALUE )
4847 clock = new ManualClock ()
49-
5048 amClientMock = mock(classOf [AMRMClient [ContainerRequest ]])
51- failureTracker = new FailureTracker (sparkConf, clock)
52- yarnBlacklistTracker =
49+ super .beforeEach()
50+ }
51+
52+ private def createYarnAllocatorBlacklistTracker (
53+ sparkConf : SparkConf = sparkConf): YarnAllocatorBlacklistTracker = {
54+ val failureTracker = new FailureTracker (sparkConf, clock)
55+ val yarnBlacklistTracker =
5356 new YarnAllocatorBlacklistTracker (sparkConf, amClientMock, failureTracker)
5457 yarnBlacklistTracker.setNumClusterNodes(4 )
55- super .beforeEach()
58+ yarnBlacklistTracker
5659 }
5760
5861 test(" expiring its own blacklisted nodes" ) {
62+ val yarnBlacklistTracker = createYarnAllocatorBlacklistTracker()
5963 (1 to MAX_FAILED_EXEC_PER_NODE_VALUE ).foreach {
6064 _ => {
6165 yarnBlacklistTracker.handleResourceAllocationFailure(Some (" host" ))
@@ -77,6 +81,8 @@ class YarnAllocatorBlacklistTrackerSuite extends SparkFunSuite with Matchers
7781 }
7882
7983 test(" not handling the expiry of scheduler blacklisted nodes" ) {
84+ val yarnBlacklistTracker = createYarnAllocatorBlacklistTracker()
85+
8086 yarnBlacklistTracker.setSchedulerBlacklistedNodes(Set (" host1" , " host2" ))
8187 verify(amClientMock)
8288 .updateBlacklist(Arrays .asList(" host1" , " host2" ), Collections .emptyList())
@@ -91,6 +97,15 @@ class YarnAllocatorBlacklistTrackerSuite extends SparkFunSuite with Matchers
9197 }
9298
9399 test(" combining scheduler and allocation blacklist" ) {
100+ sparkConf.set(YARN_EXCLUDE_NODES , Seq (" initial1" , " initial2" ))
101+ val yarnBlacklistTracker = createYarnAllocatorBlacklistTracker(sparkConf)
102+ yarnBlacklistTracker.setSchedulerBlacklistedNodes(Set ())
103+
104+ // initial1 and initial2 is added as blacklisted nodes at the very first updateBlacklist call
105+ // and they are never removed
106+ verify(amClientMock)
107+ .updateBlacklist(Arrays .asList(" initial1" , " initial2" ), Collections .emptyList())
108+
94109 (1 to MAX_FAILED_EXEC_PER_NODE_VALUE ).foreach {
95110 _ => {
96111 yarnBlacklistTracker.handleResourceAllocationFailure(Some (" host1" ))
@@ -117,6 +132,7 @@ class YarnAllocatorBlacklistTrackerSuite extends SparkFunSuite with Matchers
117132 }
118133
119134 test(" blacklist all available nodes" ) {
135+ val yarnBlacklistTracker = createYarnAllocatorBlacklistTracker()
120136 yarnBlacklistTracker.setSchedulerBlacklistedNodes(Set (" host1" , " host2" , " host3" ))
121137 verify(amClientMock)
122138 .updateBlacklist(Arrays .asList(" host1" , " host2" , " host3" ), Collections .emptyList())
@@ -137,4 +153,5 @@ class YarnAllocatorBlacklistTrackerSuite extends SparkFunSuite with Matchers
137153 verify(amClientMock).updateBlacklist(Arrays .asList(" host4" ), Collections .emptyList())
138154 assert(yarnBlacklistTracker.isAllNodeBlacklisted)
139155 }
156+
140157}
0 commit comments