Search in sources :

Example 6 with Response

use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.

the class RemoteScrollableHitSourceTests method testParseRejection.

public void testParseRejection() throws Exception {
    // The rejection comes through in the handler because the mocked http response isn't marked as an error
    AtomicBoolean called = new AtomicBoolean();
    // Handling a scroll rejection is the same as handling a search rejection so we reuse the verification code
    Consumer<Response> checkResponse = r -> {
        assertFalse(r.isTimedOut());
        assertEquals(FAKE_SCROLL_ID, r.getScrollId());
        assertEquals(4, r.getTotalHits());
        assertThat(r.getFailures(), hasSize(1));
        assertEquals("test", r.getFailures().get(0).getIndex());
        assertEquals((Integer) 0, r.getFailures().get(0).getShardId());
        assertEquals("87A7NvevQxSrEwMbtRCecg", r.getFailures().get(0).getNodeId());
        assertThat(r.getFailures().get(0).getReason(), instanceOf(EsRejectedExecutionException.class));
        assertEquals("rejected execution of org.elasticsearch.transport.TransportService$5@52d06af2 on " + "EsThreadPoolExecutor[search, queue capacity = 1000, org.elasticsearch.common.util.concurrent." + "EsThreadPoolExecutor@778ea553[Running, pool size = 7, active threads = 7, queued tasks = 1000, " + "completed tasks = 4182]]", r.getFailures().get(0).getReason().getMessage());
        assertThat(r.getHits(), hasSize(1));
        assertEquals("test", r.getHits().get(0).getIndex());
        assertEquals("test", r.getHits().get(0).getType());
        assertEquals("AVToMiC250DjIiBO3yJ_", r.getHits().get(0).getId());
        assertEquals("{\"test\":\"test1\"}", r.getHits().get(0).getSource().utf8ToString());
        called.set(true);
    };
    sourceWithMockedRemoteCall("rejection.json").doStart(checkResponse);
    assertTrue(called.get());
    called.set(false);
    sourceWithMockedRemoteCall("rejection.json").doStartNextScroll("scroll", timeValueMillis(0), checkResponse);
    assertTrue(called.get());
}
Also used : Response(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) ScheduledFuture(java.util.concurrent.ScheduledFuture) URL(java.net.URL) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) StatusLine(org.apache.http.StatusLine) HeapBufferedAsyncResponseConsumer(org.elasticsearch.client.HeapBufferedAsyncResponseConsumer) Future(java.util.concurrent.Future) After(org.junit.After) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Streams(org.elasticsearch.common.io.Streams) ThreadPool(org.elasticsearch.threadpool.ThreadPool) HttpAsyncRequestProducer(org.apache.http.nio.protocol.HttpAsyncRequestProducer) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient) StandardCharsets(java.nio.charset.StandardCharsets) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) HttpAsyncClientBuilder(org.apache.http.impl.nio.client.HttpAsyncClientBuilder) Version(org.elasticsearch.Version) RestStatus(org.elasticsearch.rest.RestStatus) TimeValue.timeValueMinutes(org.elasticsearch.common.unit.TimeValue.timeValueMinutes) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) RestClient(org.elasticsearch.client.RestClient) ContentTooLongException(org.apache.http.ContentTooLongException) ParsingException(org.elasticsearch.common.ParsingException) BasicStatusLine(org.apache.http.message.BasicStatusLine) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SearchRequest(org.elasticsearch.action.search.SearchRequest) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) BytesArray(org.elasticsearch.common.bytes.BytesArray) HttpAsyncResponseConsumer(org.apache.http.nio.protocol.HttpAsyncResponseConsumer) Answer(org.mockito.stubbing.Answer) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) TimeValue.timeValueMillis(org.elasticsearch.common.unit.TimeValue.timeValueMillis) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Matchers.empty(org.hamcrest.Matchers.empty) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) FutureCallback(org.apache.http.concurrent.FutureCallback) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) InputStreamReader(java.io.InputStreamReader) Consumer(java.util.function.Consumer) ProtocolVersion(org.apache.http.ProtocolVersion) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) HttpResponse(org.apache.http.HttpResponse) InputStreamEntity(org.apache.http.entity.InputStreamEntity) HttpHost(org.apache.http.HttpHost) Response(org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 URL (java.net.URL)6 StandardCharsets (java.nio.charset.StandardCharsets)6 ExecutorService (java.util.concurrent.ExecutorService)6 Future (java.util.concurrent.Future)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Consumer (java.util.function.Consumer)6 ContentTooLongException (org.apache.http.ContentTooLongException)6 HttpEntity (org.apache.http.HttpEntity)6 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)6 HttpHost (org.apache.http.HttpHost)6 HttpResponse (org.apache.http.HttpResponse)6 ProtocolVersion (org.apache.http.ProtocolVersion)6 StatusLine (org.apache.http.StatusLine)6 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)6 FutureCallback (org.apache.http.concurrent.FutureCallback)6 ContentType (org.apache.http.entity.ContentType)6 InputStreamEntity (org.apache.http.entity.InputStreamEntity)6