Search in sources :

Example 46 with Reader

use of java.io.Reader in project elasticsearch by elastic.

the class MoreLikeThisQuery method createQuery.

private Query createQuery(XMoreLikeThis mlt) throws IOException {
    BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder();
    if (this.likeFields != null) {
        Query mltQuery = mlt.like(this.likeFields);
        mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
        bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD);
    }
    if (this.likeText != null) {
        Reader[] readers = new Reader[likeText.length];
        for (int i = 0; i < readers.length; i++) {
            readers[i] = new FastStringReader(likeText[i]);
        }
        //LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field)
        Query mltQuery = mlt.like(moreLikeFields[0], readers);
        mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
        bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD);
    }
    return bqBuilder.build();
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) FastStringReader(org.elasticsearch.common.io.FastStringReader) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) FastStringReader(org.elasticsearch.common.io.FastStringReader) Reader(java.io.Reader) IndexReader(org.apache.lucene.index.IndexReader)

Example 47 with Reader

use of java.io.Reader in project elasticsearch by elastic.

the class TransportAnalyzeAction method createStackedTokenStream.

private static TokenStream createStackedTokenStream(String source, CharFilterFactory[] charFilterFactories, TokenizerFactory tokenizerFactory, TokenFilterFactory[] tokenFilterFactories, int current) {
    Reader reader = new FastStringReader(source);
    for (CharFilterFactory charFilterFactory : charFilterFactories) {
        reader = charFilterFactory.create(reader);
    }
    Tokenizer tokenizer = tokenizerFactory.create();
    tokenizer.setReader(reader);
    TokenStream tokenStream = tokenizer;
    for (int i = 0; i < current; i++) {
        tokenStream = tokenFilterFactories[i].create(tokenStream);
    }
    return tokenStream;
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) FastStringReader(org.elasticsearch.common.io.FastStringReader) CharFilterFactory(org.elasticsearch.index.analysis.CharFilterFactory) FastStringReader(org.elasticsearch.common.io.FastStringReader) Reader(java.io.Reader) Tokenizer(org.apache.lucene.analysis.Tokenizer)

Example 48 with Reader

use of java.io.Reader in project buck by facebook.

the class TestCaseSummariesBuildingXctoolEventHandlerTest method noTestCasesAndOcunitFailureReturnsFailedTestResultSummary.

@Test
public void noTestCasesAndOcunitFailureReturnsFailedTestResultSummary() throws Exception {
    Path jsonPath = TestDataHelper.getTestDataDirectory(this).resolve("xctool-output/ocunit-failure.json");
    try (Reader jsonReader = Files.newBufferedReader(jsonPath, StandardCharsets.UTF_8)) {
        TestCaseSummariesBuildingXctoolEventHandler testCaseSummariesBuilder = new TestCaseSummariesBuildingXctoolEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
        XctoolOutputParsing.streamOutputFromReader(jsonReader, testCaseSummariesBuilder);
        List<TestCaseSummary> summaries = testCaseSummariesBuilder.getTestCaseSummaries();
        assertThat(summaries, hasSize(1));
        Matcher<TestResultSummary> summaryMatcher = allOf(hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("message", containsString("dyld: app was built for iOS 8.3 which is newer than this simulator 8.1")));
        assertThat(summaries.get(0).getTestResults(), contains(summaryMatcher));
    }
}
Also used : Path(java.nio.file.Path) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) Reader(java.io.Reader) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Example 49 with Reader

use of java.io.Reader in project buck by facebook.

the class TestCaseSummariesBuildingXctoolEventHandlerTest method mixedPassAndFailReturnsMixedResultSummary.

@Test
@SuppressWarnings("unchecked")
public void mixedPassAndFailReturnsMixedResultSummary() throws Exception {
    Path jsonPath = TestDataHelper.getTestDataDirectory(this).resolve("xctool-output/mixed-pass-and-fail.json");
    try (Reader jsonReader = Files.newBufferedReader(jsonPath, StandardCharsets.UTF_8)) {
        TestCaseSummariesBuildingXctoolEventHandler testCaseSummariesBuilder = new TestCaseSummariesBuildingXctoolEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
        XctoolOutputParsing.streamOutputFromReader(jsonReader, testCaseSummariesBuilder);
        List<TestCaseSummary> summaries = testCaseSummariesBuilder.getTestCaseSummaries();
        assertThat(summaries, hasSize(2));
        Matcher<TestResultSummary> isOtherTestsTestSomethingSuccess = allOf(hasProperty("testCaseName", equalTo("OtherTests")), hasProperty("testName", equalTo("-[OtherTests testSomething]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(3L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
        List<TestResultSummary> otherTestsResults = summaries.get(0).getTestResults();
        assertThat(otherTestsResults, contains(isOtherTestsTestSomethingSuccess));
        Matcher<TestResultSummary> isSomeTestsTestBacktraceOutputIsCaptured = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testBacktraceOutputIsCaptured]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("-[SenTestCase performTest:]")), hasProperty("stdErr", nullValue(String.class)));
        Matcher<TestResultSummary> isSomeTestsTestOutputMerging = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testOutputMerging]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("stdout-line1\nstderr-line1\n")), hasProperty("stdErr", nullValue(String.class)));
        Matcher<TestResultSummary> isSomeTestsTestPrintSDK = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testPrintSDK]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(1L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString("SDK: 6.1")), hasProperty("stdErr", nullValue(String.class)));
        Matcher<TestResultSummary> isSomeTestsTestStream = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testStream]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(754L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", containsString(">>>> i = 0")), hasProperty("stdErr", nullValue(String.class)));
        Matcher<TestResultSummary> isSomeTestsTestWillFail = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testWillFail]")), hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("time", equalTo(0L)), hasProperty("message", containsString("SomeTests.m:40: 'a' should be equal to 'b'")), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
        Matcher<TestResultSummary> isSomeTestsTestWillPass = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("-[SomeTests testWillPass]")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
        List<TestResultSummary> someTestsResults = summaries.get(1).getTestResults();
        assertThat(someTestsResults, contains(isSomeTestsTestBacktraceOutputIsCaptured, isSomeTestsTestOutputMerging, isSomeTestsTestPrintSDK, isSomeTestsTestStream, isSomeTestsTestWillFail, isSomeTestsTestWillPass));
    }
}
Also used : Path(java.nio.file.Path) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) Reader(java.io.Reader) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Example 50 with Reader

