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


##########
persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/JdbcGrantRecordsIdempotencyPostgresIT.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 static 
org.apache.polaris.core.persistence.PrincipalSecretsGenerator.RANDOM_SECRETS;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Optional;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.entity.PolarisGrantRecord;
+import org.apache.polaris.core.storage.PolarisStorageIntegrationProvider;
+import 
org.apache.polaris.test.commons.PostgresRelationalJdbcLifeCycleManagement;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.postgresql.ds.PGSimpleDataSource;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.postgresql.PostgreSQLContainer;
+
+/**
+ * PostgreSQL integration coverage for grant-record insert idempotency. 
Complements {@link
+ * JdbcGrantRecordsIdempotencyTest}, which exercises H2 across schema versions 
v1–v4.
+ */
+@Testcontainers
+class JdbcGrantRecordsIdempotencyPostgresIT {
+
+  private static final RealmContext REALM_CONTEXT = () -> "REALM";
+  private static final int SCHEMA_VERSION = 4;
+
+  private static final long SECURABLE_CATALOG_ID = 1L;
+  private static final long SECURABLE_ID = 2L;
+  private static final long GRANTEE_CATALOG_ID = 3L;
+  private static final long GRANTEE_ID = 4L;
+  private static final int PRIVILEGE_CODE = 21;
+
+  @Container
+  private static final PostgreSQLContainer POSTGRES =
+      new PostgreSQLContainer(
+          containerSpecHelper("postgres", 
PostgresRelationalJdbcLifeCycleManagement.class)
+              .dockerImageName(null)
+              .asCompatibleSubstituteFor("postgres"));
+
+  private static PGSimpleDataSource dataSource;
+  private static JdbcBasePersistenceImpl basePersistence;
+
+  @BeforeAll
+  static void setUp() throws Exception {
+    POSTGRES.start();
+    dataSource = new PGSimpleDataSource();
+    dataSource.setURL(POSTGRES.getJdbcUrl());
+    dataSource.setUser(POSTGRES.getUsername());
+    dataSource.setPassword(POSTGRES.getPassword());
+
+    RelationalJdbcConfiguration configuration =
+        new RelationalJdbcConfiguration() {
+          @Override
+          public Optional<Integer> maxRetries() {
+            return Optional.of(2);
+          }
+
+          @Override
+          public Optional<Long> maxDurationInMs() {
+            return Optional.of(100L);
+          }
+
+          @Override
+          public Optional<Long> initialDelayInMs() {
+            return Optional.of(100L);
+          }
+
+          @Override
+          public Optional<String> databaseType() {
+            return Optional.empty();
+          }
+        };
+
+    DatasourceOperations datasourceOperations = new 
DatasourceOperations(dataSource, configuration);
+    try (InputStream scriptStream =
+        Thread.currentThread()
+            .getContextClassLoader()
+            .getResourceAsStream("postgres/schema-v4.sql")) {
+      if (scriptStream == null) {
+        throw new IllegalStateException("postgres/schema-v4.sql not found on 
classpath");
+      }
+      datasourceOperations.executeScript(scriptStream);
+    }
+
+    basePersistence =
+        new JdbcBasePersistenceImpl(
+            new PolarisDefaultDiagServiceImpl(),
+            datasourceOperations,
+            RANDOM_SECRETS,
+            mock(PolarisStorageIntegrationProvider.class),
+            REALM_CONTEXT.getRealmIdentifier(),
+            SCHEMA_VERSION);
+  }
+
+  @AfterAll
+  static void tearDown() {
+    POSTGRES.stop();
+  }
+
+  @Test
+  void writeToGrantRecordsIsIdempotentOnPostgres() throws SQLException {

Review Comment:
   Should this test be in `BasePolarisMetaStoreManagerTest` for generalization?



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