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();
}
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;
}
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));
}
}
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));
}
}
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));
}
Aggregations