LuciferYang commented on code in PR #13098: URL: https://github.com/apache/gluten/pull/13098#discussion_r4110021534
########## gluten-core/src/test/scala/org/apache/spark/util/SparkDirectoryUtilSuite.scala: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.util + +import org.apache.spark.SparkConf + +import org.scalatest.funsuite.AnyFunSuite + +import java.io.File +import java.nio.file.Files + +class SparkDirectoryUtilSuite extends AnyFunSuite { + + test("namespace fails fast naming the configured local dirs when none can be created") { + // A regular file cannot host a local directory, so directory creation fails + // for every configured root. + val notADir = Files.createTempFile("gluten-not-a-dir", ".tmp") + notADir.toFile.deleteOnExit() + val conf = new SparkConf() + .set("spark.master", "local[1]") + .set("spark.local.dirs", notADir.toAbsolutePath.toString) + .set("spark.local.dir", notADir.toAbsolutePath.toString) + SparkDirectoryUtil.init(conf) + val exception = intercept[IllegalStateException] { + SparkDirectoryUtil.get().namespace("test-namespace") + } Review Comment: Done in 38081d990. Added a package-private `createForTesting(roots)` factory and switched the test to build an isolated instance, so it no longer touches the process-wide singleton or depends on `init()` ordering. Kept it `private[util]` rather than public so the production surface does not widen. ########## gluten-core/src/main/scala/org/apache/spark/util/SparkDirectoryUtil.scala: ########## @@ -98,16 +106,22 @@ class Namespace(private val parents: Array[File], private val name: String) { path.toFile } + if (all.isEmpty) { + // all.isEmpty iff parents.isEmpty (map preserves length), so the actionable + // detail here is that no parent directories were provided. + throw new IllegalStateException( + s"No available Gluten local directory in namespace '$name': " + + s"no parent directories were provided") + } + private val cycleLooper = Stream.continually(all).flatten.toIterator Review Comment: Done in 38081d990. Replaced the `Stream.continually(...).flatten` round-robin with an index-based one (`nextRootIndex = (nextRootIndex + 1) % all.length`), dropping the deprecated `Stream` API. ########## gluten-core/src/test/scala/org/apache/spark/util/SparkDirectoryUtilSuite.scala: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.util + +import org.apache.spark.SparkConf + +import org.scalatest.funsuite.AnyFunSuite + +import java.io.File +import java.nio.file.Files + +class SparkDirectoryUtilSuite extends AnyFunSuite { + + test("namespace fails fast naming the configured local dirs when none can be created") { + // A regular file cannot host a local directory, so directory creation fails + // for every configured root. + val notADir = Files.createTempFile("gluten-not-a-dir", ".tmp") + notADir.toFile.deleteOnExit() + val conf = new SparkConf() + .set("spark.master", "local[1]") + .set("spark.local.dirs", notADir.toAbsolutePath.toString) + .set("spark.local.dir", notADir.toAbsolutePath.toString) + SparkDirectoryUtil.init(conf) + val exception = intercept[IllegalStateException] { + SparkDirectoryUtil.get().namespace("test-namespace") + } + assert(exception.getMessage.contains("test-namespace")) + assert(exception.getMessage.contains(notADir.toAbsolutePath.toString)) + } + + test("Namespace rejects an empty parent list") { + val exception = intercept[IllegalStateException] { + new Namespace(Array.empty[File], "test-namespace") + } + assert(exception.getMessage.contains("test-namespace")) + } + + test("Namespace creates child directories under an available root") { + val root = Files.createTempDirectory("gluten-usable-root").toFile + try { + val namespace = new Namespace(Array(root), "test-namespace") + val child = namespace.mkChildDirRoundRobin("child-dir") + assert(child.exists) Review Comment: Done in 38081d990. The test now asserts `child.isDirectory` and that the child's canonical path starts with the root's canonical path. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
