forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into compile-with-jdk-9
* master: Revert "[Docs] Fix Java Api index administration usage (elastic#28133)" Revert "[Docs] Fix base directory to include for put_mapping.asciidoc" Added multi get api to the high level rest client. [Docs] Clarify numeric datatype ranges (elastic#28240)
- Loading branch information
Showing
13 changed files
with
518 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
core/src/test/java/org/elasticsearch/action/get/MultiGetResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.action.get; | ||
|
||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.index.get.GetResult; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.test.XContentTestUtils.insertRandomFields; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class MultiGetResponseTests extends ESTestCase { | ||
|
||
public void testFromXContent() throws IOException { | ||
for (int runs = 0; runs < 20; runs++) { | ||
MultiGetResponse expected = createTestInstance(); | ||
XContentType xContentType = randomFrom(XContentType.values()); | ||
BytesReference shuffled = toShuffledXContent(expected, xContentType, ToXContent.EMPTY_PARAMS, false); | ||
|
||
XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled); | ||
MultiGetResponse parsed = MultiGetResponse.fromXContent(parser); | ||
assertNull(parser.nextToken()); | ||
assertNotSame(expected, parsed); | ||
|
||
assertThat(parsed.getResponses().length, equalTo(expected.getResponses().length)); | ||
for (int i = 0; i < expected.getResponses().length; i++) { | ||
MultiGetItemResponse expectedItem = expected.getResponses()[i]; | ||
MultiGetItemResponse actualItem = parsed.getResponses()[i]; | ||
assertThat(actualItem.getIndex(), equalTo(expectedItem.getIndex())); | ||
assertThat(actualItem.getType(), equalTo(expectedItem.getType())); | ||
assertThat(actualItem.getId(), equalTo(expectedItem.getId())); | ||
if (expectedItem.isFailed()) { | ||
assertThat(actualItem.isFailed(), is(true)); | ||
assertThat(actualItem.getFailure().getMessage(), containsString(expectedItem.getFailure().getMessage())); | ||
} else { | ||
assertThat(actualItem.isFailed(), is(false)); | ||
assertThat(actualItem.getResponse(), equalTo(expectedItem.getResponse())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static MultiGetResponse createTestInstance() { | ||
MultiGetItemResponse[] items = new MultiGetItemResponse[randomIntBetween(0, 128)]; | ||
for (int i = 0; i < items.length; i++) { | ||
if (randomBoolean()) { | ||
items[i] = new MultiGetItemResponse(new GetResponse(new GetResult( | ||
randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4), randomNonNegativeLong(), | ||
true, null, null | ||
)), null); | ||
} else { | ||
items[i] = new MultiGetItemResponse(null, new MultiGetResponse.Failure(randomAlphaOfLength(4), | ||
randomAlphaOfLength(4), randomAlphaOfLength(4), new RuntimeException(randomAlphaOfLength(4)))); | ||
} | ||
} | ||
return new MultiGetResponse(items); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.