use of org.elasticsearch.index.get.GetResult in project elasticsearch by elastic.
the class UpdateResponseTests method randomUpdateResponse.
/**
* Returns a tuple of {@link UpdateResponse}s.
* <p>
* The left element is the actual {@link UpdateResponse} to serialize while the right element is the
* expected {@link UpdateResponse} after parsing.
*/
public static Tuple<UpdateResponse, UpdateResponse> randomUpdateResponse(XContentType xContentType) {
Tuple<GetResult, GetResult> getResults = GetResultTests.randomGetResult(xContentType);
GetResult actualGetResult = getResults.v1();
GetResult expectedGetResult = getResults.v2();
String index = actualGetResult.getIndex();
String type = actualGetResult.getType();
String id = actualGetResult.getId();
long version = actualGetResult.getVersion();
DocWriteResponse.Result result = actualGetResult.isExists() ? DocWriteResponse.Result.UPDATED : DocWriteResponse.Result.NOT_FOUND;
String indexUUid = randomAsciiOfLength(5);
int shardId = randomIntBetween(0, 5);
// We also want small number values (randomNonNegativeLong() tend to generate high numbers)
// in order to catch some conversion error that happen between int/long after parsing.
Long seqNo = randomFrom(randomNonNegativeLong(), (long) randomIntBetween(0, 10_000), null);
ShardId actualShardId = new ShardId(index, indexUUid, shardId);
ShardId expectedShardId = new ShardId(index, INDEX_UUID_NA_VALUE, -1);
UpdateResponse actual, expected;
if (seqNo != null) {
Tuple<ReplicationResponse.ShardInfo, ReplicationResponse.ShardInfo> shardInfos = RandomObjects.randomShardInfo(random());
actual = new UpdateResponse(shardInfos.v1(), actualShardId, type, id, seqNo, version, result);
expected = new UpdateResponse(shardInfos.v2(), expectedShardId, type, id, seqNo, version, result);
} else {
actual = new UpdateResponse(actualShardId, type, id, version, result);
expected = new UpdateResponse(expectedShardId, type, id, version, result);
}
if (actualGetResult.isExists()) {
actual.setGetResult(actualGetResult);
}
if (expectedGetResult.isExists()) {
expected.setGetResult(expectedGetResult);
}
boolean forcedRefresh = randomBoolean();
actual.setForcedRefresh(forcedRefresh);
expected.setForcedRefresh(forcedRefresh);
return Tuple.tuple(actual, expected);
}
Aggregations