|
| 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 | + |
| 18 | +package org.apache.spark.storage |
| 19 | + |
| 20 | +import java.io.File |
| 21 | + |
| 22 | +import org.apache.spark.util.Utils |
| 23 | +import org.scalatest.FunSuite |
| 24 | + |
| 25 | +import org.apache.spark.SparkConf |
| 26 | + |
| 27 | + |
| 28 | +/** |
| 29 | + * Tests for the spark.local.dirs and SPARK_LOCAL_DIRS configuration options. |
| 30 | + */ |
| 31 | +class LocalDirsSuite extends FunSuite { |
| 32 | + |
| 33 | + test("Utils.getLocalDir() returns a valid directory, even if some local dirs are missing") { |
| 34 | + // Regression test for SPARK-2974 |
| 35 | + assert(!new File("/NONEXISTENT_DIR").exists()) |
| 36 | + val conf = new SparkConf(false) |
| 37 | + .set("spark.local.dir", s"/NONEXISTENT_PATH,${System.getProperty("java.io.tmpdir")}") |
| 38 | + assert(new File(Utils.getLocalDir(conf)).exists()) |
| 39 | + } |
| 40 | + |
| 41 | + test("SPARK_LOCAL_DIRS override also affects driver") { |
| 42 | + // Regression test for SPARK-2975 |
| 43 | + assert(!new File("/NONEXISTENT_DIR").exists()) |
| 44 | + // SPARK_LOCAL_DIRS is a valid directory: |
| 45 | + class MySparkConf extends SparkConf(false) { |
| 46 | + override def getenv(name: String) = { |
| 47 | + if (name == "SPARK_LOCAL_DIRS") System.getProperty("java.io.tmpdir") |
| 48 | + else super.getenv(name) |
| 49 | + } |
| 50 | + |
| 51 | + override def clone: SparkConf = { |
| 52 | + new MySparkConf().setAll(settings) |
| 53 | + } |
| 54 | + } |
| 55 | + // spark.local.dir only contains invalid directories, but that's not a problem since |
| 56 | + // SPARK_LOCAL_DIRS will override it on both the driver and workers: |
| 57 | + val conf = new MySparkConf().set("spark.local.dir", "/NONEXISTENT_PATH") |
| 58 | + assert(new File(Utils.getLocalDir(conf)).exists()) |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments