use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.
the class BulkByScrollResponse method toXContent.
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("took", took.millis());
builder.field("timed_out", timedOut);
status.innerXContent(builder, params);
builder.startArray("failures");
for (Failure failure : bulkFailures) {
builder.startObject();
failure.toXContent(builder, params);
builder.endObject();
}
for (SearchFailure failure : searchFailures) {
failure.toXContent(builder, params);
}
builder.endArray();
return builder;
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.
the class BulkByScrollResponseTests method assertResponseEquals.
private void assertResponseEquals(BulkByScrollResponse expected, BulkByScrollResponse actual) {
assertEquals(expected.getTook(), actual.getTook());
BulkByScrollTaskStatusTests.assertTaskStatusEquals(Version.CURRENT, expected.getStatus(), actual.getStatus());
assertEquals(expected.getBulkFailures().size(), actual.getBulkFailures().size());
for (int i = 0; i < expected.getBulkFailures().size(); i++) {
Failure expectedFailure = expected.getBulkFailures().get(i);
Failure actualFailure = actual.getBulkFailures().get(i);
assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
assertEquals(expectedFailure.getType(), actualFailure.getType());
assertEquals(expectedFailure.getId(), actualFailure.getId());
assertEquals(expectedFailure.getMessage(), actualFailure.getMessage());
assertEquals(expectedFailure.getStatus(), actualFailure.getStatus());
}
assertEquals(expected.getSearchFailures().size(), actual.getSearchFailures().size());
for (int i = 0; i < expected.getSearchFailures().size(); i++) {
SearchFailure expectedFailure = expected.getSearchFailures().get(i);
SearchFailure actualFailure = actual.getSearchFailures().get(i);
assertEquals(expectedFailure.getIndex(), actualFailure.getIndex());
assertEquals(expectedFailure.getShardId(), actualFailure.getShardId());
assertEquals(expectedFailure.getNodeId(), actualFailure.getNodeId());
assertEquals(expectedFailure.getReason().getClass(), actualFailure.getReason().getClass());
assertEquals(expectedFailure.getReason().getMessage(), actualFailure.getReason().getMessage());
}
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.
the class AsyncBulkByScrollActionTests method testShardFailuresAbortRequest.
/**
* Mimicks shard search failures usually caused by the data node serving the
* scroll request going down.
*/
public void testShardFailuresAbortRequest() throws Exception {
SearchFailure shardFailure = new SearchFailure(new RuntimeException("test"));
ScrollableHitSource.Response scrollResponse = new ScrollableHitSource.Response(false, singletonList(shardFailure), 0, emptyList(), null);
simulateScrollResponse(new DummyAsyncBulkByScrollAction(), timeValueNanos(System.nanoTime()), 0, scrollResponse);
BulkByScrollResponse response = listener.get();
assertThat(response.getBulkFailures(), empty());
assertThat(response.getSearchFailures(), contains(shardFailure));
assertFalse(response.isTimedOut());
assertNull(response.getReasonCancelled());
assertThat(client.scrollsCleared, contains(scrollId));
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.
the class BulkByScrollResponseTests method randomSearchFailures.
private List<SearchFailure> randomSearchFailures() {
if (randomBoolean()) {
return emptyList();
}
String index = null;
Integer shardId = null;
String nodeId = null;
if (randomBoolean()) {
index = randomAsciiOfLength(5);
shardId = randomInt();
nodeId = usually() ? randomAsciiOfLength(5) : null;
}
return singletonList(new SearchFailure(new ElasticsearchException("foo"), index, shardId, nodeId));
}
use of org.elasticsearch.action.bulk.byscroll.ScrollableHitSource.SearchFailure in project elasticsearch by elastic.
the class BulkIndexByScrollResponseTests method testMergeConstructor.
public void testMergeConstructor() {
int mergeCount = between(2, 10);
List<BulkByScrollResponse> responses = new ArrayList<>(mergeCount);
int took = between(1000, 10000);
int tookIndex = between(0, mergeCount - 1);
List<BulkItemResponse.Failure> allBulkFailures = new ArrayList<>();
List<SearchFailure> allSearchFailures = new ArrayList<>();
boolean timedOut = false;
String reasonCancelled = rarely() ? randomAsciiOfLength(5) : null;
for (int i = 0; i < mergeCount; i++) {
// One of the merged responses gets the expected value for took, the others get a smaller value
TimeValue thisTook = timeValueMillis(i == tookIndex ? took : between(0, took));
// The actual status doesn't matter too much - we test merging those elsewhere
String thisReasonCancelled = rarely() ? randomAsciiOfLength(5) : null;
BulkByScrollTask.Status status = new BulkByScrollTask.Status(i, 0, 0, 0, 0, 0, 0, 0, 0, 0, timeValueMillis(0), 0f, thisReasonCancelled, timeValueMillis(0));
List<BulkItemResponse.Failure> bulkFailures = frequently() ? emptyList() : IntStream.range(0, between(1, 3)).mapToObj(j -> new BulkItemResponse.Failure("idx", "type", "id", new Exception())).collect(Collectors.toList());
allBulkFailures.addAll(bulkFailures);
List<SearchFailure> searchFailures = frequently() ? emptyList() : IntStream.range(0, between(1, 3)).mapToObj(j -> new SearchFailure(new Exception())).collect(Collectors.toList());
allSearchFailures.addAll(searchFailures);
boolean thisTimedOut = rarely();
timedOut |= thisTimedOut;
responses.add(new BulkByScrollResponse(thisTook, status, bulkFailures, searchFailures, thisTimedOut));
}
BulkByScrollResponse merged = new BulkByScrollResponse(responses, reasonCancelled);
assertEquals(timeValueMillis(took), merged.getTook());
assertEquals(allBulkFailures, merged.getBulkFailures());
assertEquals(allSearchFailures, merged.getSearchFailures());
assertEquals(timedOut, merged.isTimedOut());
assertEquals(reasonCancelled, merged.getReasonCancelled());
}
Aggregations