Copilot commented on code in PR #11066:
URL: https://github.com/apache/gravitino/pull/11066#discussion_r3240538703


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/storage/relational/mapper/provider/base/IdpUserMetaBaseSQLProvider.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational.mapper.provider.base;
+
+import java.util.List;
+import 
org.apache.gravitino.idp.basic.storage.relational.mapper.IdpUserMetaMapper;
+import org.apache.gravitino.idp.basic.storage.relational.po.IdpUserPO;
+import org.apache.ibatis.annotations.Param;
+
+public abstract class IdpUserMetaBaseSQLProvider {
+
+  public String selectIdpUser(@Param("username") String username) {
+    return "SELECT user_id as userId, user_name as userName, password_hash as 
passwordHash,"
+        + " current_version as currentVersion,"
+        + " last_version as lastVersion, deleted_at as deletedAt"
+        + " FROM "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " WHERE user_name = #{username} AND deleted_at = 0";
+  }
+
+  public String selectIdpUsers(@Param("usernames") List<String> usernames) {
+    return "<script>"
+        + "SELECT user_id as userId, user_name as userName, password_hash as 
passwordHash,"
+        + " current_version as currentVersion,"
+        + " last_version as lastVersion, deleted_at as deletedAt"
+        + " FROM "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " WHERE deleted_at = 0 "
+        + "<choose>"
+        + "<when test='usernames != null and usernames.size() > 0'>"
+        + "AND user_name IN ("
+        + "<foreach item='item' collection='usernames' separator=','>"
+        + "#{item}"
+        + "</foreach>"
+        + ") "
+        + "</when>"
+        + "<otherwise>"
+        + "AND 1 = 0 "
+        + "</otherwise>"
+        + "</choose>"
+        + "</script>";
+  }
+
+  public String insertIdpUser(@Param("userMeta") IdpUserPO userPO) {
+    return "INSERT INTO "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " (user_id, user_name, password_hash, current_version, last_version, 
deleted_at)"
+        + " VALUES ("
+        + " #{userMeta.userId},"
+        + " #{userMeta.userName},"
+        + " #{userMeta.passwordHash},"
+        + " #{userMeta.currentVersion},"
+        + " #{userMeta.lastVersion},"
+        + " #{userMeta.deletedAt}"
+        + " )";
+  }
+
+  public String updateIdpUserPassword(
+      @Param("userId") Long userId, @Param("passwordHash") String 
passwordHash) {
+    return "UPDATE "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " SET password_hash = #{passwordHash}"
+        + " WHERE user_id = #{userId}"
+        + " AND deleted_at = 0";
+  }
+
+  public String softDeleteIdpUser(@Param("userId") Long userId) {
+    return "UPDATE "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " SET deleted_at = "
+        + currentTimeMillisExpression()
+        + " WHERE user_id = #{userId} AND deleted_at = 0";
+  }
+
+  public String deleteIdpUserMetasByLegacyTimeline(
+      @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit) 
{
+    return "DELETE FROM "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT 
#{limit}";
+  }

