fateh288 commented on code in PR #592: URL: https://github.com/apache/ranger/pull/592#discussion_r2155560260
########## agents-common/src/test/java/org/apache/ranger/plugin/util/TestServiceTags.java: ########## @@ -112,6 +115,61 @@ public void testDedup_DupTagsWithAttr_MultipleCalls() { assertEquals(0, svcTags.dedupTags()); } + @Test + public void testDedupTags_DuplicateTagWithHigherId() { + // Create ServiceTags with duplicate tags + RangerTag[] tags = { + new RangerTag("PII", Collections.singletonMap("type", "email")), + new RangerTag("PII", Collections.singletonMap("type", "email")), + new RangerTag("PCI", Collections.emptyMap()), + new RangerTag("PCI", Collections.emptyMap()), + new RangerTag("PII", Collections.singletonMap("type", "email")) + }; + + ServiceTags svcTags = createServiceTags(tags, RESOURCES); + assertEquals(5, svcTags.getTags().size()); + // Should remove 3 duplicates (2 PII, 1 PCI) + assertEquals(3, svcTags.dedupTags()); + + // Verify: 2 tags remain (one PII, one PCI) + assertEquals(2, svcTags.getTags().size()); + // Find retained PII tag ID + Long piiTagId = svcTags.getTags().entrySet().stream() + .filter(e -> e.getValue().getType().equals("PII")) + .map(Map.Entry::getKey) + .findFirst() + .orElseThrow(() -> new AssertionError("PII tag not found")); + RangerTag cachedTag = svcTags.getTags().get(piiTagId); + + // Verify resource mappings + assertTrue(svcTags.getResourceToTagIds().values().stream() + .allMatch(tagIds -> tagIds.contains(piiTagId))); + + // Add a new PII tag with higher tag ID + ServiceTags svcTags1 = new ServiceTags(svcTags); + svcTags1.getTags().remove(piiTagId); + RangerTag newTag = new RangerTag("PII", Collections.singletonMap("type", "email")); + long newTagId = 23L; + newTag.setId(newTagId); + svcTags1.getTags().put(newTagId, newTag); + svcTags1.getResourceToTagIds().get(1L).add(newTagId); + + assertEquals(0, svcTags1.dedupTags()); + assertEquals(2, svcTags1.getTags().size()); + assertEquals(cachedTag, svcTags1.getTags().get(piiTagId)); + assertFalse(svcTags1.getTags().containsKey(newTagId)); Review Comment: @vyommani I don't understand why this assertion holds true. piiTagId has been removed frm svcTags1 in line#150, then why should svcTags1 should still have this tag id ? -- 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: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org