Search in sources :

Example 16 with GetResult

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);
}
Also used : GetResult(org.elasticsearch.index.get.GetResult) DocWriteResponse(org.elasticsearch.action.DocWriteResponse) ShardId(org.elasticsearch.index.shard.ShardId)

Aggregations

GetResult (org.elasticsearch.index.get.GetResult)16 IOException (java.io.IOException)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)5 BytesArray (org.elasticsearch.common.bytes.BytesArray)4 HashMap (java.util.HashMap)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 IndexRequest (org.elasticsearch.action.index.IndexRequest)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 XContentType (org.elasticsearch.common.xcontent.XContentType)3 Map (java.util.Map)2 Explanation (org.apache.lucene.search.Explanation)2 Settings (org.elasticsearch.common.settings.Settings)2 IndexService (org.elasticsearch.index.IndexService)2 GetField (org.elasticsearch.index.get.GetField)2 GetResultTests.copyGetResult (org.elasticsearch.index.get.GetResultTests.copyGetResult)2 GetResultTests.mutateGetResult (org.elasticsearch.index.get.GetResultTests.mutateGetResult)2 GetResultTests.randomGetResult (org.elasticsearch.index.get.GetResultTests.randomGetResult)2 IndexShard (org.elasticsearch.index.shard.IndexShard)2 ShardId (org.elasticsearch.index.shard.ShardId)2