dimas-b commented on code in PR #4583:
URL: https://github.com/apache/polaris/pull/4583#discussion_r3335383203


##########
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<DynamicNode> metastoreTestsForAllH2SchemaVersions() {
+    return 
H2SchemaVersions.discover().stream().map(this::testsForSchemaVersion);

Review Comment:
   for later: I'd rather we did this testing with PostgreSQL, which is the 
"main" database 🤔 ... H2 is not expected to be used in "prod", so full schema 
coverage on H2 does not seem to add assurance for end users 🤔 



##########
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<DynamicNode> 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<Method> 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);

Review Comment:
   This is flaky, IMHO, because we provide only a very narrow sub-set of 
functionality that `@Test` method may expect from the JUnit framework... but 
overall, it's probably ok for now.



##########
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<DynamicNode> 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<Method> testMethods() {
+    return 
Arrays.stream(BasePolarisMetaStoreManagerTest.class.getDeclaredMethods())
+        .filter(method -> method.isAnnotationPresent(Test.class))

Review Comment:
   This is a bit too obscure and incomplete. We do not intend to have JUnit 
discover those methods, so why rely on JUnit annotations? We only process 
`@Test` but JUnit has more ways of declaring test methods.



##########
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.
+   *
+   * <p>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<Integer> discover() {
+    ClassLoader classLoader = H2SchemaVersions.class.getClassLoader();
+    SortedSet<Integer> versions = new TreeSet<>();
+    for (int version = 0; ; version++) {
+      String resource = String.format("h2/schema-v%d.sql", version);
+      if (classLoader.getResource(resource) == null) {

Review Comment:
   +1 to @nandorKollar 's comment and it's not a "nit" IMHO :)
   
   I'd check every version number until `DatabaseType.getLatestSchemaVersion()` 
and _fail_ if any version is missing the corresponding schema file resource.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to