harrisric commented on code in PR #367: URL: https://github.com/apache/maven-enforcer/pull/367#discussion_r2133792237
########## enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/TestArtifactMatcher.java: ########## @@ -125,6 +125,37 @@ void testMatch() { executeMatch(matcher, "groupId", "anotherArtifact", "1.1", "", "", false); } + @Test + void testMatcherPerformance() { + patterns.add("groupId:artifactId:1.0"); + patterns.add("*:anotherArtifact"); + + ignorePatterns.add("badGroup:*:*:test"); + ignorePatterns.add("*:anotherArtifact:1.1"); + + ArtifactMatcher matcher = new ArtifactMatcher(patterns, ignorePatterns); + + long startTime = System.nanoTime(); + Artifact artifactGood1 = createMockArtifact("groupId", "artifactId", "1.0", "", "", ""); + Artifact artifactGood2 = createMockArtifact("groupId", "anotherArtifact", "1.0", "", "", ""); + Artifact artifactBad1 = createMockArtifact("badGroup", "artifactId", "1.0", "", "test", ""); + Artifact artifactGood3 = createMockArtifact("badGroup", "anotherArtifact", "1.0", "", "", ""); + Artifact artifactBad2 = createMockArtifact("groupId", "anotherArtifact", "1.1", "", "", ""); + for (int i = 0; i < 10_000; i++) { + assertEquals(true, matcher.match(artifactGood1)); + assertEquals(true, matcher.match(artifactGood2)); + assertEquals(false, matcher.match(artifactBad1)); + assertEquals(true, matcher.match(artifactGood3)); + assertEquals(false, matcher.match(artifactBad2)); + } + long timeTakenNs = System.nanoTime() - startTime; + assertTrue( + timeTakenNs < 200_000_000, + String.format( + "Time taken for repeated tests should be less than 200ms, but was: %dms", + timeTakenNs / 1_000_000)); + } Review Comment: @slawekjaranowski - I don't think that `ArtifactMatcher` is a very volatile area of the codebase so perhaps over-zealous to keep the performance test in. Therefore I'm happy to just take this as proof that that change is behaving as intended (i.e. you can run the test with/without the other changes and see the difference in performance) and remove it from the PR going forward (it's not doing anything exotic and so easy to recreate) to avoid any potential build flakiness. @Bukama - thanks, that's a good recommendation I'll remember for the future. Then a question remains whether to extend the technique to `RequireReleaseDeps `and `BannedPlugins` - happy to do that in this PR or a separate one, based on your preferences. -- 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: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org