lasdf1234 commented on code in PR #11043: URL: https://github.com/apache/gravitino/pull/11043#discussion_r3226695232
########## plugins/idp-basic/src/test/java/org/apache/gravitino/storage/relational/mapper/provider/base/TestIdpGroupMetaBaseSQLProvider.java: ########## @@ -0,0 +1,110 @@ +/* + * 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 org.apache.gravitino.storage.relational.po.IdpGroupPO; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class TestIdpGroupMetaBaseSQLProvider { + + protected IdpGroupMetaBaseSQLProvider createProvider() { + return new IdpGroupMetaBaseSQLProvider(); + } + + protected String expectedDeleteAtClause() { + return "deleted_at = #{deletedAt}"; + } + + protected String expectedDeleteIdpGroupMetasByLegacyTimelineSql() { + return "DELETE FROM idp_group_meta WHERE deleted_at > 0 AND deleted_at < #{legacyTimeline} LIMIT #{limit}"; + } + + @Test + public void testSelectIdpGroup() { + String normalizedSql = createProvider().selectIdpGroup("group").replaceAll("\\s+", " ").trim(); + + Assertions.assertTrue(normalizedSql.contains("SELECT group_id as groupId")); + Assertions.assertTrue(normalizedSql.contains("FROM idp_group_meta")); + Assertions.assertTrue( + normalizedSql.contains("WHERE group_name = #{groupName} AND deleted_at = 0")); + } + + @Test + public void testInsertIdpGroup() { + String normalizedSql = + createProvider().insertIdpGroup(newGroupPO()).replaceAll("\\s+", " ").trim(); + + Assertions.assertTrue(normalizedSql.contains("INSERT INTO idp_group_meta")); + Assertions.assertTrue( + normalizedSql.contains( + "(group_id, group_name, current_version, last_version, deleted_at)")); + Assertions.assertTrue( + normalizedSql.contains( + "VALUES ( #{groupMeta.groupId}, #{groupMeta.groupName}, #{groupMeta.currentVersion}, #{groupMeta.lastVersion}, #{groupMeta.deletedAt} )")); + } + + @Test + public void testSoftDeleteIdpGroup() { + String normalizedSql = + createProvider().softDeleteIdpGroup(1L, 2L).replaceAll("\\s+", " ").trim(); + + Assertions.assertTrue(normalizedSql.contains("UPDATE idp_group_meta")); + Assertions.assertTrue(normalizedSql.contains(expectedDeleteAtClause())); + Assertions.assertTrue(normalizedSql.contains("current_version = current_version + 1")); + Assertions.assertTrue(normalizedSql.contains("last_version = last_version + 1")); + Assertions.assertTrue(normalizedSql.contains("WHERE group_id = #{groupId} AND deleted_at = 0")); + } + + @Test + public void testSoftDeleteIdpGroupDoesNotUseOptimisticLocking() { + IdpGroupMetaBaseSQLProvider provider = createProvider(); + + String normalizedSql = provider.softDeleteIdpGroup(1L, 2L).replaceAll("\\s+", " ").trim(); + + Assertions.assertFalse( + normalizedSql.contains("current_version = #{currentVersion}"), + "Built-in IdP group delete should not use optimistic locking"); + Assertions.assertTrue( + normalizedSql.contains("current_version = current_version + 1"), + "Built-in IdP group delete should increment current_version in place"); + Assertions.assertTrue( + normalizedSql.contains("last_version = last_version + 1"), + "Built-in IdP group delete should increment last_version in place"); + } + + @Test + public void testDeleteIdpGroupMetasByLegacyTimeline() { + String normalizedSql = + createProvider().deleteIdpGroupMetasByLegacyTimeline(1L, 2).replaceAll("\\s+", " ").trim(); + + Assertions.assertEquals(expectedDeleteIdpGroupMetasByLegacyTimelineSql(), normalizedSql); + } + + private IdpGroupPO newGroupPO() { + return IdpGroupPO.builder() + .withGroupId(1L) + .withGroupName("group") + .withCurrentVersion(1L) + .withLastVersion(1L) + .withDeletedAt(0L) + .build(); + } +} Review Comment: Got , I referred to the TestAuthMappers class and rewrote the TestIdpUserMetaMapper, TestIdpGroupMetaMapper, and TestIdpGroupUserRelMapper which can cover these test scenarios. The code has been submitted. -- 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]
