Search in sources :

Example 16 with FakeRestRequest

use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.

the class BytesRestResponseTests method testSimpleExceptionMessage.

public void testSimpleExceptionMessage() throws Exception {
    RestRequest request = new FakeRestRequest();
    RestChannel channel = new SimpleExceptionRestChannel(request);
    Exception t = new ElasticsearchException("an error occurred reading data", new FileNotFoundException("/foo/bar"));
    BytesRestResponse response = new BytesRestResponse(channel, t);
    String text = response.content().utf8ToString();
    assertThat(text, containsString("ElasticsearchException[an error occurred reading data]"));
    assertThat(text, not(containsString("FileNotFoundException")));
    assertThat(text, not(containsString("/foo/bar")));
    assertThat(text, not(containsString("error_trace")));
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FileNotFoundException(java.io.FileNotFoundException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Example 17 with FakeRestRequest

use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.

the class BytesRestResponseTests method testWithHeaders.

public void testWithHeaders() throws Exception {
    RestRequest request = new FakeRestRequest();
    RestChannel channel = randomBoolean() ? new DetailedExceptionRestChannel(request) : new SimpleExceptionRestChannel(request);
    BytesRestResponse response = new BytesRestResponse(channel, new WithHeadersException());
    assertEquals(2, response.getHeaders().size());
    assertThat(response.getHeaders().get("n1"), notNullValue());
    assertThat(response.getHeaders().get("n1"), contains("v11", "v12"));
    assertThat(response.getHeaders().get("n2"), notNullValue());
    assertThat(response.getHeaders().get("n2"), contains("v21", "v22"));
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest)

Example 18 with FakeRestRequest

use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.

the class BytesRestResponseTests method testDetailedExceptionMessage.

public void testDetailedExceptionMessage() throws Exception {
    RestRequest request = new FakeRestRequest();
    RestChannel channel = new DetailedExceptionRestChannel(request);
    Exception t = new ElasticsearchException("an error occurred reading data", new FileNotFoundException("/foo/bar"));
    BytesRestResponse response = new BytesRestResponse(channel, t);
    String text = response.content().utf8ToString();
    assertThat(text, containsString("{\"type\":\"exception\",\"reason\":\"an error occurred reading data\"}"));
    assertThat(text, containsString("{\"type\":\"file_not_found_exception\",\"reason\":\"/foo/bar\"}"));
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FileNotFoundException(java.io.FileNotFoundException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Example 19 with FakeRestRequest

use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.

the class BytesRestResponseTests method testConvert.

public void testConvert() throws IOException {
    RestRequest request = new FakeRestRequest();
    RestChannel channel = new DetailedExceptionRestChannel(request);
    ShardSearchFailure failure = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 1));
    ShardSearchFailure failure1 = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 2));
    SearchPhaseExecutionException ex = new SearchPhaseExecutionException("search", "all shards failed", new ShardSearchFailure[] { failure, failure1 });
    BytesRestResponse response = new BytesRestResponse(channel, new RemoteTransportException("foo", ex));
    String text = response.content().utf8ToString();
    String expected = "{\"error\":{\"root_cause\":[{\"type\":\"parsing_exception\",\"reason\":\"foobar\",\"line\":1,\"col\":2}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"search\",\"grouped\":true,\"failed_shards\":[{\"shard\":1,\"index\":\"foo\",\"node\":\"node_1\",\"reason\":{\"type\":\"parsing_exception\",\"reason\":\"foobar\",\"line\":1,\"col\":2}}]},\"status\":400}";
    assertEquals(expected.trim(), text.trim());
    String stackTrace = ExceptionsHelper.stackTrace(ex);
    assertTrue(stackTrace.contains("Caused by: ParsingException[foobar]"));
}
Also used : RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ParsingException(org.elasticsearch.common.ParsingException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) Index(org.elasticsearch.index.Index) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest)

Example 20 with FakeRestRequest

use of org.elasticsearch.test.rest.FakeRestRequest in project elasticsearch by elastic.

the class BytesRestResponseTests method testErrorTrace.

public void testErrorTrace() throws Exception {
    RestRequest request = new FakeRestRequest();
    request.params().put("error_trace", "true");
    RestChannel channel = new DetailedExceptionRestChannel(request);
    Exception t = new UnknownException("an error occurred reading data", new FileNotFoundException("/foo/bar"));
    BytesRestResponse response = new BytesRestResponse(channel, t);
    String text = response.content().utf8ToString();
    assertThat(text, containsString("\"type\":\"unknown_exception\",\"reason\":\"an error occurred reading data\""));
    assertThat(text, containsString("{\"type\":\"file_not_found_exception\""));
    assertThat(text, containsString("\"stack_trace\":\"[an error occurred reading data]"));
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) FileNotFoundException(java.io.FileNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException)

Aggregations

FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)30 IOException (java.io.IOException)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 ThreadContext (org.elasticsearch.common.util.concurrent.ThreadContext)10 NodeClient (org.elasticsearch.client.node.NodeClient)7 BytesArray (org.elasticsearch.common.bytes.BytesArray)7 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)6 ParsingException (org.elasticsearch.common.ParsingException)6 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 RemoteTransportException (org.elasticsearch.transport.RemoteTransportException)6 FileNotFoundException (java.io.FileNotFoundException)5 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)5 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)5 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)5 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)4 RestRequest (org.elasticsearch.rest.RestRequest)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Settings (org.elasticsearch.common.settings.Settings)3 Table (org.elasticsearch.common.Table)2