From 86366d482057239b33c01caa44985d6f58f9cf34 Mon Sep 17 00:00:00 2001 From: Venkateshwaran Shanmugham Date: Fri, 29 May 2026 23:27:05 +0530 Subject: [PATCH 1/3] JDBC: Automate schema version test discovery --- persistence/relational-jdbc/build.gradle.kts | 80 +++++++++++++++++++ ...thJdbcBasePersistenceImplV0SchemaTest.java | 28 ------- ...thJdbcBasePersistenceImplV1SchemaTest.java | 28 ------- ...thJdbcBasePersistenceImplV2SchemaTest.java | 28 ------- ...thJdbcBasePersistenceImplV3SchemaTest.java | 28 ------- ...thJdbcBasePersistenceImplV4SchemaTest.java | 29 ------- 6 files changed, 80 insertions(+), 141 deletions(-) delete mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV0SchemaTest.java delete mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV1SchemaTest.java delete mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV2SchemaTest.java delete mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV3SchemaTest.java delete mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest.java diff --git a/persistence/relational-jdbc/build.gradle.kts b/persistence/relational-jdbc/build.gradle.kts index ae4ed62261..e9d7217199 100644 --- a/persistence/relational-jdbc/build.gradle.kts +++ b/persistence/relational-jdbc/build.gradle.kts @@ -55,3 +55,83 @@ dependencies { testImplementation(project(":polaris-container-spec-helper")) testImplementation(project(":polaris-runtime-test-common")) } + +val generatedSchemaVersionTestsDir = + layout.buildDirectory.dir("generated/sources/schemaVersionTests/java") + +val generateSchemaVersionTests by + tasks.registering { + val schemaFiles = + files( + // schema-v0.sql lives in test resources to cover legacy bootstrap behavior; newer H2 + // schema files live in main resources. Scan both so new schema versions get tests + // automatically. + fileTree("src/main/resources/h2") { include("schema-v*.sql") }, + fileTree("src/test/resources/h2") { include("schema-v*.sql") }, + ) + inputs.files(schemaFiles) + outputs.dir(generatedSchemaVersionTestsDir) + + doLast { + val outputDir = + generatedSchemaVersionTestsDir + .get() + .file("org/apache/polaris/persistence/relational/jdbc") + .asFile + delete(outputDir) + outputDir.mkdirs() + + val schemaVersionPattern = Regex("""schema-v(\d+)\.sql""") + val schemaVersions = + schemaFiles.files + .mapNotNull { schemaVersionPattern.matchEntire(it.name)?.groupValues?.get(1)?.toInt() } + .toSortedSet() + + check(schemaVersions.isNotEmpty()) { "No H2 schema files found for JDBC tests" } + + schemaVersions.forEach { schemaVersion -> + outputDir + .resolve( + "AtomicMetastoreManagerWithJdbcBasePersistenceImplV${schemaVersion}SchemaTest.java" + ) + .writeText( + """ + /* + * 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.polaris.persistence.relational.jdbc; + + public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV${schemaVersion}SchemaTest + extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { + + @Override + public int schemaVersion() { + return ${schemaVersion}; + } + } + """ + .trimIndent() + .plus("\n") + ) + } + } + } + +sourceSets { test { java.srcDir(generateSchemaVersionTests) } } + +tasks.named("compileTestJava") { dependsOn(generateSchemaVersionTests) } diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV0SchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV0SchemaTest.java deleted file mode 100644 index 3650d8b7ac..0000000000 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV0SchemaTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.polaris.persistence.relational.jdbc; - -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV0SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - @Override - public int schemaVersion() { - return 0; - } -} diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV1SchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV1SchemaTest.java deleted file mode 100644 index 2d50b27015..0000000000 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV1SchemaTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.polaris.persistence.relational.jdbc; - -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV1SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - @Override - public int schemaVersion() { - return 1; - } -} diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV2SchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV2SchemaTest.java deleted file mode 100644 index 8ccafb9618..0000000000 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV2SchemaTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.polaris.persistence.relational.jdbc; - -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV2SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - @Override - public int schemaVersion() { - return 2; - } -} diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV3SchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV3SchemaTest.java deleted file mode 100644 index bb81da4d02..0000000000 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV3SchemaTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.polaris.persistence.relational.jdbc; - -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV3SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - @Override - public int schemaVersion() { - return 3; - } -} diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest.java deleted file mode 100644 index e26a0fccca..0000000000 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.polaris.persistence.relational.jdbc; - -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - - @Override - public int schemaVersion() { - return 4; - } -} From 9b57f284dcb17c0e866262c6187654df3c4a31b7 Mon Sep 17 00:00:00 2001 From: Venkateshwaran Shanmugham Date: Sun, 31 May 2026 19:36:50 +0530 Subject: [PATCH 2/3] JDBC: automate schema version test discovery --- persistence/relational-jdbc/build.gradle.kts | 80 ------------------ ...WithJdbcBasePersistenceImplSchemaTest.java | 81 +++++++++++++++++++ .../relational/jdbc/H2SchemaVersions.java | 50 ++++++++++++ 3 files changed, 131 insertions(+), 80 deletions(-) create mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java create mode 100644 persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java diff --git a/persistence/relational-jdbc/build.gradle.kts b/persistence/relational-jdbc/build.gradle.kts index e9d7217199..ae4ed62261 100644 --- a/persistence/relational-jdbc/build.gradle.kts +++ b/persistence/relational-jdbc/build.gradle.kts @@ -55,83 +55,3 @@ dependencies { testImplementation(project(":polaris-container-spec-helper")) testImplementation(project(":polaris-runtime-test-common")) } - -val generatedSchemaVersionTestsDir = - layout.buildDirectory.dir("generated/sources/schemaVersionTests/java") - -val generateSchemaVersionTests by - tasks.registering { - val schemaFiles = - files( - // schema-v0.sql lives in test resources to cover legacy bootstrap behavior; newer H2 - // schema files live in main resources. Scan both so new schema versions get tests - // automatically. - fileTree("src/main/resources/h2") { include("schema-v*.sql") }, - fileTree("src/test/resources/h2") { include("schema-v*.sql") }, - ) - inputs.files(schemaFiles) - outputs.dir(generatedSchemaVersionTestsDir) - - doLast { - val outputDir = - generatedSchemaVersionTestsDir - .get() - .file("org/apache/polaris/persistence/relational/jdbc") - .asFile - delete(outputDir) - outputDir.mkdirs() - - val schemaVersionPattern = Regex("""schema-v(\d+)\.sql""") - val schemaVersions = - schemaFiles.files - .mapNotNull { schemaVersionPattern.matchEntire(it.name)?.groupValues?.get(1)?.toInt() } - .toSortedSet() - - check(schemaVersions.isNotEmpty()) { "No H2 schema files found for JDBC tests" } - - schemaVersions.forEach { schemaVersion -> - outputDir - .resolve( - "AtomicMetastoreManagerWithJdbcBasePersistenceImplV${schemaVersion}SchemaTest.java" - ) - .writeText( - """ - /* - * 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.polaris.persistence.relational.jdbc; - - public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV${schemaVersion}SchemaTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - - @Override - public int schemaVersion() { - return ${schemaVersion}; - } - } - """ - .trimIndent() - .plus("\n") - ) - } - } - } - -sourceSets { test { java.srcDir(generateSchemaVersionTests) } } - -tasks.named("compileTestJava") { dependsOn(generateSchemaVersionTests) } diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java new file mode 100644 index 0000000000..2346dd8142 --- /dev/null +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java @@ -0,0 +1,81 @@ +/* + * 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.polaris.persistence.relational.jdbc; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Comparator; +import java.util.stream.Stream; +import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest; +import org.junit.jupiter.api.DynamicContainer; +import org.junit.jupiter.api.DynamicNode; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestFactory; + +/** + * Runs {@link BasePolarisMetaStoreManagerTest} integration tests against every H2 schema version + * discovered on the classpath. + */ +public class AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest { + + @TestFactory + Stream metastoreTestsForAllH2SchemaVersions() { + return H2SchemaVersions.discover().stream().map(this::testsForSchemaVersion); + } + + private DynamicNode testsForSchemaVersion(int schemaVersion) { + return DynamicContainer.dynamicContainer( + "schema-v" + schemaVersion, + testMethods() + .map( + method -> + DynamicTest.dynamicTest( + method.getName(), () -> runTest(method, schemaVersion)))); + } + + private static Stream testMethods() { + return Arrays.stream(BasePolarisMetaStoreManagerTest.class.getDeclaredMethods()) + .filter(method -> method.isAnnotationPresent(Test.class)) + .sorted(Comparator.comparing(Method::getName)); + } + + private static void runTest(Method method, int schemaVersion) throws Exception { + AtomicMetastoreManagerWithJdbcBasePersistenceImplTest testInstance = + new SchemaVersionTest(schemaVersion); + testInstance.setupPolarisMetaStoreManager(); + method.setAccessible(true); + method.invoke(testInstance); + } + + private static final class SchemaVersionTest + extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { + + private final int schemaVersion; + + private SchemaVersionTest(int schemaVersion) { + this.schemaVersion = schemaVersion; + } + + @Override + public int schemaVersion() { + return schemaVersion; + } + } +} diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java new file mode 100644 index 0000000000..48b03cc9fd --- /dev/null +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java @@ -0,0 +1,50 @@ +/* + * 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.polaris.persistence.relational.jdbc; + +import java.util.SortedSet; +import java.util.TreeSet; + +/** Discovers H2 schema versions available on the test classpath. */ +final class H2SchemaVersions { + + private H2SchemaVersions() {} + + /** + * Returns sorted schema versions for which {@code h2/schema-vN.sql} exists on the classpath. + * + *

schema-v0.sql lives in test resources to cover legacy bootstrap behavior; newer H2 schema + * files live in main resources. Both are merged on the test classpath. + */ + static SortedSet discover() { + ClassLoader classLoader = H2SchemaVersions.class.getClassLoader(); + SortedSet versions = new TreeSet<>(); + for (int version = 0; ; version++) { + String resource = String.format("h2/schema-v%d.sql", version); + if (classLoader.getResource(resource) == null) { + break; + } + versions.add(version); + } + if (versions.isEmpty()) { + throw new IllegalStateException("No H2 schema files found on classpath"); + } + return versions; + } +} From 5ec7401764c81e395c4ad13a0c877b0a1d258373 Mon Sep 17 00:00:00 2001 From: Venkateshwaran Shanmugham Date: Tue, 2 Jun 2026 15:27:06 +0530 Subject: [PATCH 3/3] Simplify JDBC schema version test execution --- ...WithJdbcBasePersistenceImplSchemaTest.java | 66 +++++-------------- .../relational/jdbc/H2SchemaVersions.java | 39 ++++++++--- 2 files changed, 46 insertions(+), 59 deletions(-) diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java index 2346dd8142..58e30de267 100644 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java @@ -18,64 +18,28 @@ */ package org.apache.polaris.persistence.relational.jdbc; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Comparator; import java.util.stream.Stream; -import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest; -import org.junit.jupiter.api.DynamicContainer; -import org.junit.jupiter.api.DynamicNode; -import org.junit.jupiter.api.DynamicTest; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; /** - * Runs {@link BasePolarisMetaStoreManagerTest} integration tests against every H2 schema version - * discovered on the classpath. + * Runs {@link org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest} integration + * tests against every H2 schema version on the classpath. */ -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest { +@ParameterizedClass +@MethodSource("schemaVersions") +public class AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest + extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - @TestFactory - Stream metastoreTestsForAllH2SchemaVersions() { - return H2SchemaVersions.discover().stream().map(this::testsForSchemaVersion); - } - - private DynamicNode testsForSchemaVersion(int schemaVersion) { - return DynamicContainer.dynamicContainer( - "schema-v" + schemaVersion, - testMethods() - .map( - method -> - DynamicTest.dynamicTest( - method.getName(), () -> runTest(method, schemaVersion)))); - } - - private static Stream testMethods() { - return Arrays.stream(BasePolarisMetaStoreManagerTest.class.getDeclaredMethods()) - .filter(method -> method.isAnnotationPresent(Test.class)) - .sorted(Comparator.comparing(Method::getName)); - } + @Parameter int schemaVersion; - private static void runTest(Method method, int schemaVersion) throws Exception { - AtomicMetastoreManagerWithJdbcBasePersistenceImplTest testInstance = - new SchemaVersionTest(schemaVersion); - testInstance.setupPolarisMetaStoreManager(); - method.setAccessible(true); - method.invoke(testInstance); + static Stream schemaVersions() { + return H2SchemaVersions.discoverAsStream(); } - private static final class SchemaVersionTest - extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { - - private final int schemaVersion; - - private SchemaVersionTest(int schemaVersion) { - this.schemaVersion = schemaVersion; - } - - @Override - public int schemaVersion() { - return schemaVersion; - } + @Override + public int schemaVersion() { + return schemaVersion; } } diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java index 48b03cc9fd..6103b8dda1 100644 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java @@ -18,8 +18,11 @@ */ package org.apache.polaris.persistence.relational.jdbc; +import java.util.ArrayList; +import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import java.util.stream.Stream; /** Discovers H2 schema versions available on the test classpath. */ final class H2SchemaVersions { @@ -29,22 +32,42 @@ private H2SchemaVersions() {} /** * Returns sorted schema versions for which {@code h2/schema-vN.sql} exists on the classpath. * - *

schema-v0.sql lives in test resources to cover legacy bootstrap behavior; newer H2 schema - * files live in main resources. Both are merged on the test classpath. + *

Every version from {@code 0} through {@link DatabaseType#H2}{@linkplain + * DatabaseType#getLatestSchemaVersion() latest} must be present. {@code schema-v0.sql} lives in + * test resources to cover legacy bootstrap behavior; newer H2 schema files live in main + * resources. */ static SortedSet discover() { ClassLoader classLoader = H2SchemaVersions.class.getClassLoader(); + int latestVersion = DatabaseType.H2.getLatestSchemaVersion(); SortedSet versions = new TreeSet<>(); - for (int version = 0; ; version++) { - String resource = String.format("h2/schema-v%d.sql", version); + List missingVersions = new ArrayList<>(); + for (int version = 0; version <= latestVersion; version++) { + String resource = + String.format("%s/schema-v%d.sql", DatabaseType.H2.getDisplayName(), version); if (classLoader.getResource(resource) == null) { - break; + missingVersions.add(version); + } else { + versions.add(version); } - versions.add(version); } - if (versions.isEmpty()) { - throw new IllegalStateException("No H2 schema files found on classpath"); + if (!missingVersions.isEmpty()) { + throw new IllegalStateException( + String.format( + "Missing H2 schema resource(s) %s for version(s) %s (expected versions 0-%d)", + missingVersions.stream() + .map( + version -> + String.format( + "%s/schema-v%d.sql", DatabaseType.H2.getDisplayName(), version)) + .toList(), + missingVersions, + latestVersion)); } return versions; } + + static Stream discoverAsStream() { + return discover().stream(); + } }