use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testParseRequestFailure.
public void testParseRequestFailure() throws Exception {
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> {
assertFalse(r.isTimedOut());
assertNull(r.getScrollId());
assertEquals(0, r.getTotalHits());
assertThat(r.getFailures(), hasSize(1));
assertThat(r.getFailures().get(0).getReason(), instanceOf(ParsingException.class));
ParsingException failure = (ParsingException) r.getFailures().get(0).getReason();
assertEquals("Unknown key for a VALUE_STRING in [invalid].", failure.getMessage());
assertEquals(2, failure.getLineNumber());
assertEquals(14, failure.getColumnNumber());
called.set(true);
};
sourceWithMockedRemoteCall("request_failure.json").doStart(checkResponse);
assertTrue(called.get());
called.set(false);
sourceWithMockedRemoteCall("request_failure.json").doStartNextScroll("scroll", timeValueMillis(0), checkResponse);
assertTrue(called.get());
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testTooLargeResponse.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTooLargeResponse() throws Exception {
ContentTooLongException tooLong = new ContentTooLongException("too long!");
CloseableHttpAsyncClient httpClient = mock(CloseableHttpAsyncClient.class);
when(httpClient.<HttpResponse>execute(any(HttpAsyncRequestProducer.class), any(HttpAsyncResponseConsumer.class), any(HttpClientContext.class), any(FutureCallback.class))).then(new Answer<Future<HttpResponse>>() {
@Override
public Future<HttpResponse> answer(InvocationOnMock invocationOnMock) throws Throwable {
HeapBufferedAsyncResponseConsumer consumer = (HeapBufferedAsyncResponseConsumer) invocationOnMock.getArguments()[1];
FutureCallback callback = (FutureCallback) invocationOnMock.getArguments()[3];
assertEquals(new ByteSizeValue(100, ByteSizeUnit.MB).bytesAsInt(), consumer.getBufferLimit());
callback.failed(tooLong);
return null;
}
});
RemoteScrollableHitSource source = sourceWithMockedClient(true, httpClient);
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> called.set(true);
Throwable e = expectThrows(RuntimeException.class, () -> source.doStartNextScroll(FAKE_SCROLL_ID, timeValueMillis(0), checkResponse));
// Unwrap the some artifacts from the test
while (e.getMessage().equals("failed")) {
e = e.getCause();
}
// This next exception is what the user sees
assertEquals("Remote responded with a chunk that was too large. Use a smaller batch size.", e.getMessage());
// And that exception is reported as being caused by the underlying exception returned by the client
assertSame(tooLong, e.getCause());
assertFalse(called.get());
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testRetryAndSucceed.
public void testRetryAndSucceed() throws Exception {
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> {
assertThat(r.getFailures(), hasSize(0));
called.set(true);
};
retriesAllowed = between(1, Integer.MAX_VALUE);
sourceWithMockedRemoteCall("fail:rejection.json", "start_ok.json").doStart(checkResponse);
assertTrue(called.get());
assertEquals(1, retries);
retries = 0;
called.set(false);
sourceWithMockedRemoteCall("fail:rejection.json", "scroll_ok.json").doStartNextScroll("scroll", timeValueMillis(0), checkResponse);
assertTrue(called.get());
assertEquals(1, retries);
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testParseFailureWithStatus.
public void testParseFailureWithStatus() 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(10000, r.getTotalHits());
assertThat(r.getFailures(), hasSize(1));
assertEquals(null, r.getFailures().get(0).getIndex());
assertEquals(null, r.getFailures().get(0).getShardId());
assertEquals(null, r.getFailures().get(0).getNodeId());
assertThat(r.getFailures().get(0).getReason(), instanceOf(RuntimeException.class));
assertEquals("Unknown remote exception with reason=[SearchContextMissingException[No search context found for id [82]]]", 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("10000", r.getHits().get(0).getId());
assertEquals("{\"test\":\"test10000\"}", r.getHits().get(0).getSource().utf8ToString());
called.set(true);
};
sourceWithMockedRemoteCall("failure_with_status.json").doStart(checkResponse);
assertTrue(called.get());
called.set(false);
sourceWithMockedRemoteCall("failure_with_status.json").doStartNextScroll("scroll", timeValueMillis(0), checkResponse);
assertTrue(called.get());
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.Response in project elasticsearch by elastic.
the class RemoteScrollableHitSourceTests method testRetryUntilYouRunOutOfTries.
public void testRetryUntilYouRunOutOfTries() throws Exception {
AtomicBoolean called = new AtomicBoolean();
Consumer<Response> checkResponse = r -> called.set(true);
retriesAllowed = between(0, 10);
String[] paths = new String[retriesAllowed + 2];
for (int i = 0; i < retriesAllowed + 2; i++) {
paths[i] = "fail:rejection.json";
}
RuntimeException e = expectThrows(RuntimeException.class, () -> sourceWithMockedRemoteCall(paths).doStart(checkResponse));
assertEquals("failed", e.getMessage());
assertFalse(called.get());
assertEquals(retriesAllowed, retries);
retries = 0;
e = expectThrows(RuntimeException.class, () -> sourceWithMockedRemoteCall(paths).doStartNextScroll("scroll", timeValueMillis(0), checkResponse));
assertEquals("failed", e.getMessage());
assertFalse(called.get());
assertEquals(retriesAllowed, retries);
}
Aggregations