Skip to content

Commit

Permalink
Using temporary directory in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KasunaStony committed Jun 21, 2023
1 parent 0679ad8 commit fa846aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 5 additions & 1 deletion tools/java_api/java_test/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

import tools.java_api.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.Path;

import java.io.IOException;

public class TestBase {

@TempDir
static Path tempDir;
protected static KuzuDatabase db;
protected static KuzuConnection conn;

@BeforeAll
static void getDBandConn() throws IOException, KuzuObjectRefDestroyedException{
System.out.println("Kuzu test starting, loading data...");
TestHelper.loadData();
TestHelper.loadData(tempDir.toFile().getAbsolutePath());
db = TestHelper.getDatabase();
conn = TestHelper.getConnection();
System.out.println("Test data loaded");
Expand Down
4 changes: 2 additions & 2 deletions tools/java_api/java_test/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public static KuzuConnection getConnection() {
return conn;
}

public static void loadData() throws IOException, KuzuObjectRefDestroyedException {
public static void loadData(String dbPath) throws IOException, KuzuObjectRefDestroyedException {
Path tempDir = Files.createTempDirectory("java_api_test_db");
tempDir.toFile().deleteOnExit();

BufferedReader reader;
db = new KuzuDatabase("java_api_test_db", 0);
db = new KuzuDatabase(dbPath, 0);
conn = new KuzuConnection(db);
try {
reader = new BufferedReader(new FileReader("./../../dataset/tinysnb/schema.cypher"));
Expand Down
7 changes: 2 additions & 5 deletions tools/java_api/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ public static void deleteFolder(File folder) {
}

public static void main(String[] args) throws KuzuObjectRefDestroyedException {

String folderPath = "java_api_test_db";
deleteFolder(new File(folderPath));


BufferedReader reader;
KuzuDatabase db = new KuzuDatabase("java_api_test_db", 0);
KuzuDatabase db = new KuzuDatabase("./nope/java_api_test_db", 0);
KuzuConnection conn = new KuzuConnection(db);
try {
reader = new BufferedReader(new FileReader("./../../dataset/tinysnb/schema.cypher"));
Expand Down

0 comments on commit fa846aa

Please sign in to comment.