|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.spark.scheduler.cluster |
| 18 | + |
| 19 | +import java.util.concurrent.atomic.AtomicInteger |
| 20 | + |
| 21 | +import org.apache.hadoop.net.NetworkTopology |
| 22 | +import org.mockito.Mockito.doNothing |
| 23 | +import org.scalatestplus.mockito.MockitoSugar |
| 24 | + |
| 25 | +import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite} |
| 26 | +import org.apache.spark.deploy.yarn.config.RESOLVE_RACK_ENABLED |
| 27 | +import org.apache.spark.scheduler.{DAGScheduler, WorkerOffer} |
| 28 | + |
| 29 | +class YarnClusterSchedulerSuite extends SparkFunSuite with MockitoSugar { |
| 30 | + |
| 31 | + test("rack resolve is disabled by default on resourceOffers") { |
| 32 | + Seq(None, Some(false), Some(true)).foreach { resolveRack => |
| 33 | + val conf = new SparkConf().setMaster("local").setAppName("YarnClusterSchedulerSuite") |
| 34 | + resolveRack.foreach(enabled => conf.set(RESOLVE_RACK_ENABLED, enabled)) |
| 35 | + val sc = new SparkContext(conf) |
| 36 | + val clusterScheduler = new YarnClusterScheduler(sc) |
| 37 | + val executor = "executor0" |
| 38 | + val host = "host0" |
| 39 | + val dagScheduler = mock[DAGScheduler] |
| 40 | + clusterScheduler.setDAGScheduler(dagScheduler) |
| 41 | + doNothing().when(dagScheduler).executorAdded(executor, host) |
| 42 | + clusterScheduler.resourceOffers(IndexedSeq(WorkerOffer(executor, host, new AtomicInteger(1)))) |
| 43 | + if (conf.get(RESOLVE_RACK_ENABLED)) { |
| 44 | + assert(clusterScheduler.hasHostAliveOnRack(NetworkTopology.DEFAULT_RACK)) |
| 45 | + } else { |
| 46 | + assert(!clusterScheduler.hasHostAliveOnRack(NetworkTopology.DEFAULT_RACK)) |
| 47 | + } |
| 48 | + sc.stop() |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments