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


##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplPostgresSchemaIT.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 static 
org.apache.polaris.containerspec.ContainerSpecHelper.containerSpecHelper;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.stream.Stream;
+import javax.sql.DataSource;
+import 
org.apache.polaris.test.commons.PostgresRelationalJdbcLifeCycleManagement;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.postgresql.ds.PGSimpleDataSource;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.postgresql.PostgreSQLContainer;
+
+/**
+ * Runs {@link 
org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest} integration
+ * tests against every PostgreSQL schema version on the classpath.
+ */
+@Testcontainers
+@ParameterizedClass
+@MethodSource("schemaVersions")
+public class AtomicMetastoreManagerWithJdbcBasePersistenceImplPostgresSchemaIT
+    extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest {
+
+  @Container
+  private static final PostgreSQLContainer POSTGRES =
+      new PostgreSQLContainer(
+          containerSpecHelper("postgres", 
PostgresRelationalJdbcLifeCycleManagement.class)
+              .dockerImageName(null)
+              .asCompatibleSubstituteFor("postgres"));
+
+  @Parameter int schemaVersion;
+
+  private DataSource dataSource;
+
+  static Stream<Integer> schemaVersions() {
+    return SchemaVersions.discoverAsStream(DatabaseType.POSTGRES);
+  }
+
+  @Override
+  protected DatabaseType databaseType() {
+    return DatabaseType.POSTGRES;
+  }
+
+  @Override
+  public int schemaVersion() {
+    return schemaVersion;
+  }
+
+  @Override
+  protected DataSource createDataSource() {
+    if (dataSource == null) {
+      dataSource = createPostgresDataSource(schemaVersion());
+    }
+    return dataSource;
+  }
+
+  private static DataSource createPostgresDataSource(int schemaVersion) {
+    String databaseName = "polaris_schema_v" + schemaVersion;
+    createDatabaseIfNotExists(databaseName);
+
+    PGSimpleDataSource postgresDataSource = new PGSimpleDataSource();
+    postgresDataSource.setURL(jdbcUrlForDatabase(databaseName));
+    postgresDataSource.setUser(POSTGRES.getUsername());
+    postgresDataSource.setPassword(POSTGRES.getPassword());
+    return postgresDataSource;
+  }
+
+  private static void createDatabaseIfNotExists(String databaseName) {
+    try (Connection connection =
+            DriverManager.getConnection(
+                POSTGRES.getJdbcUrl(), POSTGRES.getUsername(), 
POSTGRES.getPassword());
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE DATABASE " + databaseName);
+    } catch (SQLException e) {
+      if (!"42P04".equals(e.getSQLState())) {

Review Comment:
   Could you add a comment about that this error code means? 😅 



##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplPostgresSchemaIT.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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 static 
org.apache.polaris.containerspec.ContainerSpecHelper.containerSpecHelper;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.stream.Stream;
+import javax.sql.DataSource;
+import 
org.apache.polaris.test.commons.PostgresRelationalJdbcLifeCycleManagement;
+import org.junit.jupiter.params.Parameter;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.postgresql.ds.PGSimpleDataSource;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.postgresql.PostgreSQLContainer;
+
+/**
+ * Runs {@link 
org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest} integration
+ * tests against every PostgreSQL schema version on the classpath.
+ */
+@Testcontainers
+@ParameterizedClass
+@MethodSource("schemaVersions")
+public class AtomicMetastoreManagerWithJdbcBasePersistenceImplPostgresSchemaIT
+    extends AtomicMetastoreManagerWithJdbcBasePersistenceImplTest {
+
+  @Container
+  private static final PostgreSQLContainer POSTGRES =
+      new PostgreSQLContainer(
+          containerSpecHelper("postgres", 
PostgresRelationalJdbcLifeCycleManagement.class)

Review Comment:
   `PostgresRelationalJdbcLifeCycleManagement` is not relevant here. It should 
be "this" class ;)



##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/TestRelationalJdbcConfiguration.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.Optional;
+
+/** Shared {@link RelationalJdbcConfiguration} for JDBC persistence 
integration tests. */
+final class TestRelationalJdbcConfiguration implements 
RelationalJdbcConfiguration {

Review Comment:
   nit: this class does not "test" the configuration class, it implements it to 
provide configuration to actual test cases... I propose renaming to 
`SimpleRelationalJdbcConfiguration` for the sake of clarity.



##########
polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java:
##########
@@ -1209,16 +1209,18 @@ boolean isPolicyMappingRecordExists(
       PolarisBaseEntity target,
       PolicyEntity policy,
       Map<String, String> parameters) {
-    PolarisPolicyMappingRecord expected =
-        new PolarisPolicyMappingRecord(
-            target.getCatalogId(),
-            target.getId(),
-            policy.getCatalogId(),
-            policy.getId(),
-            policy.getPolicyTypeCode(),
-            parameters);
+    Map<String, String> expectedParameters = parameters == null ? Map.of() : 
parameters;
     long policyMappingCount =
-        policyMappingRecords.stream().filter(record -> 
expected.equals(record)).count();
+        policyMappingRecords.stream()
+            .filter(
+                record ->
+                    record.getPolicyCatalogId() == policy.getCatalogId()

Review Comment:
   What's the difference from the "natural" comparator?



##########
polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisPersistenceTestSupport.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.core.persistence;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.jspecify.annotations.NonNull;
+
+/** Shared helpers for persistence integration tests. */
+final class PolarisPersistenceTestSupport {
+
+  private PolarisPersistenceTestSupport() {}
+
+  /**
+   * Asserts two entities are equivalent, comparing JSON-backed fields by 
parsed map content instead
+   * of raw serialized strings. This avoids false negatives when backends such 
as PostgreSQL JSONB
+   * rewrite JSON formatting while preserving semantics.
+   */
+  static void assertEntitiesEquivalent(
+      @NonNull PolarisBaseEntity actual, @NonNull PolarisBaseEntity expected) {
+    
assertThat(PolarisEntity.toCore(actual)).isEqualTo(PolarisEntity.toCore(expected));
+    assertThat(actual.getSubTypeCode()).isEqualTo(expected.getSubTypeCode());
+    
assertThat(actual.getCreateTimestamp()).isEqualTo(expected.getCreateTimestamp());
+    
assertThat(actual.getDropTimestamp()).isEqualTo(expected.getDropTimestamp());
+    
assertThat(actual.getPurgeTimestamp()).isEqualTo(expected.getPurgeTimestamp());
+    
assertThat(actual.getToPurgeTimestamp()).isEqualTo(expected.getToPurgeTimestamp());
+    
assertThat(actual.getLastUpdateTimestamp()).isEqualTo(expected.getLastUpdateTimestamp());
+    
assertThat(actual.getGrantRecordsVersion()).isEqualTo(expected.getGrantRecordsVersion());
+    
assertThat(actual.getPropertiesAsMap()).isEqualTo(expected.getPropertiesAsMap());
+    assertThat(actual.getInternalPropertiesAsMap())
+        .isEqualTo(expected.getInternalPropertiesAsMap());
+  }
+
+  static void assertEntitiesEquivalentInAnyOrder(
+      @NonNull List<PolarisBaseEntity> actual, @NonNull 
List<PolarisBaseEntity> expected) {
+    assertThat(actual).hasSameSizeAs(expected);
+    List<PolarisBaseEntity> unmatched = new ArrayList<>(expected);
+    for (PolarisBaseEntity actualEntity : actual) {
+      PolarisBaseEntity match =
+          unmatched.stream()
+              .filter(candidate -> entitiesEquivalent(actualEntity, candidate))
+              .findFirst()
+              .orElse(null);
+      assertThat(match)
+          .as("No equivalent entity found in expected list for %s", 
actualEntity)
+          .isNotNull();
+      unmatched.remove(match);
+    }
+  }
+
+  private static boolean entitiesEquivalent(

Review Comment:
   Is it functionally different from `PolarisBaseEntity.equals()`?



##########
polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisPersistenceTestSupport.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.core.persistence;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polaris.core.entity.PolarisBaseEntity;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.jspecify.annotations.NonNull;
+
+/** Shared helpers for persistence integration tests. */
+final class PolarisPersistenceTestSupport {
+
+  private PolarisPersistenceTestSupport() {}
+
+  /**
+   * Asserts two entities are equivalent, comparing JSON-backed fields by 
parsed map content instead
+   * of raw serialized strings. This avoids false negatives when backends such 
as PostgreSQL JSONB
+   * rewrite JSON formatting while preserving semantics.
+   */
+  static void assertEntitiesEquivalent(
+      @NonNull PolarisBaseEntity actual, @NonNull PolarisBaseEntity expected) {
+    
assertThat(PolarisEntity.toCore(actual)).isEqualTo(PolarisEntity.toCore(expected));
+    assertThat(actual.getSubTypeCode()).isEqualTo(expected.getSubTypeCode());
+    
assertThat(actual.getCreateTimestamp()).isEqualTo(expected.getCreateTimestamp());
+    
assertThat(actual.getDropTimestamp()).isEqualTo(expected.getDropTimestamp());
+    
assertThat(actual.getPurgeTimestamp()).isEqualTo(expected.getPurgeTimestamp());
+    
assertThat(actual.getToPurgeTimestamp()).isEqualTo(expected.getToPurgeTimestamp());
+    
assertThat(actual.getLastUpdateTimestamp()).isEqualTo(expected.getLastUpdateTimestamp());
+    
assertThat(actual.getGrantRecordsVersion()).isEqualTo(expected.getGrantRecordsVersion());
+    
assertThat(actual.getPropertiesAsMap()).isEqualTo(expected.getPropertiesAsMap());
+    assertThat(actual.getInternalPropertiesAsMap())
+        .isEqualTo(expected.getInternalPropertiesAsMap());
+  }
+
+  static void assertEntitiesEquivalentInAnyOrder(
+      @NonNull List<PolarisBaseEntity> actual, @NonNull 
List<PolarisBaseEntity> expected) {

Review Comment:
   Traditional `assertEquals` methods have `expected` as the first argument 🤷 



-- 
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