This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/main by this push:
new 4e31f16b0 Clean calcite tests
4e31f16b0 is described below
commit 4e31f16b00b4f2a4e7dbd14320481a99118551df
Author: Bertil Chapuis <[email protected]>
AuthorDate: Mon May 19 13:00:04 2025 +0200
Clean calcite tests
---
.../baremaps/calcite/BaremapsDdlExecutorTest.java | 29 ++++----
.../apache/baremaps/calcite/csv/CsvSchemaTest.java | 27 -------
.../apache/baremaps/calcite/csv/CsvTableTest.java | 1 -
.../calcite/flatgeobuf/FlatGeoBufSchemaTest.java | 85 ++++++++--------------
.../calcite/geopackage/GeoPackageTableTest.java | 2 +-
5 files changed, 49 insertions(+), 95 deletions(-)
diff --git
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsDdlExecutorTest.java
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsDdlExecutorTest.java
index 562be04ac..f8837ef73 100644
---
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsDdlExecutorTest.java
+++
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/BaremapsDdlExecutorTest.java
@@ -20,6 +20,7 @@ package org.apache.baremaps.calcite;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.*;
import java.util.List;
@@ -36,6 +37,7 @@ import org.apache.calcite.schema.SchemaPlus;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
@@ -46,10 +48,17 @@ import org.locationtech.jts.geom.Point;
*/
public class BaremapsDdlExecutorTest {
- private static final String CITY_DATA_DIR = "city_data";
- private static final String CITY_POPULATION_DIR = "city_population";
- private static final String POPULATION_DATA_DIR = "population_data";
- private static final String TEST_TABLE_DATA_DIR = "test_table_data";
+ @TempDir
+ Path cityDataDir;
+
+ @TempDir
+ Path cityPopulationDir;
+
+ @TempDir
+ Path populationDataDir;
+
+ @TempDir
+ Path testTableDataDir;
private DataCollection<DataRow> cityCollection;
private DataCollection<DataRow> populationCollection;
@@ -70,7 +79,7 @@ public class BaremapsDdlExecutorTest {
testTableSchema = createTestTableSchema();
// Create and initialize collections
- MemoryMappedDirectory cityMemory = new
MemoryMappedDirectory(Paths.get(CITY_DATA_DIR));
+ MemoryMappedDirectory cityMemory = new MemoryMappedDirectory(cityDataDir);
DataRowType cityRowType = new DataRowType(citySchema);
cityCollection = AppendOnlyLog.<DataRow>builder()
.dataType(cityRowType)
@@ -78,7 +87,7 @@ public class BaremapsDdlExecutorTest {
.build();
MemoryMappedDirectory populationMemory =
- new MemoryMappedDirectory(Paths.get(POPULATION_DATA_DIR));
+ new MemoryMappedDirectory(populationDataDir);
DataRowType populationRowType = new DataRowType(populationSchema);
populationCollection = AppendOnlyLog.<DataRow>builder()
.dataType(populationRowType)
@@ -86,7 +95,7 @@ public class BaremapsDdlExecutorTest {
.build();
MemoryMappedDirectory testTableMemory =
- new MemoryMappedDirectory(Paths.get(TEST_TABLE_DATA_DIR));
+ new MemoryMappedDirectory(testTableDataDir);
DataRowType testTableRowType = new DataRowType(testTableSchema);
testTableCollection = AppendOnlyLog.<DataRow>builder()
.dataType(testTableRowType)
@@ -96,12 +105,6 @@ public class BaremapsDdlExecutorTest {
@AfterEach
void tearDown() throws Exception {
- // Clean up directories
- FileUtils.deleteRecursively(Paths.get(CITY_DATA_DIR).toFile());
- FileUtils.deleteRecursively(Paths.get(POPULATION_DATA_DIR).toFile());
- FileUtils.deleteRecursively(Paths.get(CITY_POPULATION_DIR).toFile());
- FileUtils.deleteRecursively(Paths.get(TEST_TABLE_DATA_DIR).toFile());
-
// Clean up any additional directories created during test execution
FileUtils.deleteRecursively(Paths.get("options_table").toFile());
FileUtils.deleteRecursively(Paths.get("options_table_as").toFile());
diff --git
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvSchemaTest.java
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvSchemaTest.java
index e1da22fa4..023945f71 100644
---
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvSchemaTest.java
+++
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvSchemaTest.java
@@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -32,7 +31,6 @@ import org.apache.baremaps.testing.TestFiles;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
class CsvSchemaTest {
@@ -41,31 +39,6 @@ class CsvSchemaTest {
private static final char SEPARATOR = ',';
private static final boolean HAS_HEADER = true;
- @BeforeAll
- static void setup() throws IOException {
- // Ensure the test directory exists
- SAMPLE_CSV_DIR.mkdirs();
-
- // Create test CSV files if they don't exist
- if (!TestFiles.CITIES_CSV.toFile().exists()) {
- // Create a sample cities.csv file
- String citiesContent = "city,country,population\n"
- + "Paris,France,2148000\n"
- + "London,UK,8982000\n"
- + "Tokyo,Japan,37400000\n";
- Files.writeString(TestFiles.CITIES_CSV, citiesContent);
- }
-
- if (!TestFiles.COUNTRIES_CSV.toFile().exists()) {
- // Create a sample countries.csv file
- String countriesContent = "country,continent,population\n"
- + "France,Europe,67390000\n"
- + "UK,Europe,67220000\n"
- + "Japan,Asia,125700000\n";
- Files.writeString(TestFiles.COUNTRIES_CSV, countriesContent);
- }
- }
-
@Test
void testSchemaCreation() throws IOException {
// Create a CsvSchema instance
diff --git
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvTableTest.java
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvTableTest.java
index 190f961e2..dfe98516a 100644
---
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvTableTest.java
+++
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/csv/CsvTableTest.java
@@ -38,7 +38,6 @@ import org.junit.jupiter.api.Test;
public class CsvTableTest {
private static final File CITIES_CSV = TestFiles.CITIES_CSV.toFile();
- private static final File COUNTRIES_CSV = TestFiles.COUNTRIES_CSV.toFile();
private static final char SEPARATOR = ',';
private static final boolean HAS_HEADER = true;
diff --git
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufSchemaTest.java
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufSchemaTest.java
index 470f63415..c1839d316 100644
---
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufSchemaTest.java
+++
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufSchemaTest.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -32,8 +33,8 @@ import org.apache.baremaps.testing.TestFiles;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/**
* Tests for the FlatGeoBufSchema class, which provides access to FlatGeoBuf
files through the
@@ -43,18 +44,8 @@ class FlatGeoBufSchemaTest {
private static final File SAMPLE_FLATGEOBUF_DIR =
TestFiles.SAMPLE_FLATGEOBUF_DIR.toFile();
- @BeforeAll
- static void setup() throws IOException {
- // Ensure the test directory exists
- SAMPLE_FLATGEOBUF_DIR.mkdirs();
-
- // Create test FlatGeoBuf files if they don't exist
- if (!TestFiles.POINT_FLATGEOBUF.toFile().exists()) {
- // We can't easily create FlatGeoBuf files in the test, so we'll just
ensure the directory
- // exists
- // and rely on the test files being present in the test resources
- }
- }
+ @TempDir
+ Path tempDir;
@Test
void testSchemaCreation() throws IOException {
@@ -106,12 +97,8 @@ class FlatGeoBufSchemaTest {
@Test
void testSchemaWithMultipleFiles() throws IOException {
- // Create a temporary directory for test files
- File tempDir = Files.createTempDirectory("flatgeobuf-test").toFile();
- tempDir.deleteOnExit();
-
// Create a FlatGeoBufSchema instance with the temporary directory
- FlatGeoBufSchema schema = new FlatGeoBufSchema(tempDir);
+ FlatGeoBufSchema schema = new FlatGeoBufSchema(tempDir.toFile());
// Get the table map
Map<String, Table> tableMap = schema.getTableMap();
@@ -123,7 +110,7 @@ class FlatGeoBufSchemaTest {
@Test
void testSchemaWithNonExistentDirectory() throws IOException {
// Create a non-existent directory path
- File nonExistentDir = new File(SAMPLE_FLATGEOBUF_DIR,
"non-existent-subdirectory");
+ File nonExistentDir = tempDir.resolve("non-existent-directory").toFile();
// Create a FlatGeoBufSchema instance with the non-existent directory
FlatGeoBufSchema schema = new FlatGeoBufSchema(nonExistentDir);
@@ -137,51 +124,43 @@ class FlatGeoBufSchemaTest {
@Test
void testSchemaWithMultipleFlatGeoBufFiles() throws Exception {
- // Create a temporary directory for test files
- File tempDir = Files.createTempDirectory("flatgeobuf-multi-test").toFile();
- tempDir.deleteOnExit();
-
// Copy the sample FlatGeoBuf file to the temporary directory with
different names
File pointFile = TestFiles.POINT_FLATGEOBUF.toFile();
- if (pointFile.exists()) {
- // Copy the file with different names to simulate multiple files
- Files.copy(pointFile.toPath(), new File(tempDir, "points.fgb").toPath());
- Files.copy(pointFile.toPath(), new File(tempDir, "cities.fgb").toPath());
- // Create a FlatGeoBufSchema instance with the temporary directory
- FlatGeoBufSchema schema = new FlatGeoBufSchema(tempDir);
+ // Copy the file with different names to simulate multiple files
+ Files.copy(pointFile.toPath(), new File(tempDir.toFile(),
"points.fgb").toPath());
+ Files.copy(pointFile.toPath(), new File(tempDir.toFile(),
"cities.fgb").toPath());
- // Get the table map
- Map<String, Table> tableMap = schema.getTableMap();
+ // Create a FlatGeoBufSchema instance with the temporary directory
+ FlatGeoBufSchema schema = new FlatGeoBufSchema(tempDir.toFile());
- // Verify that the schema has the expected tables
- assertEquals(2, tableMap.size(), "Schema should have 2 tables");
- assertTrue(tableMap.containsKey("points"), "Schema should contain the
'points' table");
- assertTrue(tableMap.containsKey("cities"), "Schema should contain the
'cities' table");
+ // Get the table map
+ Map<String, Table> tableMap = schema.getTableMap();
- // Test SQL query with one of the tables
- Properties info = new Properties();
- info.setProperty("lex", "MYSQL");
+ // Verify that the schema has the expected tables
+ assertEquals(2, tableMap.size(), "Schema should have 2 tables");
+ assertTrue(tableMap.containsKey("points"), "Schema should contain the
'points' table");
+ assertTrue(tableMap.containsKey("cities"), "Schema should contain the
'cities' table");
- try (Connection connection =
DriverManager.getConnection("jdbc:calcite:", info)) {
- CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
- SchemaPlus rootSchema = calciteConnection.getRootSchema();
+ // Test SQL query with one of the tables
+ Properties info = new Properties();
+ info.setProperty("lex", "MYSQL");
- // Register the schema
- rootSchema.add("multi_flatgeobuf", schema);
+ try (Connection connection = DriverManager.getConnection("jdbc:calcite:",
info)) {
+ CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
+ SchemaPlus rootSchema = calciteConnection.getRootSchema();
- // Execute a query on one of the tables
- try (Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(
- "SELECT * FROM multi_flatgeobuf.points LIMIT 5")) {
+ // Register the schema
+ rootSchema.add("multi_flatgeobuf", schema);
- // Verify that we get results
- assertTrue(resultSet.next(), "Should have at least one row");
- }
+ // Execute a query on one of the tables
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(
+ "SELECT * FROM multi_flatgeobuf.points LIMIT 5")) {
+
+ // Verify that we get results
+ assertTrue(resultSet.next(), "Should have at least one row");
}
- } else {
- // Skip the test if the sample file doesn't exist
- System.out.println("Skipping testSchemaWithMultipleFlatGeoBufFiles:
sample file not found");
}
}
}
diff --git
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageTableTest.java
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageTableTest.java
index 5c242604d..7efd0f04a 100644
---
a/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageTableTest.java
+++
b/baremaps-calcite/src/test/java/org/apache/baremaps/calcite/geopackage/GeoPackageTableTest.java
@@ -38,7 +38,7 @@ import org.locationtech.jts.geom.Geometry;
class GeoPackageTableTest {
private static final File SAMPLE_GEOPACKAGE = TestFiles.GEOPACKAGE.toFile();
- private static final String TABLE_NAME = "countries"; // The table name in
the sample GeoPackage
+ private static final String TABLE_NAME = "countries";
@Test
void testSchemaVerification() throws IOException {