@Override public Object create(Random random) { int num = random.nextInt(10); StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(random.nextBoolean()); for (int i = 0; i < num; i++) { String input = ""; do { input = TestUtil.randomRealisticUnicodeString(random); } while(input.isEmpty()); String out = ""; TestUtil.randomSimpleString(random); do { out = TestUtil.randomRealisticUnicodeString(random); } while(out.isEmpty()); builder.add(input, out); } try { return builder.build(); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
private OutOfMemoryError getOOM(Throwable disaster, IndexWriter writer, PrintStream log) { Throwable e = disaster; if (e instanceof AlreadyClosedException) { e = e.getCause(); } if (e instanceof OutOfMemoryError && e.getMessage() != null && e.getMessage().startsWith("Fake OutOfMemoryError")) { log.println("\nTEST: got expected fake exc:" + e.getMessage()); e.printStackTrace(log); // TODO: remove rollback here, and add this assert to ensure "full OOM protection" anywhere IW does writes // assertTrue("hit OOM but writer is still open, WTF: ", writer.isClosed()); try { writer.rollback(); } catch (Throwable t) {} return (OutOfMemoryError) e; } else { Rethrow.rethrow(disaster); return null; // dead } }
@Override public Object create(Random random) { int num = random.nextInt(10); StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(random.nextBoolean()); for (int i = 0; i < num; i++) { String input = ""; do { input = _TestUtil.randomRealisticUnicodeString(random); } while(input.isEmpty()); String out = ""; _TestUtil.randomSimpleString(random); do { out = _TestUtil.randomRealisticUnicodeString(random); } while(out.isEmpty()); builder.add(input, out); } try { return builder.build(); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
@Override public Object create(Random random) { // TODO: make nastier InputStream affixStream = TestHunspellStemFilter.class.getResourceAsStream("simple.aff"); InputStream dictStream = TestHunspellStemFilter.class.getResourceAsStream("simple.dic"); try { return new Dictionary(affixStream, dictStream); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
@Override public Object create(Random random) { // TODO: make nastier try { InputSource is = new InputSource(TestCompoundWordTokenFilter.class.getResource("da_UTF8.xml").toExternalForm()); HyphenationTree hyphenator = Lucene43HyphenationCompoundWordTokenFilter.getHyphenationTree(is); return hyphenator; } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
@Override public Object create(Random random) { try { String lang = TestSnowball.SNOWBALL_LANGS[random.nextInt(TestSnowball.SNOWBALL_LANGS.length)]; Class<? extends SnowballProgram> clazz = Class.forName("org.tartarus.snowball.ext." + lang + "Stemmer").asSubclass(SnowballProgram.class); return clazz.newInstance(); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
@Override public Object create(Random random) { SynonymMap.Builder b = new SynonymMap.Builder(random.nextBoolean()); final int numEntries = atLeast(10); for (int j = 0; j < numEntries; j++) { addSyn(b, randomNonEmptyString(random), randomNonEmptyString(random), random.nextBoolean()); } try { return b.build(); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
private <T> T createComponent(Constructor<T> ctor, Object[] args, StringBuilder descr) { try { final T instance = ctor.newInstance(args); /* if (descr.length() > 0) { descr.append(","); } */ descr.append("\n "); descr.append(ctor.getDeclaringClass().getName()); String params = Arrays.deepToString(args); params = params.substring(1, params.length()-1); descr.append("(").append(params).append(")"); return instance; } catch (InvocationTargetException ite) { final Throwable cause = ite.getCause(); if (cause instanceof IllegalArgumentException || cause instanceof UnsupportedOperationException) { // thats ok, ignore if (VERBOSE) { System.err.println("Ignoring IAE/UOE from ctor:"); cause.printStackTrace(System.err); } } else { Rethrow.rethrow(cause); } } catch (IllegalAccessException iae) { Rethrow.rethrow(iae); } catch (InstantiationException ie) { Rethrow.rethrow(ie); } return null; // no success }
@Override public void run() { boolean success = false; try { latch.await(); // see the part in checkRandomData where it replays the same text again // to verify reproducability/reuse: hopefully this would catch thread hazards. checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw); success = true; } catch (Exception e) { Rethrow.rethrow(e); } finally { failed = !success; } }
@Override public Object create(Random random) { // TODO: make nastier InputStream affixStream = HunspellDictionaryTest.class.getResourceAsStream("test.aff"); InputStream dictStream = HunspellDictionaryTest.class.getResourceAsStream("test.dic"); try { return new HunspellDictionary(affixStream, dictStream, TEST_VERSION_CURRENT); } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
@Override public Object create(Random random) { // TODO: make nastier try { InputSource is = new InputSource(TestCompoundWordTokenFilter.class.getResource("da_UTF8.xml").toExternalForm()); HyphenationTree hyphenator = HyphenationCompoundWordTokenFilter.getHyphenationTree(is); return hyphenator; } catch (Exception ex) { Rethrow.rethrow(ex); return null; // unreachable code } }
private <T> T createComponent(Constructor<T> ctor, Object[] args, StringBuilder descr) { try { final T instance = ctor.newInstance(args); /* if (descr.length() > 0) { descr.append(","); } */ descr.append("\n "); descr.append(ctor.getDeclaringClass().getName()); String params = Arrays.toString(args); params = params.substring(1, params.length()-1); descr.append("(").append(params).append(")"); return instance; } catch (InvocationTargetException ite) { final Throwable cause = ite.getCause(); if (cause instanceof IllegalArgumentException || cause instanceof UnsupportedOperationException) { // thats ok, ignore if (VERBOSE) { System.err.println("Ignoring IAE/UOE from ctor:"); cause.printStackTrace(System.err); } } else { Rethrow.rethrow(cause); } } catch (IllegalAccessException iae) { Rethrow.rethrow(iae); } catch (InstantiationException ie) { Rethrow.rethrow(ie); } return null; // no success }
@Override public void run() { boolean success = false; try { // see the part in checkRandomData where it replays the same text again // to verify reproducability/reuse: hopefully this would catch thread hazards. checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw); success = true; } catch (IOException e) { Rethrow.rethrow(e); } finally { failed = !success; } }