Skip to content

Commit 73e64f7

Browse files
erenavsarogullarisquito
authored andcommitted
[SPARK-19662][SCHEDULER][TEST] Add Fair Scheduler Unit Test coverage for different build cases
## What changes were proposed in this pull request? Fair Scheduler can be built via one of the following options: - By setting a `spark.scheduler.allocation.file` property, - By setting `fairscheduler.xml` into classpath. These options are checked **in order** and fair-scheduler is built via first found option. If invalid path is found, `FileNotFoundException` will be expected. This PR aims unit test coverage of these use cases and a minor documentation change has been added for second option(`fairscheduler.xml` into classpath) to inform the users. Also, this PR was related with apache#16813 and has been created separately to keep patch content as isolated and to help the reviewers. ## How was this patch tested? Added new Unit Tests. Author: erenavsarogullari <[email protected]> Closes apache#16992 from erenavsarogullari/SPARK-19662.
1 parent 24e6c18 commit 73e64f7

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<allocations>
20+
<pool name="pool1">
21+
<minShare>3</minShare>
22+
<weight>1</weight>
23+
<schedulingMode>FIFO</schedulingMode>
24+
</pool>
25+
<pool name="pool2">
26+
<minShare>4</minShare>
27+
<weight>2</weight>
28+
<schedulingMode>FAIR</schedulingMode>
29+
</pool>
30+
<pool name="pool3">
31+
<minShare>2</minShare>
32+
<weight>3</weight>
33+
<schedulingMode>FAIR</schedulingMode>
34+
</pool>
35+
</allocations>

core/src/test/scala/org/apache/spark/scheduler/PoolSuite.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.spark.scheduler
1919

20+
import java.io.FileNotFoundException
2021
import java.util.Properties
2122

2223
import org.apache.spark.{LocalSparkContext, SparkConf, SparkContext, SparkFunSuite}
@@ -292,6 +293,49 @@ class PoolSuite extends SparkFunSuite with LocalSparkContext {
292293
}
293294
}
294295

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+
295339
private def verifyPool(rootPool: Pool, poolName: String, expectedInitMinShare: Int,
296340
expectedInitWeight: Int, expectedSchedulingMode: SchedulingMode): Unit = {
297341
val selectedPool = rootPool.getSchedulableByName(poolName)

docs/job-scheduling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ properties:
235235
of the cluster. By default, each pool's `minShare` is 0.
236236

237237
The pool properties can be set by creating an XML file, similar to `conf/fairscheduler.xml.template`,
238-
and setting a `spark.scheduler.allocation.file` property in your
238+
and either putting a file named `fairscheduler.xml` on the classpath, or setting `spark.scheduler.allocation.file` property in your
239239
[SparkConf](configuration.html#spark-properties).
240240

241241
{% highlight scala %}

0 commit comments

Comments
 (0)