Skip to content
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

Fix match result is always false in MatchesListRegexDecideRule #328

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.FutureTask;
Expand Down Expand Up @@ -118,7 +117,7 @@ protected boolean evaluate(CrawlURI uri) {
FutureTask<Boolean> matchesFuture = new FutureTask<>(() -> p.matcher(interruptible).matches());
ForkJoinPool.commonPool().submit(matchesFuture);
try {
matchesFuture.get(getTimeoutPerRegexSeconds(), TimeUnit.SECONDS);
matches = matchesFuture.get(getTimeoutPerRegexSeconds(), TimeUnit.SECONDS);
} catch (TimeoutException e) {
matchesFuture.cancel(true);
logger.warning("Timed out after " + getTimeoutPerRegexSeconds() + " seconds waiting for '" + p + "' to match.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.archive.modules.deciderules;

import com.google.common.annotations.VisibleForTesting;
import junit.framework.TestCase;
import org.apache.commons.httpclient.URIException;
import org.archive.modules.CrawlURI;
Expand Down Expand Up @@ -32,4 +31,21 @@ public void testEvaluate() throws URIException {
final DecideResult decideResult = rule.decisionFor(curi);
assertEquals("Expected NONE not " + decideResult , DecideResult.NONE, decideResult);
}

public void testEvaluateInTime() throws URIException {
final String regex = "http://www\\.netarkivet\\.dk/x+";
String seed = "http://www.netarkivet.dk/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
MatchesListRegexDecideRule rule = new MatchesListRegexDecideRule();
List<Pattern> patternList = new ArrayList<>();
patternList.add(Pattern.compile(regex));
rule.setRegexList(patternList);
rule.setEnabled(true);
rule.setListLogicalOr(true);
rule.setDecision(DecideResult.REJECT);
rule.setTimeoutPerRegexSeconds(2);
final CrawlURI curi = new CrawlURI(UURIFactory.getInstance(seed));
final DecideResult decideResult = rule.decisionFor(curi);
assertEquals("Expected REJECT not " + decideResult , DecideResult.REJECT, decideResult);
}

}