aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/test/java/me/lucko/spark
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2024-07-29 19:43:14 +0100
committerLuck <git@lucko.me>2024-07-29 19:43:25 +0100
commit6e7cc883d2d716bfcfcf871956f2acb995474d2d (patch)
tree1425fa7d5c44c30daa6d703f2547d0b1ca8aa163 /spark-common/src/test/java/me/lucko/spark
parent7076811d48357cfe22792e4042ce03183b0a791d (diff)
downloadspark-6e7cc883d2d716bfcfcf871956f2acb995474d2d.tar.gz
spark-6e7cc883d2d716bfcfcf871956f2acb995474d2d.tar.bz2
spark-6e7cc883d2d716bfcfcf871956f2acb995474d2d.zip
Cleanup spark tmp dir on startup
Diffstat (limited to 'spark-common/src/test/java/me/lucko/spark')
-rw-r--r--spark-common/src/test/java/me/lucko/spark/common/util/TemporaryFilesTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/spark-common/src/test/java/me/lucko/spark/common/util/TemporaryFilesTest.java b/spark-common/src/test/java/me/lucko/spark/common/util/TemporaryFilesTest.java
new file mode 100644
index 0000000..9e07381
--- /dev/null
+++ b/spark-common/src/test/java/me/lucko/spark/common/util/TemporaryFilesTest.java
@@ -0,0 +1,77 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common.util;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class TemporaryFilesTest {
+
+ @Test
+ public void testDelete(@TempDir Path tempDir) throws IOException {
+ Path dir = tempDir.resolve("test");
+ TemporaryFiles temporaryFiles = new TemporaryFiles(dir);
+
+ assertTrue(Files.exists(dir) && Files.isDirectory(dir));
+ assertTrue(Files.exists(dir.resolve("about.txt")));
+ assertEquals("# What is this directory?", Files.readAllLines(dir.resolve("about.txt")).get(0));
+
+ Path temporaryFile = temporaryFiles.create("test", ".txt");
+ Files.write(temporaryFile, "Hello, world!".getBytes());
+
+ assertTrue(Files.exists(temporaryFile));
+ temporaryFiles.deleteTemporaryFiles();
+ assertFalse(Files.exists(temporaryFile));
+ }
+
+ @Test
+ public void testCleanupOnInit(@TempDir Path tempDir) throws IOException {
+ Path dir = tempDir.resolve("test");
+
+ Path nestedDirectory = dir.resolve("hello").resolve("world");
+ Files.createDirectories(nestedDirectory);
+
+ Path testFile = nestedDirectory.resolve("file.txt");
+ Files.write(testFile, "Hello, world!".getBytes());
+ assertTrue(Files.exists(testFile));
+
+ TemporaryFiles temporaryFiles = new TemporaryFiles(dir);
+
+ assertFalse(Files.exists(testFile));
+ }
+
+ @Test
+ public void testSecondInit(@TempDir Path tempDir) throws IOException {
+ Path dir = tempDir.resolve("test");
+
+ TemporaryFiles temporaryFiles = new TemporaryFiles(dir);
+ TemporaryFiles temporaryFiles2 = new TemporaryFiles(dir);
+ }
+
+}