-
Notifications
You must be signed in to change notification settings - Fork 30
Update PathMaskChecker for Directory List #2505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
addons/koji/common/src/test/java/org/commonjava/indy/koji/util/PathMaskCheckerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package org.commonjava.indy.koji.util; | ||
|
|
||
| import org.commonjava.indy.core.content.PathMaskChecker; | ||
| import org.commonjava.indy.model.core.HostedRepository; | ||
| import org.commonjava.indy.model.core.RemoteRepository; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| public class PathMaskCheckerTest | ||
| { | ||
|
|
||
| @Test | ||
| public void extractGroupIdPath() throws Exception | ||
| { | ||
| List<Map.Entry<String, String>> metadataFiles = List.of( | ||
| Map.entry("com/github/fge/msg-simple/maven-metadata.xml", "com/github/fge/"), | ||
| Map.entry("org/jboss/eap/jboss-eap-parent/maven-metadata.xml", "org/jboss/eap/"), | ||
| Map.entry("org/apache/lucene/lucene-core/maven-metadata.xml", "org/apache/lucene/"), | ||
| Map.entry("org/wildfly/security/wildfly-elytron/maven-metadata.xml", "org/wildfly/security/"), | ||
| Map.entry("io/dropwizard/metrics/metrics-core/maven-metadata.xml", "io/dropwizard/metrics/"), | ||
| Map.entry("org/jboss/spec/javax/el/jboss-el-api_3.0_spec/maven-metadata.xml", "org/jboss/spec/javax/el/") | ||
| ); | ||
|
|
||
| for (var entry : metadataFiles) | ||
| { | ||
| assertEquals( entry.getValue(), PathMaskChecker.extractGroupIdPath(entry.getKey()) ); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void checkListingMask() throws Exception | ||
| { | ||
| HostedRepository hostedRepository = new HostedRepository( | ||
| "mvn-hosted" | ||
| ); | ||
|
|
||
| RemoteRepository mrrcRepo = new RemoteRepository( | ||
| "mrrc-ga", | ||
| "http://example.url" | ||
| ); | ||
| mrrcRepo.setPathMaskPatterns( | ||
| Set.of("r|.+[-.]redhat[-_]\\d+.*|") | ||
| ); | ||
|
|
||
| RemoteRepository repositoryMatched = new RemoteRepository( | ||
| "koji-org.infinispan-infinispan-parent-9.4.2.Final_redhat_00001-2", | ||
| "http://example.url" | ||
| ); | ||
| repositoryMatched.setPathMaskPatterns( | ||
| Set.of("r|org\\/infinispan\\/.+\\/9.4.2.Final-redhat-00001\\/.+|", | ||
| "org/infinispan/infinispan-query-dsl/maven-metadata.xml", | ||
| "r|org\\/infinispan\\/server\\/.+\\/9.4.2.Final-redhat-00001\\/.+|")); | ||
|
|
||
| RemoteRepository repositoryUnMatched = new RemoteRepository( | ||
| "koji-org.jboss.eap-jboss-eap-parent-7.2.0.GA_redhat_00002-2", | ||
| "http://example.url" | ||
| ); | ||
| repositoryUnMatched.setPathMaskPatterns( | ||
| Set.of("r|org\\/jboss\\/eap\\/.+\\/7.2.0.GA-redhat-00002\\/.+|", | ||
| "org/jboss/eap/jboss-eap-parent/maven-metadata.xml")); | ||
|
|
||
| RemoteRepository repositoryWithMultipleGroupIds = new RemoteRepository( | ||
| "koji-com.sun.mail-all-1.6.1.redhat_1-1", | ||
| "http://example.url" | ||
| ); | ||
| repositoryWithMultipleGroupIds.setPathMaskPatterns( | ||
| Set.of("javax/mail/javax.mail-api/maven-metadata.xml", | ||
| "com/sun/mail/javax.mail-api/maven-metadata.xml", | ||
| "r|javax\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|", | ||
| "r|com\\/sun\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|")); | ||
|
|
||
| assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/")); | ||
| assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/infinispan/")); | ||
| assertTrue(PathMaskChecker.checkListingMask(repositoryMatched, "org/infinispan/infinispan-component-annotations/")); | ||
| assertTrue(PathMaskChecker.checkListingMask(repositoryWithMultipleGroupIds, "com/sun/mail/")); | ||
| assertTrue(PathMaskChecker.checkListingMask(repositoryWithMultipleGroupIds, "javax/mail/")); | ||
| assertFalse(PathMaskChecker.checkListingMask(repositoryUnMatched, "org/infinispan/")); | ||
|
|
||
| assertTrue(PathMaskChecker.checkListingMask(hostedRepository, "org/infinispan/")); | ||
| assertTrue(PathMaskChecker.checkListingMask(mrrcRepo, "org/infinispan/")); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean it is faster to check the groupId against meta pattern before checking all patterns?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking all patterns does not work for some cases, like the following patterns of the repo maven:remote:koji-com.sun.mail-all-1.6.1.redhat_1-1:
"path_mask_patterns": [ "com/sun/mail/javax.mail/maven-metadata.xml", "r|com\\/sun\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|", "r|javax\\/mail\\/.+\\/1.6.1.redhat-1\\/.+|" ],it does not work if the directory listing path is "/com/sun/mail/android". And the android-1.6.1.redhat-1.pom is also one of the artifacts produced by that brew build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing this https://issues.redhat.com/browse/MMENG-4453 will resolve the above issue, but we need to make it compatible on the exiting remote koji repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this make a lot many repos return true? if group matches (/com/sun/mail), such repo will be listed even the artifact not match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function is aiming to reduce the repo candidates for further query against cassandra or brew. When I debug this, it now returns all koji-* repos which is ~2500 on prod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand this pr is to fix the file missing issue when listing, so you use the groupId to filter first. Am I right? If so, let's go with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why it now returns all koji-* repos? if the patterns do not match, it should filter most of them...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it because old line 76? if ( isRegexPattern( pattern ) ) --> this could return true when hit the regex pattern. maybe it always hit it and finally returns all koji repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's it line 76 and the reason in the comment line 78~80.
And this PR is still for the listing performance issue, https://issues.redhat.com/browse/MMENG-4447 .
There are attached logs I found during tests that would be helpful to know how it costs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM