Bukama commented on code in PR #367:
URL: https://github.com/apache/maven-enforcer/pull/367#discussion_r2133748822


##########
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:
   Sitenote: Maybe use 
`[@Timeout](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/Timeout.html)`?



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

Reply via email to