Changeset: 721b7b109ecc for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/721b7b109ecc
Modified Files:
        tests/TestRunner.java
Branch: onclient
Log Message:

Provide tempdir to tests that need it


diffs (63 lines):

diff --git a/tests/TestRunner.java b/tests/TestRunner.java
--- a/tests/TestRunner.java
+++ b/tests/TestRunner.java
@@ -8,10 +8,16 @@
 
 import org.monetdb.jdbc.MonetConnection;
 
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.sql.*;
 import java.util.ArrayList;
 
@@ -27,6 +33,7 @@ public class TestRunner {
        private Statement stmt;
        private StringWriter outBuffer;
        private PrintWriter out;
+       private Path tmpDir = null;
 
        public TestRunner(String jdbcUrl, int verbosity, boolean 
watchDogEnabled) {
                this.jdbcUrl = jdbcUrl;
@@ -252,6 +259,34 @@ public class TestRunner {
                assertEq("query result", expected, result);
        }
 
+       protected synchronized Path getTmpDir(String name) throws IOException {
+               if (tmpDir == null) {
+                       tmpDir = Files.createTempDirectory("testMonetDB");
+                       Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+                               try {
+                                       Files.walkFileTree(tmpDir, new 
SimpleFileVisitor<Path>() {
+                                               @Override
+                                               public FileVisitResult 
visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                                                       Files.delete(file);
+                                                       return 
FileVisitResult.CONTINUE;
+                                               }
+
+                                               @Override
+                                               public FileVisitResult 
postVisitDirectory(Path dir, IOException exc) throws IOException {
+                                                       Files.delete(dir);
+                                                       return 
FileVisitResult.CONTINUE;
+                                               }
+                                       });
+                               } catch (IOException e) {
+                                       // we do this on a best effort basis
+                               }
+                       }));
+               }
+               Path p = tmpDir.resolve(name);
+               Files.createDirectory(p);
+               return p;
+       }
+
        static class Failure extends Exception {
 
                public Failure(String message) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to