use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class JsonRendererTestCase method test.
@Test
public final void test() throws IOException, InterruptedException, ExecutionException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"c\": \"d\",\n" + " \"uri\": \"http://localhost/1\"\n" + " },\n" + " \"id\": \"http://localhost/1\",\n" + " \"relevance\": 0.9,\n" + " \"types\": [\n" + " \"summary\"\n" + " ]\n" + " }\n" + " ],\n" + " \"id\": \"usual\",\n" + " \"relevance\": 1.0\n" + " },\n" + " {\n" + " \"fields\": {\n" + " \"e\": \"f\"\n" + " },\n" + " \"id\": \"type grouphit\",\n" + " \"relevance\": 1.0,\n" + " \"types\": [\n" + " \"grouphit\"\n" + " ]\n" + " },\n" + " {\n" + " \"fields\": {\n" + " \"b\": \"foo\",\n" + " \"uri\": \"http://localhost/\"\n" + " },\n" + " \"id\": \"http://localhost/\",\n" + " \"relevance\": 0.95,\n" + " \"types\": [\n" + " \"summary\"\n" + " ]\n" + " }\n" + " ],\n" + " \"coverage\": {\n" + " \"coverage\": 100,\n" + " \"documents\": 500,\n" + " \"full\": true,\n" + " \"nodes\": 1,\n" + " \"results\": 1,\n" + " \"resultsFull\": 1\n" + " },\n" + " \"errors\": [\n" + " {\n" + " \"code\": 18,\n" + " \"message\": \"boom\",\n" + " \"summary\": \"Internal server error.\"\n" + " }\n" + " ],\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}";
Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
Execution execution = new Execution(Execution.Context.createContextStub());
Result r = new Result(q);
r.setCoverage(new Coverage(500, 1, true));
FastHit h = new FastHit("http://localhost/", .95);
h.setField("$a", "Hello, world.");
h.setField("b", "foo");
r.hits().add(h);
HitGroup g = new HitGroup("usual");
h = new FastHit("http://localhost/1", .90);
h.setField("c", "d");
g.add(h);
r.hits().add(g);
HitGroup gg = new HitGroup("type grouphit");
gg.types().add("grouphit");
gg.setField("e", "f");
r.hits().add(gg);
r.hits().addError(ErrorMessage.createInternalServerError("boom"));
String summary = render(execution, r);
assertEqualJson(expected, summary);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class JsonRendererTestCase method testTracingWithEmptySubtree.
@SuppressWarnings("unchecked")
@Test
public final void testTracingWithEmptySubtree() throws IOException, InterruptedException, ExecutionException {
String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " },\n" + " \"trace\": {\n" + " \"children\": [\n" + " {\n" + " \"message\": \"No query profile is used\"\n" + " },\n" + " {\n" + " \"message\": \"Resolved properties:\\ntracelevel=10 (value from request)\\nquery=a (value from request)\\n\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"timestamp\": 42\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + "}";
Query q = new Query("/?query=a&tracelevel=10");
Execution execution = new Execution(Execution.Context.createContextStub());
Result r = new Result(q);
execution.search(q);
new Execution(new Chain<>(), execution.context());
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ListenableFuture<Boolean> f = renderer.render(bs, r, execution, null);
assertTrue(f.get());
String summary = Utf8.toString(bs.toByteArray());
ObjectMapper m = new ObjectMapper();
Map<String, Object> exp = m.readValue(expected, Map.class);
Map<String, Object> gen = m.readValue(summary, Map.class);
{
// nuke timestamp and check it's there
Map<String, Object> trace = (Map<String, Object>) gen.get("trace");
List<Object> children1 = (List<Object>) trace.get("children");
Map<String, Object> subtrace = (Map<String, Object>) children1.get(2);
List<Object> children2 = (List<Object>) subtrace.get("children");
Map<String, Object> traceElement = (Map<String, Object>) children2.get(0);
traceElement.put("timestamp", Integer.valueOf(42));
}
assertEquals(exp, gen);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class JsonRendererTestCase method testEmptyTracing.
@Test
public final void testEmptyTracing() throws IOException, InterruptedException, ExecutionException {
String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
Query q = new Query("/?query=a&tracelevel=0");
Execution execution = new Execution(Execution.Context.createContextStub());
Result r = new Result(q);
execution.search(q);
Execution e2 = new Execution(new Chain<Searcher>(), execution.context());
Query subQuery = new Query("/?query=b&tracelevel=0");
e2.search(subQuery);
subQuery.trace("yellow", 1);
q.trace("marker", 1);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ListenableFuture<Boolean> f = renderer.render(bs, r, execution, null);
assertTrue(f.get());
String summary = Utf8.toString(bs.toByteArray());
assertEqualJson(expected, summary);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class JsonRendererTestCase method testTracingOfNestedNodesWithDataAndSubnodes.
@Test
public final void testTracingOfNestedNodesWithDataAndSubnodes() throws IOException, InterruptedException, ExecutionException {
String expected = "{\n" + " \"root\": {\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " },\n" + " \"trace\": {\n" + " \"children\": [\n" + " {\n" + " \"message\": \"No query profile is used\"\n" + " },\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"message\": \"string payload\",\n" + " \"children\": [\n" + " {\n" + " \"children\": [\n" + " {\n" + " \"message\": \"in OO languages, nesting is for birds\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + " }\n" + "}\n";
Query q = new Query("/?query=a&tracelevel=1");
Execution execution = new Execution(Execution.Context.createContextStub());
Result r = new Result(q);
execution.search(q);
final TraceNode child = new TraceNode("string payload", 0L);
final TraceNode childOfChild = new TraceNode(null, 0L);
child.add(childOfChild);
childOfChild.add(new TraceNode("in OO languages, nesting is for birds", 0L));
execution.trace().traceNode().add(child);
String summary = render(execution, r);
assertEqualJson(expected, summary);
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class AsyncGroupPopulationTestCase method test.
@Test
public final void test() throws InterruptedException, ExecutionException, JsonParseException, JsonMappingException, IOException {
String rawExpected = "{" + " \"root\": {" + " \"children\": [" + " {" + " \"id\": \"yahoo1\"," + " \"relevance\": 1.0" + " }," + " {" + " \"id\": \"yahoo2\"," + " \"relevance\": 1.0" + " }" + " ]," + " \"fields\": {" + " \"totalCount\": 0" + " }," + " \"id\": \"yahoo\"," + " \"relevance\": 1.0" + " }" + "}";
ByteArrayOutputStream out = new ByteArrayOutputStream();
HitGroup h = new InstrumentedGroup("yahoo");
h.incoming().add(new Hit("yahoo1"));
JsonRenderer renderer = new JsonRenderer();
Result result = new Result(new Query(), h);
renderer.init();
ListenableFuture<Boolean> f = renderer.render(out, result, new Execution(Execution.Context.createContextStub()), result.getQuery());
WrappedFuture<DataList<Hit>> x = (WrappedFuture<DataList<Hit>>) h.incoming().completed();
x.isListening.get(86_400_000);
h.incoming().add(new Hit("yahoo2"));
h.incoming().markComplete();
Boolean b = f.get();
assertTrue(b);
String rawGot = Utf8.toString(out.toByteArray());
ObjectMapper m = new ObjectMapper();
Map<?, ?> expected = m.readValue(rawExpected, Map.class);
Map<?, ?> got = m.readValue(rawGot, Map.class);
assertEquals(expected, got);
}
Aggregations