Skip to content
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 @@ -290,10 +290,7 @@ public void testHashCodeWithThreads() throws Exception {
for (int i = 0; i < queries.length; i++) {
queries[i] =
new AutomatonQuery(
new Term("bogus", "bogus"),
Operations.determinize(
AutomatonTestUtil.randomAutomaton(random()),
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT));
new Term("bogus", "bogus"), AutomatonTestUtil.randomDeterminizedAutomaton(random()));
}
final CountDownLatch startingGun = new CountDownLatch(1);
int numThreads = TestUtil.nextInt(random(), 2, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ public void testMergeAcceptStatesWithNoTransition() {
int iters = atLeast(100);
for (int iter = 0; iter < iters; iter++) {
// sameLanguage requires a deterministic automaton
Automaton expected =
Operations.determinize(AutomatonTestUtil.randomAutomaton(random()), Integer.MAX_VALUE);
Automaton expected = AutomatonTestUtil.randomDeterminizedAutomaton(random());
Automaton actual = Operations.mergeAcceptStatesWithNoTransition(expected);
assertTrue(AutomatonTestUtil.sameLanguage(expected, actual));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import org.apache.lucene.util.Version;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.CompiledAutomaton;
import org.apache.lucene.util.automaton.Operations;

/** Helper class extracted from BasePostingsFormatTestCase to exercise a postings format. */
public class RandomPostingsTester {
Expand Down Expand Up @@ -1703,8 +1702,7 @@ private void testTermsOneThread(
// Test Terms.intersect:
for (String field : fields.keySet()) {
while (true) {
Automaton a = AutomatonTestUtil.randomAutomaton(random);
a = Operations.determinize(a, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
Automaton a = AutomatonTestUtil.randomDeterminizedAutomaton(random);
CompiledAutomaton ca = new CompiledAutomaton(a, false, true, false);
if (ca.type != CompiledAutomaton.AUTOMATON_TYPE.NORMAL) {
// Keep retrying until we get an A that will really "use" the PF's intersect code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ public static Automaton randomAutomaton(Random random) {
}
}

/** return a random DFA for testing */
public static Automaton randomDeterminizedAutomaton(Random random) {
while (true) {
try {
return Operations.determinize(
randomAutomaton(random), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
} catch (TooComplexToDeterminizeException _) {
// This can (rarely) happen if the random automaton is too hard; just try again...
}
}
}

/*
* below are original, unoptimized implementations of DFA operations for testing. These are from
* brics automaton, full license (BSD) below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ public void testRandomStrings() throws Exception {
public void testRandomRegexps() throws Exception {
int iters = TEST_NIGHTLY ? atLeast(30) : atLeast(1);
for (int i = 0; i < iters; i++) {
Automaton automaton =
Operations.determinize(
AutomatonTestUtil.randomAutomaton(random()),
Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
Automaton automaton = AutomatonTestUtil.randomDeterminizedAutomaton(random());
final CharacterRunAutomaton dfa = new CharacterRunAutomaton(automaton);
final boolean lowercase = random().nextBoolean();
final int limit = TestUtil.nextInt(random(), 0, 500);
Expand Down
Loading