Review Comment:
   PostgreSQL does not support `DELETE ... LIMIT` directly (which is why 
`IdpUserMetaPostgreSQLProvider` overrides this method). However, this base 
implementation is inherited by any future dialect that forgets to override it, 
and the SQL fragment here is essentially MySQL/H2-specific. Consider making 
this method abstract (like `currentTimeMillisExpression()`) so each dialect 
must provide an explicit implementation, preventing silent breakage when adding 
new backends.
   



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/basic/storage/relational/BackendTestExtension.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Stream;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.storage.relational.JDBCBackend;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
+
+public class BackendTestExtension
+    implements TestTemplateInvocationContextProvider, BeforeAllCallback, 
AfterAllCallback {
+
+  private static final String DOCKER_TEST_FLAG = "dockerTest";
+  private static final ExtensionContext.Namespace NAMESPACE =
+      ExtensionContext.Namespace.create(BackendTestExtension.class);
+  private static final String STORE_KEY = "BACKEND_MAP";
+
+  @Override
+  public void beforeAll(ExtensionContext context) {
+    context.getStore(NAMESPACE).put(STORE_KEY, new ConcurrentHashMap<String, 
BackendResource>());
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public void afterAll(ExtensionContext context) throws Exception {
+    ConcurrentHashMap<String, BackendResource> map =
+        (ConcurrentHashMap<String, BackendResource>) 
context.getStore(NAMESPACE).get(STORE_KEY);
+    if (map != null) {
+      for (BackendResource backendResource : map.values()) {
+        backendResource.close();
+      }
+      map.clear();
+    }
+  }
+
+  @Override
+  public boolean supportsTestTemplate(ExtensionContext context) {
+    return 
TestJDBCBackend.class.isAssignableFrom(context.getRequiredTestClass());
+  }
+
+  @Override
+  public Stream<TestTemplateInvocationContext> 
provideTestTemplateInvocationContexts(
+      ExtensionContext context) {
+    return resolveBackends(context.getRequiredTestClass()).stream()
+        .map(BackendInvocationContext::new);
+  }
+
+  private List<String> resolveBackends(Class<?> testClass) {
+    BackendTypes backendTypes = findBackendTypes(testClass);
+    if (backendTypes != null) {
+      return List.of(backendTypes.value());
+    }
+
+    List<String> backendsToTest = new ArrayList<>();
+    backendsToTest.add("h2");
+    if ("true".equalsIgnoreCase(System.getenv(DOCKER_TEST_FLAG))) {
+      backendsToTest.add("mysql");
+      backendsToTest.add("postgresql");
+    }
+    return backendsToTest;
+  }
+
+  private BackendTypes findBackendTypes(Class<?> testClass) {
+    Class<?> current = testClass;
+    while (current != null) {
+      BackendTypes backendTypes = 
current.getDeclaredAnnotation(BackendTypes.class);
+      if (backendTypes != null) {
+        return backendTypes;
+      }
+      current = current.getSuperclass();
+    }
+    return null;
+  }
+
+  private static class BackendInvocationContext implements 
TestTemplateInvocationContext {
+    private final String backendType;
+
+    private BackendInvocationContext(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public String getDisplayName(int invocationIndex) {
+      return String.format("[%s Backend]", backendType.toUpperCase());
+    }
+
+    @Override
+    public List<Extension> getAdditionalExtensions() {
+      return Collections.singletonList(new BackendSetupCallback(backendType));
+    }
+  }
+
+  private static class BackendSetupCallback implements BeforeEachCallback {
+    private final String backendType;
+
+    private BackendSetupCallback(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext context) throws Exception {
+      BackendResource backendResource = getOrCreateBackendResource(context, 
backendType);
+      Object testInstance = context.getRequiredTestInstance();
+      if (testInstance instanceof TestJDBCBackend) {
+        ((TestJDBCBackend) testInstance).setBackend(backendResource.backend());
+        ((TestJDBCBackend) testInstance).setBackendType(backendType);
+      }
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private static Map<String, BackendResource> 
getBackendResources(ExtensionContext context) {
+    return (Map<String, BackendResource>) 
context.getStore(NAMESPACE).get(STORE_KEY, Map.class);
+  }
+
+  private static BackendResource getOrCreateBackendResource(
+      ExtensionContext context, String backendType) throws SQLException {
+    Map<String, BackendResource> backendResources = 
getBackendResources(context);
+    BackendResource backendResource = backendResources.get(backendType);
+    if (backendResource != null) {
+      return backendResource;
+    }
+
+    backendResource = createBackendResource(backendType);
+    backendResources.put(backendType, backendResource);
+    return backendResource;
+  }
+
+  private static BackendResource createBackendResource(String backendType) 
throws SQLException {
+    BaseIT baseIT = new BaseIT();
+    Config config = new Config(false) {};
+    Path h2Path = null;
+    config.set(Configs.ENTITY_STORE, Configs.RELATIONAL_ENTITY_STORE);
+    config.set(Configs.ENTITY_RELATIONAL_STORE, backendType);
+    config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_MAX_CONNECTIONS, 20);
+    config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_WAIT_MILLISECONDS, 
1000L);
+
+    if ("mysql".equals(backendType)) {
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL, 
baseIT.startAndInitMySQLBackend());
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PASSWORD, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_DRIVER, 
"com.mysql.cj.jdbc.Driver");
+    } else if ("postgresql".equals(backendType)) {
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL, 
baseIT.startAndInitPGBackend());
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PASSWORD, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_DRIVER, 
"org.postgresql.Driver");
+    } else {
+      try {
+        String uuid = UUID.randomUUID().toString().replace("-", "");
+        h2Path = Path.of("/tmp", "gravitino_jdbc_test_h2_" + uuid);
+        Files.createDirectories(h2Path);
+      } catch (IOException e) {

Review Comment:
   Hard-coding `/tmp` makes this test unrunnable on Windows and bypasses the OS 
temp directory convention. Use 
`Files.createTempDirectory(\"gravitino_jdbc_test_h2_\")` or 
`System.getProperty(\"java.io.tmpdir\")` to obtain a portable temp location.



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/basic/storage/relational/BackendTestExtension.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Stream;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.storage.relational.JDBCBackend;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
+
+public class BackendTestExtension
+    implements TestTemplateInvocationContextProvider, BeforeAllCallback, 
AfterAllCallback {
+
+  private static final String DOCKER_TEST_FLAG = "dockerTest";
+  private static final ExtensionContext.Namespace NAMESPACE =
+      ExtensionContext.Namespace.create(BackendTestExtension.class);
+  private static final String STORE_KEY = "BACKEND_MAP";
+
+  @Override
+  public void beforeAll(ExtensionContext context) {
+    context.getStore(NAMESPACE).put(STORE_KEY, new ConcurrentHashMap<String, 
BackendResource>());
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public void afterAll(ExtensionContext context) throws Exception {
+    ConcurrentHashMap<String, BackendResource> map =
+        (ConcurrentHashMap<String, BackendResource>) 
context.getStore(NAMESPACE).get(STORE_KEY);
+    if (map != null) {
+      for (BackendResource backendResource : map.values()) {
+        backendResource.close();
+      }
+      map.clear();
+    }
+  }
+
+  @Override
+  public boolean supportsTestTemplate(ExtensionContext context) {
+    return 
TestJDBCBackend.class.isAssignableFrom(context.getRequiredTestClass());
+  }
+
+  @Override
+  public Stream<TestTemplateInvocationContext> 
provideTestTemplateInvocationContexts(
+      ExtensionContext context) {
+    return resolveBackends(context.getRequiredTestClass()).stream()
+        .map(BackendInvocationContext::new);
+  }
+
+  private List<String> resolveBackends(Class<?> testClass) {
+    BackendTypes backendTypes = findBackendTypes(testClass);
+    if (backendTypes != null) {
+      return List.of(backendTypes.value());
+    }
+
+    List<String> backendsToTest = new ArrayList<>();
+    backendsToTest.add("h2");
+    if ("true".equalsIgnoreCase(System.getenv(DOCKER_TEST_FLAG))) {
+      backendsToTest.add("mysql");
+      backendsToTest.add("postgresql");
+    }
+    return backendsToTest;
+  }
+
+  private BackendTypes findBackendTypes(Class<?> testClass) {
+    Class<?> current = testClass;
+    while (current != null) {
+      BackendTypes backendTypes = 
current.getDeclaredAnnotation(BackendTypes.class);
+      if (backendTypes != null) {
+        return backendTypes;
+      }
+      current = current.getSuperclass();
+    }
+    return null;
+  }
+
+  private static class BackendInvocationContext implements 
TestTemplateInvocationContext {
+    private final String backendType;
+
+    private BackendInvocationContext(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public String getDisplayName(int invocationIndex) {
+      return String.format("[%s Backend]", backendType.toUpperCase());
+    }
+
+    @Override
+    public List<Extension> getAdditionalExtensions() {
+      return Collections.singletonList(new BackendSetupCallback(backendType));
+    }
+  }
+
+  private static class BackendSetupCallback implements BeforeEachCallback {
+    private final String backendType;
+
+    private BackendSetupCallback(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext context) throws Exception {
+      BackendResource backendResource = getOrCreateBackendResource(context, 
backendType);
+      Object testInstance = context.getRequiredTestInstance();
+      if (testInstance instanceof TestJDBCBackend) {
+        ((TestJDBCBackend) testInstance).setBackend(backendResource.backend());
+        ((TestJDBCBackend) testInstance).setBackendType(backendType);
+      }
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private static Map<String, BackendResource> 
getBackendResources(ExtensionContext context) {
+    return (Map<String, BackendResource>) 
context.getStore(NAMESPACE).get(STORE_KEY, Map.class);
+  }
+
+  private static BackendResource getOrCreateBackendResource(
+      ExtensionContext context, String backendType) throws SQLException {
+    Map<String, BackendResource> backendResources = 
getBackendResources(context);
+    BackendResource backendResource = backendResources.get(backendType);
+    if (backendResource != null) {
+      return backendResource;
+    }
+
+    backendResource = createBackendResource(backendType);
+    backendResources.put(backendType, backendResource);
+    return backendResource;
+  }
+
+  private static BackendResource createBackendResource(String backendType) 
throws SQLException {
+    BaseIT baseIT = new BaseIT();
+    Config config = new Config(false) {};
+    Path h2Path = null;
+    config.set(Configs.ENTITY_STORE, Configs.RELATIONAL_ENTITY_STORE);
+    config.set(Configs.ENTITY_RELATIONAL_STORE, backendType);
+    config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_MAX_CONNECTIONS, 20);
+    config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_WAIT_MILLISECONDS, 
1000L);
+
+    if ("mysql".equals(backendType)) {
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL, 
baseIT.startAndInitMySQLBackend());
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PASSWORD, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_DRIVER, 
"com.mysql.cj.jdbc.Driver");
+    } else if ("postgresql".equals(backendType)) {
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL, 
baseIT.startAndInitPGBackend());
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PASSWORD, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_DRIVER, 
"org.postgresql.Driver");
+    } else {
+      try {
+        String uuid = UUID.randomUUID().toString().replace("-", "");
+        h2Path = Path.of("/tmp", "gravitino_jdbc_test_h2_" + uuid);
+        Files.createDirectories(h2Path);
+      } catch (IOException e) {
+        throw new RuntimeException("Create H2 test directory failed", e);
+      }
+
+      config.set(
+          Configs.ENTITY_RELATIONAL_JDBC_BACKEND_URL,
+          String.format("jdbc:h2:file:%s;DB_CLOSE_DELAY=-1;MODE=MYSQL", 
h2Path));
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_USER, "root");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PASSWORD, "123456");
+      config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_DRIVER, 
"org.h2.Driver");
+    }
+
+    JDBCBackend jdbcBackend = new JDBCBackend();
+    try {
+      jdbcBackend.close();
+    } catch (IOException e) {
+      throw new RuntimeException("Close JDBC backend before initialization 
failed", e);
+    }

Review Comment:
   Calling `close()` immediately after constructing a fresh `JDBCBackend` 
(before `initialize`) is non-obvious. If this is a workaround for shared static 
state in `SqlSessionFactoryHelper`, please add a comment explaining why this is 
necessary; otherwise, remove the redundant close/exception-handling block.
   



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/storage/relational/mapper/IdpUserMetaMapper.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational.mapper;
+
+import java.util.List;
+import org.apache.gravitino.idp.basic.storage.relational.po.IdpUserPO;
+import org.apache.ibatis.annotations.DeleteProvider;
+import org.apache.ibatis.annotations.InsertProvider;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.SelectProvider;
+import org.apache.ibatis.annotations.UpdateProvider;

Review Comment:
   The mapper's `@*Provider` annotations reference 
`IdpUserMetaSQLProviderFactory` and call its static methods (`selectIdpUser`, 
etc.). The factory's public static methods carry `@Param` annotations even 
though `@Param` on static provider methods has no effect — only the mapper 
interface parameters need `@Param`. Consider removing the redundant `@Param` 
annotations on the factory's static methods to reduce confusion about where 
parameter binding actually occurs.



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/basic/storage/relational/mapper/TestIdpUserMetaMapperH2.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational.mapper;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.gravitino.idp.basic.storage.relational.BackendTypes;
+import org.junit.jupiter.api.TestTemplate;
+
+@BackendTypes({"h2"})
+public class TestIdpUserMetaMapperH2 extends IdpMapperTestBase implements 
IdpUserMetaMapperTest {
+
+  @Override
+  public IdpMapperTestBase testBase() {
+    return this;
+  }
+
+  @TestTemplate
+  public void testInsertIdpUserAndSelectIdpUser() {
+    IdpUserMetaMapperTest.super.testInsertIdpUserAndSelectIdpUser();
+  }
+
+  @TestTemplate
+  public void testSelectIdpUsers() {
+    IdpUserMetaMapperTest.super.testSelectIdpUsers();
+  }
+
+  @TestTemplate
+  public void testSelectIdpUsersIgnoresDeletedUsers() {
+    IdpUserMetaMapperTest.super.testSelectIdpUsersIgnoresDeletedUsers();
+  }
+
+  @TestTemplate
+  public void testUpdateIdpUserPassword() {
+    IdpUserMetaMapperTest.super.testUpdateIdpUserPassword();
+  }
+
+  @TestTemplate
+  public void testUpdateIdpUserPasswordKeepsVersionsUnchanged() {
+    
IdpUserMetaMapperTest.super.testUpdateIdpUserPasswordKeepsVersionsUnchanged();
+  }
+
+  @TestTemplate
+  public void testUpdateIdpUserPasswordReturnsZeroForDeletedUser() {
+    
IdpUserMetaMapperTest.super.testUpdateIdpUserPasswordReturnsZeroForDeletedUser();
+  }
+
+  @TestTemplate
+  public void testSoftDeleteIdpUser() {
+    IdpUserMetaMapperTest.super.testSoftDeleteIdpUser();
+  }
+
+  @TestTemplate
+  public void testSoftDeleteIdpUserReturnsZeroForDeletedUser() {
+    
IdpUserMetaMapperTest.super.testSoftDeleteIdpUserReturnsZeroForDeletedUser();
+  }
+
+  @TestTemplate
+  public void testSoftDeleteIdpUserRunsWithH2Provider() {
+    assertEquals("h2", backendType);
+
+    insertUser(1L, "alice", "hash-a", 1L, 0L, 0L);
+    assertEquals(1, idpUserMetaMapper.softDeleteIdpUser(1L));
+    assertTrue(queryLongValueInMapperTest("idp_user_meta", "deleted_at", 
"user_id", 1L) > 0L);
+  }

Review Comment:
   This test largely duplicates `testSoftDeleteIdpUser` from 
`IdpUserMetaMapperTest` with only an added `assertEquals(\"h2\", backendType)` 
line. Since `@BackendTypes({\"h2\"})` already constrains this class to H2, the 
extra assertion is redundant. Consider removing this duplicate test or, if the 
intent is to verify backend-specific behavior, document what distinguishes it 
from the inherited test.



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/basic/storage/relational/BackendTestExtension.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.gravitino.idp.basic.storage.relational;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Stream;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.storage.relational.JDBCBackend;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
+
+public class BackendTestExtension
+    implements TestTemplateInvocationContextProvider, BeforeAllCallback, 
AfterAllCallback {
+
+  private static final String DOCKER_TEST_FLAG = "dockerTest";
+  private static final ExtensionContext.Namespace NAMESPACE =
+      ExtensionContext.Namespace.create(BackendTestExtension.class);
+  private static final String STORE_KEY = "BACKEND_MAP";
+
+  @Override
+  public void beforeAll(ExtensionContext context) {
+    context.getStore(NAMESPACE).put(STORE_KEY, new ConcurrentHashMap<String, 
BackendResource>());
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public void afterAll(ExtensionContext context) throws Exception {
+    ConcurrentHashMap<String, BackendResource> map =
+        (ConcurrentHashMap<String, BackendResource>) 
context.getStore(NAMESPACE).get(STORE_KEY);
+    if (map != null) {
+      for (BackendResource backendResource : map.values()) {
+        backendResource.close();
+      }
+      map.clear();
+    }
+  }
+
+  @Override
+  public boolean supportsTestTemplate(ExtensionContext context) {
+    return 
TestJDBCBackend.class.isAssignableFrom(context.getRequiredTestClass());
+  }
+
+  @Override
+  public Stream<TestTemplateInvocationContext> 
provideTestTemplateInvocationContexts(
+      ExtensionContext context) {
+    return resolveBackends(context.getRequiredTestClass()).stream()
+        .map(BackendInvocationContext::new);
+  }
+
+  private List<String> resolveBackends(Class<?> testClass) {
+    BackendTypes backendTypes = findBackendTypes(testClass);
+    if (backendTypes != null) {
+      return List.of(backendTypes.value());
+    }
+
+    List<String> backendsToTest = new ArrayList<>();
+    backendsToTest.add("h2");
+    if ("true".equalsIgnoreCase(System.getenv(DOCKER_TEST_FLAG))) {
+      backendsToTest.add("mysql");
+      backendsToTest.add("postgresql");
+    }
+    return backendsToTest;
+  }
+
+  private BackendTypes findBackendTypes(Class<?> testClass) {
+    Class<?> current = testClass;
+    while (current != null) {
+      BackendTypes backendTypes = 
current.getDeclaredAnnotation(BackendTypes.class);
+      if (backendTypes != null) {
+        return backendTypes;
+      }
+      current = current.getSuperclass();
+    }
+    return null;
+  }
+
+  private static class BackendInvocationContext implements 
TestTemplateInvocationContext {
+    private final String backendType;
+
+    private BackendInvocationContext(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public String getDisplayName(int invocationIndex) {
+      return String.format("[%s Backend]", backendType.toUpperCase());
+    }
+
+    @Override
+    public List<Extension> getAdditionalExtensions() {
+      return Collections.singletonList(new BackendSetupCallback(backendType));
+    }
+  }
+
+  private static class BackendSetupCallback implements BeforeEachCallback {
+    private final String backendType;
+
+    private BackendSetupCallback(String backendType) {
+      this.backendType = backendType;
+    }
+
+    @Override
+    public void beforeEach(ExtensionContext context) throws Exception {
+      BackendResource backendResource = getOrCreateBackendResource(context, 
backendType);
+      Object testInstance = context.getRequiredTestInstance();
+      if (testInstance instanceof TestJDBCBackend) {
+        ((TestJDBCBackend) testInstance).setBackend(backendResource.backend());
+        ((TestJDBCBackend) testInstance).setBackendType(backendType);
+      }
+    }

Review Comment:
   `getOrCreateBackendResource` reads then puts into the map non-atomically; if 
test templates are ever parallelized, two threads could create duplicate 
`JDBCBackend` instances for the same backend type and leak resources. Consider 
using `ConcurrentMap#computeIfAbsent` (note that the value factory throws 
`SQLException`, so wrap accordingly) to make the get-or-create atomic.



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