Search in sources :

Example 21 with ErrorMessage

use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.

the class DefaultErrorHitTestCase method testErrorHitRenderingWithException.

@SuppressWarnings("null")
public void testErrorHitRenderingWithException() throws IOException {
    NullPointerException cause = null;
    try {
        Object a = null;
        a.toString();
    } catch (NullPointerException e) {
        cause = e;
    }
    StringWriter w = new StringWriter();
    SearchRendererAdaptor.simpleRenderDefaultErrorHit(w, new DefaultErrorHit("test", new ErrorMessage(79, "Myerror", "Mydetail", cause)));
    String sep = System.getProperty("line.separator");
    assertEquals("<errordetails>\n" + "  <error source=\"test\" error=\"Myerror\" code=\"79\">Mydetail\n" + "    <cause>\n" + "java.lang.NullPointerException" + sep + "\tat ", w.toString().substring(0, 119 + sep.length()));
}
Also used : StringWriter(java.io.StringWriter) ErrorMessage(com.yahoo.search.result.ErrorMessage) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit)

Example 22 with ErrorMessage

use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.

the class JsonRendererTestCase method testErrorWithStackTrace.

@Test
public void testErrorWithStackTrace() throws InterruptedException, ExecutionException, IOException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"errors\": [\n" + "            {\n" + "                \"code\": 1234,\n" + "                \"message\": \"top of the day\",\n" + "                \"stackTrace\": \"java.lang.Throwable\\n\\tat com.yahoo.search.rendering.JsonRendererTestCase.testErrorWithStackTrace(JsonRendererTestCase.java:732)\\n\",\n" + "                \"summary\": \"hello\"\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    Result r = new Result(q);
    Throwable t = new Throwable();
    StackTraceElement[] stack = new StackTraceElement[1];
    stack[0] = new StackTraceElement("com.yahoo.search.rendering.JsonRendererTestCase", "testErrorWithStackTrace", "JsonRendererTestCase.java", 732);
    t.setStackTrace(stack);
    ErrorMessage e = new ErrorMessage(1234, "hello", "top of the day", t);
    r.hits().addError(e);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : Query(com.yahoo.search.Query) JSONString(com.yahoo.prelude.hitfield.JSONString) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 23 with ErrorMessage

use of com.yahoo.search.result.ErrorMessage in project vespa by vespa-engine.

the class PartialFillTestCase method testMergeErrors.

@Test
public void testMergeErrors() {
    BadFS4 fs4 = new BadFS4();
    Query a = new Query("/?query=foo");
    Query b = new Query("/?query=bar");
    Result r = new Result(new Query("/?query=ignorethis"));
    {
        FastHit h = new FastHit();
        h.setQuery(a);
        h.setFillable();
        r.hits().add(h);
    }
    {
        FastHit h = new FastHit();
        h.setQuery(b);
        h.setFillable();
        r.hits().add(h);
    }
    doFill(fs4, r, "default");
    ErrorHit eh = r.hits().getErrorHit();
    assertNotNull(eh);
    ErrorMessage exp_sub = ErrorMessage.createUnspecifiedError("error");
    int n = 0;
    for (Iterator<? extends com.yahoo.search.result.ErrorMessage> i = eh.errorIterator(); i.hasNext(); ) {
        com.yahoo.search.result.ErrorMessage error = i.next();
        switch(n) {
            case 0:
                assertEquals(exp_sub, error);
                break;
            case 1:
                assertEquals(exp_sub, error);
                break;
            default:
                assertTrue(false);
        }
        n++;
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) ErrorHit(com.yahoo.search.result.ErrorHit) ErrorMessage(com.yahoo.search.result.ErrorMessage) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

ErrorMessage (com.yahoo.search.result.ErrorMessage)23 Result (com.yahoo.search.Result)16 Query (com.yahoo.search.Query)10 Test (org.junit.Test)9 ErrorHit (com.yahoo.search.result.ErrorHit)4 IndexFacts (com.yahoo.prelude.IndexFacts)3 Execution (com.yahoo.search.searchchain.Execution)3 MockBackend (com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend)2 Hit (com.yahoo.search.result.Hit)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Metric (com.yahoo.jdisc.Metric)1 URI (com.yahoo.net.URI)1 DocumentdbInfoConfig (com.yahoo.prelude.fastsearch.DocumentdbInfoConfig)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)1 JSONString (com.yahoo.prelude.hitfield.JSONString)1 XMLString (com.yahoo.prelude.hitfield.XMLString)1 FederationTarget (com.yahoo.search.federation.selection.FederationTarget)1