|
17 | 17 |
|
18 | 18 | package org.apache.spark.scheduler
|
19 | 19 |
|
| 20 | +import java.io.FileNotFoundException |
20 | 21 | import java.util.Properties
|
21 | 22 |
|
22 | 23 | import org.apache.spark.{LocalSparkContext, SparkConf, SparkContext, SparkFunSuite}
|
@@ -292,6 +293,49 @@ class PoolSuite extends SparkFunSuite with LocalSparkContext {
|
292 | 293 | }
|
293 | 294 | }
|
294 | 295 |
|
| 296 | + test("Fair Scheduler should build fair scheduler when " + |
| 297 | + "valid spark.scheduler.allocation.file property is set") { |
| 298 | + val xmlPath = getClass.getClassLoader.getResource("fairscheduler-with-valid-data.xml").getFile() |
| 299 | + val conf = new SparkConf().set(SCHEDULER_ALLOCATION_FILE_PROPERTY, xmlPath) |
| 300 | + sc = new SparkContext(LOCAL, APP_NAME, conf) |
| 301 | + |
| 302 | + val rootPool = new Pool("", SchedulingMode.FAIR, 0, 0) |
| 303 | + val schedulableBuilder = new FairSchedulableBuilder(rootPool, sc.conf) |
| 304 | + schedulableBuilder.buildPools() |
| 305 | + |
| 306 | + verifyPool(rootPool, schedulableBuilder.DEFAULT_POOL_NAME, 0, 1, FIFO) |
| 307 | + verifyPool(rootPool, "pool1", 3, 1, FIFO) |
| 308 | + verifyPool(rootPool, "pool2", 4, 2, FAIR) |
| 309 | + verifyPool(rootPool, "pool3", 2, 3, FAIR) |
| 310 | + } |
| 311 | + |
| 312 | + test("Fair Scheduler should use default file(fairscheduler.xml) if it exists in classpath " + |
| 313 | + "and spark.scheduler.allocation.file property is not set") { |
| 314 | + val conf = new SparkConf() |
| 315 | + sc = new SparkContext(LOCAL, APP_NAME, conf) |
| 316 | + |
| 317 | + val rootPool = new Pool("", SchedulingMode.FAIR, 0, 0) |
| 318 | + val schedulableBuilder = new FairSchedulableBuilder(rootPool, sc.conf) |
| 319 | + schedulableBuilder.buildPools() |
| 320 | + |
| 321 | + verifyPool(rootPool, schedulableBuilder.DEFAULT_POOL_NAME, 0, 1, FIFO) |
| 322 | + verifyPool(rootPool, "1", 2, 1, FIFO) |
| 323 | + verifyPool(rootPool, "2", 3, 1, FIFO) |
| 324 | + verifyPool(rootPool, "3", 0, 1, FIFO) |
| 325 | + } |
| 326 | + |
| 327 | + test("Fair Scheduler should throw FileNotFoundException " + |
| 328 | + "when invalid spark.scheduler.allocation.file property is set") { |
| 329 | + val conf = new SparkConf().set(SCHEDULER_ALLOCATION_FILE_PROPERTY, "INVALID_FILE_PATH") |
| 330 | + sc = new SparkContext(LOCAL, APP_NAME, conf) |
| 331 | + |
| 332 | + val rootPool = new Pool("", SchedulingMode.FAIR, 0, 0) |
| 333 | + val schedulableBuilder = new FairSchedulableBuilder(rootPool, sc.conf) |
| 334 | + intercept[FileNotFoundException] { |
| 335 | + schedulableBuilder.buildPools() |
| 336 | + } |
| 337 | + } |
| 338 | + |
295 | 339 | private def verifyPool(rootPool: Pool, poolName: String, expectedInitMinShare: Int,
|
296 | 340 | expectedInitWeight: Int, expectedSchedulingMode: SchedulingMode): Unit = {
|
297 | 341 | val selectedPool = rootPool.getSchedulableByName(poolName)
|
|
0 commit comments