lasdf1234 commented on code in PR #11066: URL: https://github.com/apache/gravitino/pull/11066#discussion_r3239454813
########## plugins/idp-basic/src/test/java/org/apache/gravitino/storage/relational/mapper/provider/base/TestIdpUserMetaBaseSQLProvider.java: ########## @@ -0,0 +1,188 @@ +/* + * 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.storage.relational.mapper.provider.base; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.gravitino.storage.relational.po.IdpUserPO; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.SqlSource; +import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver; +import org.apache.ibatis.session.Configuration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class TestIdpUserMetaBaseSQLProvider { + + protected IdpUserMetaBaseSQLProvider createProvider() { + return new IdpUserMetaBaseSQLProvider(); + } + + protected String expectedDeleteAtClause() { + return "deleted_at = (UNIX_TIMESTAMP() * 1000.0) + EXTRACT(MICROSECOND FROM CURRENT_TIMESTAMP(3)) / 1000"; + } + + protected String expectedDeleteIdpUserMetasByLegacyTimelineSql() { + return "DELETE FROM idp_user_meta WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit}"; + } + + @Test + public void testSelectIdpUser() { + String normalizedSql = createProvider().selectIdpUser("tom").replaceAll("\\s+", " ").trim(); + + Assertions.assertTrue(normalizedSql.contains("SELECT user_id as userId")); + Assertions.assertTrue(normalizedSql.contains("FROM idp_user_meta")); + Assertions.assertTrue( + normalizedSql.contains("WHERE user_name = #{userName} AND deleted_at = 0")); + } + + @Test + public void testSelectIdpUsers() { + String script = createProvider().selectIdpUsers(Arrays.asList("tom", "jerry")); + Map<String, Object> params = new HashMap<>(); + params.put("userNames", Arrays.asList("tom", "jerry")); + + String normalizedSql = renderScript(script, params); + + Assertions.assertTrue(normalizedSql.contains("SELECT user_id as userId")); + Assertions.assertTrue(normalizedSql.contains("FROM idp_user_meta")); + Assertions.assertTrue(normalizedSql.matches(".*user_name IN \\( \\? , \\? \\).*")); + Assertions.assertFalse(normalizedSql.matches(".*\\b1\\s*=\\s*0\\b.*")); + } + + @Test + public void testSelectIdpUsersWithEmptyUserNames() { + String script = createProvider().selectIdpUsers(Collections.emptyList()); + Map<String, Object> params = new HashMap<>(); + params.put("userNames", Collections.emptyList()); + + String normalizedSql = renderScript(script, params); + + Assertions.assertFalse( + normalizedSql.matches(".*\\bIN\\s*\\(\\s*\\).*"), + "Empty userNames should not generate invalid SQL IN (...) with no values"); + Assertions.assertTrue( + normalizedSql.matches(".*\\b1\\s*=\\s*0\\b.*"), + "Empty userNames should result in an unsatisfiable WHERE clause (e.g., AND 1 = 0)"); + } + + @Test + public void testSelectIdpUsersWithNullUserNames() { + String script = createProvider().selectIdpUsers(null); + Map<String, Object> params = new HashMap<>(); + params.put("userNames", null); + + String normalizedSql = renderScript(script, params); + + Assertions.assertFalse( + normalizedSql.matches(".*\\bIN\\s*\\(\\s*\\).*"), + "Null userNames should not generate invalid SQL IN (...) with no values"); + Assertions.assertTrue( + normalizedSql.matches(".*\\b1\\s*=\\s*0\\b.*"), + "Null userNames should result in an unsatisfiable WHERE clause (e.g., AND 1 = 0)"); + } + + @Test + public void testInsertIdpUser() { + String normalizedSql = + createProvider().insertIdpUser(newUserPO()).replaceAll("\\s+", " ").trim(); + + Assertions.assertTrue(normalizedSql.contains("INSERT INTO idp_user_meta")); + Assertions.assertTrue( + normalizedSql.contains( + "(user_id, user_name, password_hash, current_version, last_version, deleted_at)")); + Assertions.assertTrue( + normalizedSql.contains( + "VALUES ( #{userMeta.userId}, #{userMeta.userName}, #{userMeta.passwordHash}, #{userMeta.currentVersion}, #{userMeta.lastVersion}, #{userMeta.deletedAt} )")); Review Comment: Got, The code has been modified and I have also asked the AI to review other sections with more than 100 chars for me. The code has been changed. ########## plugins/idp-basic/src/test/java/org/apache/gravitino/storage/relational/mapper/provider/h2/TestIdpUserMetaH2Provider.java: ########## @@ -0,0 +1,31 @@ +/* + * 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.storage.relational.mapper.provider.h2; + +import org.apache.gravitino.storage.relational.mapper.provider.base.IdpUserMetaBaseSQLProvider; +import org.apache.gravitino.storage.relational.mapper.provider.base.TestIdpUserMetaBaseSQLProvider; + +public class TestIdpUserMetaH2Provider extends TestIdpUserMetaBaseSQLProvider { Review Comment: Got, I have already used @Tag("gravitino-docker-test") for MySQL and PG test. ########## plugins/idp-basic/build.gradle.kts: ########## @@ -24,10 +24,27 @@ plugins { } dependencies { + implementation(project(":core")) implementation(libs.bcprov.jdk18on) implementation(libs.commons.lang3) implementation(libs.guava) + implementation(libs.mybatis) + testImplementation(project(":api")) Review Comment: Got,remove testImplementation(project(":api")),The code has been revised. ########## plugins/idp-basic/build.gradle.kts: ########## @@ -24,10 +24,28 @@ plugins { } dependencies { + annotationProcessor(libs.lombok) + implementation(project(":core")) implementation(libs.bcprov.jdk18on) implementation(libs.commons.lang3) implementation(libs.guava) + implementation(libs.mybatis) + compileOnly(libs.lombok) + testImplementation(project(":clients:client-java")) + testImplementation(project(":common")) + testImplementation(project(":core")) + testImplementation(project(":server")) Review Comment: ":server" and ":server-common" are indirectly dependent through BaseIT (used for starting MySQL/PG Testcontainers) and cannot be removed. -- 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]
