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/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java similarity index 61% rename from persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest.java rename to persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java index e26a0fccca..58e30de267 100644 --- 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/AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest.java @@ -16,14 +16,30 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.polaris.persistence.relational.jdbc; -public class AtomicMetastoreManagerWithJdbcBasePersistenceImplV4SchemaTest +import java.util.stream.Stream; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Runs {@link org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest} integration + * tests against every H2 schema version on the classpath. + */ +@ParameterizedClass +@MethodSource("schemaVersions") +public class AtomicMetastoreManagerWithJdbcBasePersistenceImplSchemaTest extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest { + @Parameter int schemaVersion; + + static Stream schemaVersions() { + return H2SchemaVersions.discoverAsStream(); + } + @Override public int schemaVersion() { - return 4; + return schemaVersion; } } 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/H2SchemaVersions.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java new file mode 100644 index 0000000000..6103b8dda1 --- /dev/null +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/H2SchemaVersions.java @@ -0,0 +1,73 @@ +/* + * 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.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 { + + private H2SchemaVersions() {} + + /** + * Returns sorted schema versions for which {@code h2/schema-vN.sql} exists on the 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<>(); + 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) { + missingVersions.add(version); + } else { + versions.add(version); + } + } + 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(); + } +}