use of java.io.Reader in project buck by facebook.

the class XctestOutputParsingTest method streamingSimpleSuccess.

@Test
public void streamingSimpleSuccess() throws Exception {
    Path outputPath = TestDataHelper.getTestDataDirectory(this).resolve("xctest-output/simple-success.txt");
    final List<Object> streamedObjects = new ArrayList<>();
    try (Reader outputReader = Files.newBufferedReader(outputPath, StandardCharsets.UTF_8)) {
        XctestOutputParsing.streamOutput(outputReader, eventCallbackAddingEventsToList(streamedObjects));
    }
    assertThat(streamedObjects, hasSize(8));
    Iterator<Object> iter = streamedObjects.iterator();
    Object nextStreamedObject;
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginXctestEvent.class));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestSuiteEvent.class));
    XctestOutputParsing.BeginTestSuiteEvent beginTestSuiteEvent1 = (XctestOutputParsing.BeginTestSuiteEvent) nextStreamedObject;
    assertThat(beginTestSuiteEvent1.suite, equalTo("Example/ExampleTests.xctest(Tests)"));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestSuiteEvent.class));
    XctestOutputParsing.BeginTestSuiteEvent beginTestSuiteEvent2 = (XctestOutputParsing.BeginTestSuiteEvent) nextStreamedObject;
    assertThat(beginTestSuiteEvent2.suite, equalTo("SuccessTests"));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestCaseEvent.class));
    XctestOutputParsing.BeginTestCaseEvent beginTestEvent = (XctestOutputParsing.BeginTestCaseEvent) nextStreamedObject;
    assertThat(beginTestEvent.test, equalTo("-[SuccessTests testSuccess]"));
    assertThat(beginTestEvent.className, equalTo("SuccessTests"));
    assertThat(beginTestEvent.methodName, equalTo("testSuccess"));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestCaseEvent.class));
    XctestOutputParsing.EndTestCaseEvent endTestEvent = (XctestOutputParsing.EndTestCaseEvent) nextStreamedObject;
    assertThat(endTestEvent.test, equalTo("-[SuccessTests testSuccess]"));
    assertThat(endTestEvent.className, equalTo("SuccessTests"));
    assertThat(endTestEvent.methodName, equalTo("testSuccess"));
    assertThat(endTestEvent.output, equalTo("-- test output --\n"));
    assertThat(endTestEvent.succeeded, is(true));
    assertThat(endTestEvent.exceptions, empty());
    assertThat(endTestEvent.totalDuration, closeTo(0.003, EPSILON));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestSuiteEvent.class));
    XctestOutputParsing.EndTestSuiteEvent endTestSuiteEvent2 = (XctestOutputParsing.EndTestSuiteEvent) nextStreamedObject;
    assertThat(endTestSuiteEvent2.suite, equalTo("SuccessTests"));
    assertThat(endTestSuiteEvent2.testCaseCount, equalTo(1));
    assertThat(endTestSuiteEvent2.totalFailureCount, equalTo(0));
    assertThat(endTestSuiteEvent2.unexpectedExceptionCount, equalTo(0));
    assertThat(endTestSuiteEvent2.testDuration, closeTo(0.012, EPSILON));
    assertThat(endTestSuiteEvent2.totalDuration, closeTo(0.013, EPSILON));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestSuiteEvent.class));
    XctestOutputParsing.EndTestSuiteEvent endTestSuiteEvent1 = (XctestOutputParsing.EndTestSuiteEvent) nextStreamedObject;
    assertThat(endTestSuiteEvent1.suite, equalTo("Example/ExampleTests.xctest(Tests)"));
    assertThat(endTestSuiteEvent1.testCaseCount, equalTo(1));
    assertThat(endTestSuiteEvent1.totalFailureCount, equalTo(0));
    assertThat(endTestSuiteEvent1.unexpectedExceptionCount, equalTo(0));
    assertThat(endTestSuiteEvent1.testDuration, closeTo(0.012, EPSILON));
    assertThat(endTestSuiteEvent1.totalDuration, closeTo(0.051, EPSILON));
    nextStreamedObject = iter.next();
    assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndXctestEvent.class));
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Reader (java.io.Reader)1498 InputStreamReader (java.io.InputStreamReader)526 StringReader (java.io.StringReader)498 IOException (java.io.IOException)348 BufferedReader (java.io.BufferedReader)242 InputStream (java.io.InputStream)219 TokenStream (org.apache.lucene.analysis.TokenStream)171 Test (org.junit.Test)170 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)137 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileReader (java.io.FileReader)108 FileInputStream (java.io.FileInputStream)107 File (java.io.File)105 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 SqlSession (org.apache.ibatis.session.SqlSession)83 StringWriter (java.io.StringWriter)81 ArrayList (java.util.ArrayList)77 Writer (java.io.Writer)63