|
@@ -29,6 +29,7 @@ import org.apache.http.entity.ByteArrayEntity;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.DocWriteRequest;
|
|
|
+import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
|
|
@@ -111,6 +112,7 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
|
|
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
|
|
|
import org.elasticsearch.search.suggest.SuggestBuilder;
|
|
|
import org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder;
|
|
|
+import org.elasticsearch.tasks.TaskId;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.test.RandomObjects;
|
|
|
|
|
@@ -142,6 +144,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXC
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.hasEntry;
|
|
|
import static org.hamcrest.Matchers.hasKey;
|
|
|
+import static org.hamcrest.Matchers.notNullValue;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
|
|
|
public class RequestConvertersTests extends ESTestCase {
|
|
@@ -188,8 +191,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
|
|
|
int numberOfRequests = randomIntBetween(0, 32);
|
|
|
for (int i = 0; i < numberOfRequests; i++) {
|
|
|
- MultiGetRequest.Item item =
|
|
|
- new MultiGetRequest.Item(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4));
|
|
|
+ MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4));
|
|
|
if (randomBoolean()) {
|
|
|
item.routing(randomAlphaOfLength(4));
|
|
|
}
|
|
@@ -268,7 +270,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
|
|
|
public void testIndicesExistEmptyIndices() {
|
|
|
expectThrows(IllegalArgumentException.class, () -> RequestConverters.indicesExist(new GetIndexRequest()));
|
|
|
- expectThrows(IllegalArgumentException.class, () -> RequestConverters.indicesExist(new GetIndexRequest().indices((String[])null)));
|
|
|
+ expectThrows(IllegalArgumentException.class, () -> RequestConverters.indicesExist(new GetIndexRequest().indices((String[]) null)));
|
|
|
}
|
|
|
|
|
|
private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) {
|
|
@@ -422,7 +424,8 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
setRandomLocal(getSettingsRequest, expectedParams);
|
|
|
|
|
|
if (randomBoolean()) {
|
|
|
- //the request object will not have include_defaults present unless it is set to true
|
|
|
+ // the request object will not have include_defaults present unless it is set to
|
|
|
+ // true
|
|
|
getSettingsRequest.includeDefaults(randomBoolean());
|
|
|
if (getSettingsRequest.includeDefaults()) {
|
|
|
expectedParams.put("include_defaults", Boolean.toString(true));
|
|
@@ -966,22 +969,21 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
bulkRequest.add(new IndexRequest("index", "type", "0").source(singletonMap("field", "value"), XContentType.SMILE));
|
|
|
bulkRequest.add(new IndexRequest("index", "type", "1").source(singletonMap("field", "value"), XContentType.JSON));
|
|
|
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> RequestConverters.bulk(bulkRequest));
|
|
|
- assertEquals("Mismatching content-type found for request with content-type [JSON], " +
|
|
|
- "previous requests have content-type [SMILE]", exception.getMessage());
|
|
|
+ assertEquals(
|
|
|
+ "Mismatching content-type found for request with content-type [JSON], " + "previous requests have content-type [SMILE]",
|
|
|
+ exception.getMessage());
|
|
|
}
|
|
|
{
|
|
|
BulkRequest bulkRequest = new BulkRequest();
|
|
|
- bulkRequest.add(new IndexRequest("index", "type", "0")
|
|
|
- .source(singletonMap("field", "value"), XContentType.JSON));
|
|
|
- bulkRequest.add(new IndexRequest("index", "type", "1")
|
|
|
- .source(singletonMap("field", "value"), XContentType.JSON));
|
|
|
+ bulkRequest.add(new IndexRequest("index", "type", "0").source(singletonMap("field", "value"), XContentType.JSON));
|
|
|
+ bulkRequest.add(new IndexRequest("index", "type", "1").source(singletonMap("field", "value"), XContentType.JSON));
|
|
|
bulkRequest.add(new UpdateRequest("index", "type", "2")
|
|
|
.doc(new IndexRequest().source(singletonMap("field", "value"), XContentType.JSON))
|
|
|
- .upsert(new IndexRequest().source(singletonMap("field", "value"), XContentType.SMILE))
|
|
|
- );
|
|
|
+ .upsert(new IndexRequest().source(singletonMap("field", "value"), XContentType.SMILE)));
|
|
|
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> RequestConverters.bulk(bulkRequest));
|
|
|
- assertEquals("Mismatching content-type found for request with content-type [SMILE], " +
|
|
|
- "previous requests have content-type [JSON]", exception.getMessage());
|
|
|
+ assertEquals(
|
|
|
+ "Mismatching content-type found for request with content-type [SMILE], " + "previous requests have content-type [JSON]",
|
|
|
+ exception.getMessage());
|
|
|
}
|
|
|
{
|
|
|
XContentType xContentType = randomFrom(XContentType.CBOR, XContentType.YAML);
|
|
@@ -1022,9 +1024,10 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams);
|
|
|
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
- //rarely skip setting the search source completely
|
|
|
+ // rarely skip setting the search source completely
|
|
|
if (frequently()) {
|
|
|
- //frequently set the search source to have some content, otherwise leave it empty but still set it
|
|
|
+ // frequently set the search source to have some content, otherwise leave it
|
|
|
+ // empty but still set it
|
|
|
if (frequently()) {
|
|
|
if (randomBoolean()) {
|
|
|
searchSourceBuilder.size(randomIntBetween(0, Integer.MAX_VALUE));
|
|
@@ -1094,7 +1097,8 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
|
|
|
for (int i = 0; i < numberOfSearchRequests; i++) {
|
|
|
SearchRequest searchRequest = randomSearchRequest(() -> {
|
|
|
- // No need to return a very complex SearchSourceBuilder here, that is tested elsewhere
|
|
|
+ // No need to return a very complex SearchSourceBuilder here, that is tested
|
|
|
+ // elsewhere
|
|
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
|
|
searchSourceBuilder.from(randomInt(10));
|
|
|
searchSourceBuilder.size(randomIntBetween(20, 100));
|
|
@@ -1102,14 +1106,13 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
});
|
|
|
// scroll is not supported in the current msearch api, so unset it:
|
|
|
searchRequest.scroll((Scroll) null);
|
|
|
- // only expand_wildcards, ignore_unavailable and allow_no_indices can be specified from msearch api, so unset other options:
|
|
|
+ // only expand_wildcards, ignore_unavailable and allow_no_indices can be
|
|
|
+ // specified from msearch api, so unset other options:
|
|
|
IndicesOptions randomlyGenerated = searchRequest.indicesOptions();
|
|
|
IndicesOptions msearchDefault = new MultiSearchRequest().indicesOptions();
|
|
|
- searchRequest.indicesOptions(IndicesOptions.fromOptions(
|
|
|
- randomlyGenerated.ignoreUnavailable(), randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(),
|
|
|
- randomlyGenerated.expandWildcardsClosed(), msearchDefault.allowAliasesToMultipleIndices(),
|
|
|
- msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases()
|
|
|
- ));
|
|
|
+ searchRequest.indicesOptions(IndicesOptions.fromOptions(randomlyGenerated.ignoreUnavailable(),
|
|
|
+ randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(), randomlyGenerated.expandWildcardsClosed(),
|
|
|
+ msearchDefault.allowAliasesToMultipleIndices(), msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases()));
|
|
|
multiSearchRequest.add(searchRequest);
|
|
|
}
|
|
|
|
|
@@ -1134,8 +1137,8 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
requests.add(searchRequest);
|
|
|
};
|
|
|
MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())),
|
|
|
- REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null,
|
|
|
- null, xContentRegistry(), true);
|
|
|
+ REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null,
|
|
|
+ xContentRegistry(), true);
|
|
|
assertEquals(requests, multiSearchRequest.requests());
|
|
|
}
|
|
|
|
|
@@ -1230,7 +1233,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
|
|
|
String[] indices = randomBoolean() ? null : randomIndicesNames(0, 5);
|
|
|
getAliasesRequest.indices(indices);
|
|
|
- //the HEAD endpoint requires at least an alias or an index
|
|
|
+ // the HEAD endpoint requires at least an alias or an index
|
|
|
boolean hasIndices = indices != null && indices.length > 0;
|
|
|
String[] aliases;
|
|
|
if (hasIndices) {
|
|
@@ -1261,15 +1264,15 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
public void testExistsAliasNoAliasNoIndex() {
|
|
|
{
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
|
|
|
- IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
|
|
|
- RequestConverters.existsAlias(getAliasesRequest));
|
|
|
+ IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> RequestConverters.existsAlias(getAliasesRequest));
|
|
|
assertEquals("existsAlias requires at least an alias or an index", iae.getMessage());
|
|
|
}
|
|
|
{
|
|
|
- GetAliasesRequest getAliasesRequest = new GetAliasesRequest((String[])null);
|
|
|
- getAliasesRequest.indices((String[])null);
|
|
|
- IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () ->
|
|
|
- RequestConverters.existsAlias(getAliasesRequest));
|
|
|
+ GetAliasesRequest getAliasesRequest = new GetAliasesRequest((String[]) null);
|
|
|
+ getAliasesRequest.indices((String[]) null);
|
|
|
+ IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> RequestConverters.existsAlias(getAliasesRequest));
|
|
|
assertEquals("existsAlias requires at least an alias or an index", iae.getMessage());
|
|
|
}
|
|
|
}
|
|
@@ -1279,14 +1282,10 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
String[] indices = randomIndicesNames(0, 5);
|
|
|
String[] fields = generateRandomStringArray(5, 10, false, false);
|
|
|
|
|
|
- FieldCapabilitiesRequest fieldCapabilitiesRequest = new FieldCapabilitiesRequest()
|
|
|
- .indices(indices)
|
|
|
- .fields(fields);
|
|
|
+ FieldCapabilitiesRequest fieldCapabilitiesRequest = new FieldCapabilitiesRequest().indices(indices).fields(fields);
|
|
|
|
|
|
Map<String, String> indicesOptionsParams = new HashMap<>();
|
|
|
- setRandomIndicesOptions(fieldCapabilitiesRequest::indicesOptions,
|
|
|
- fieldCapabilitiesRequest::indicesOptions,
|
|
|
- indicesOptionsParams);
|
|
|
+ setRandomIndicesOptions(fieldCapabilitiesRequest::indicesOptions, fieldCapabilitiesRequest::indicesOptions, indicesOptionsParams);
|
|
|
|
|
|
Request request = RequestConverters.fieldCaps(fieldCapabilitiesRequest);
|
|
|
|
|
@@ -1301,12 +1300,13 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
assertEquals(endpoint.toString(), request.getEndpoint());
|
|
|
assertEquals(4, request.getParameters().size());
|
|
|
|
|
|
- // Note that we don't check the field param value explicitly, as field names are passed through
|
|
|
- // a hash set before being added to the request, and can appear in a non-deterministic order.
|
|
|
+ // Note that we don't check the field param value explicitly, as field names are
|
|
|
+ // passed through
|
|
|
+ // a hash set before being added to the request, and can appear in a
|
|
|
+ // non-deterministic order.
|
|
|
assertThat(request.getParameters(), hasKey("fields"));
|
|
|
String[] requestFields = Strings.splitStringByCommaToArray(request.getParameters().get("fields"));
|
|
|
- assertEquals(new HashSet<>(Arrays.asList(fields)),
|
|
|
- new HashSet<>(Arrays.asList(requestFields)));
|
|
|
+ assertEquals(new HashSet<>(Arrays.asList(fields)), new HashSet<>(Arrays.asList(requestFields)));
|
|
|
|
|
|
for (Map.Entry<String, String> param : indicesOptionsParams.entrySet()) {
|
|
|
assertThat(request.getParameters(), hasEntry(param.getKey(), param.getValue()));
|
|
@@ -1465,6 +1465,66 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
assertEquals(expectedParams, request.getParameters());
|
|
|
}
|
|
|
|
|
|
+ public void testListTasks() {
|
|
|
+ {
|
|
|
+ ListTasksRequest request = new ListTasksRequest();
|
|
|
+ Map<String, String> expectedParams = new HashMap<>();
|
|
|
+ if (randomBoolean()) {
|
|
|
+ request.setDetailed(randomBoolean());
|
|
|
+ if (request.getDetailed()) {
|
|
|
+ expectedParams.put("detailed", "true");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ request.setWaitForCompletion(randomBoolean());
|
|
|
+ if (request.getWaitForCompletion()) {
|
|
|
+ expectedParams.put("wait_for_completion", "true");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ String timeout = randomTimeValue();
|
|
|
+ request.setTimeout(timeout);
|
|
|
+ expectedParams.put("timeout", timeout);
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ if (randomBoolean()) {
|
|
|
+ TaskId taskId = new TaskId(randomAlphaOfLength(5), randomNonNegativeLong());
|
|
|
+ request.setParentTaskId(taskId);
|
|
|
+ expectedParams.put("parent_task_id", taskId.toString());
|
|
|
+ } else {
|
|
|
+ request.setParentTask(TaskId.EMPTY_TASK_ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ String[] nodes = generateRandomStringArray(10, 8, false);
|
|
|
+ request.setNodes(nodes);
|
|
|
+ if (nodes.length > 0) {
|
|
|
+ expectedParams.put("nodes", String.join(",", nodes));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (randomBoolean()) {
|
|
|
+ String[] actions = generateRandomStringArray(10, 8, false);
|
|
|
+ request.setActions(actions);
|
|
|
+ if (actions.length > 0) {
|
|
|
+ expectedParams.put("actions", String.join(",", actions));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ expectedParams.put("group_by", "none");
|
|
|
+ Request httpRequest = RequestConverters.listTasks(request);
|
|
|
+ assertThat(httpRequest, notNullValue());
|
|
|
+ assertThat(httpRequest.getMethod(), equalTo(HttpGet.METHOD_NAME));
|
|
|
+ assertThat(httpRequest.getEntity(), nullValue());
|
|
|
+ assertThat(httpRequest.getEndpoint(), equalTo("/_tasks"));
|
|
|
+ assertThat(httpRequest.getParameters(), equalTo(expectedParams));
|
|
|
+ }
|
|
|
+ {
|
|
|
+ ListTasksRequest request = new ListTasksRequest();
|
|
|
+ request.setTaskId(new TaskId(randomAlphaOfLength(5), randomNonNegativeLong()));
|
|
|
+ IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> RequestConverters.listTasks(request));
|
|
|
+ assertEquals("TaskId cannot be used for list tasks request", exception.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testGetRepositories() {
|
|
|
Map<String, String> expectedParams = new HashMap<>();
|
|
|
StringBuilder endpoint = new StringBuilder("/_snapshot");
|
|
@@ -1474,7 +1534,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
setRandomLocal(getRepositoriesRequest, expectedParams);
|
|
|
|
|
|
if (randomBoolean()) {
|
|
|
- String[] entries = new String[] {"a", "b", "c"};
|
|
|
+ String[] entries = new String[] { "a", "b", "c" };
|
|
|
getRepositoriesRequest.repositories(entries);
|
|
|
endpoint.append("/" + String.join(",", entries));
|
|
|
}
|
|
@@ -1513,9 +1573,8 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
names.put("-#template", "-%23template");
|
|
|
names.put("foo^bar", "foo%5Ebar");
|
|
|
|
|
|
- PutIndexTemplateRequest putTemplateRequest = new PutIndexTemplateRequest()
|
|
|
- .name(randomFrom(names.keySet()))
|
|
|
- .patterns(Arrays.asList(generateRandomStringArray(20, 100, false, false)));
|
|
|
+ PutIndexTemplateRequest putTemplateRequest = new PutIndexTemplateRequest().name(randomFrom(names.keySet()))
|
|
|
+ .patterns(Arrays.asList(generateRandomStringArray(20, 100, false, false)));
|
|
|
if (randomBoolean()) {
|
|
|
putTemplateRequest.order(randomInt());
|
|
|
}
|
|
@@ -1572,14 +1631,12 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
assertEquals("/a/b", endpointBuilder.build());
|
|
|
}
|
|
|
{
|
|
|
- EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPart("b")
|
|
|
- .addPathPartAsIs("_create");
|
|
|
+ EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPart("b").addPathPartAsIs("_create");
|
|
|
assertEquals("/a/b/_create", endpointBuilder.build());
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a", "b", "c")
|
|
|
- .addPathPartAsIs("_create");
|
|
|
+ EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a", "b", "c").addPathPartAsIs("_create");
|
|
|
assertEquals("/a/b/c/_create", endpointBuilder.build());
|
|
|
}
|
|
|
{
|
|
@@ -1638,13 +1695,12 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
assertEquals("/foo%5Ebar", endpointBuilder.build());
|
|
|
}
|
|
|
{
|
|
|
- EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("cluster1:index1,index2")
|
|
|
- .addPathPartAsIs("_search");
|
|
|
+ EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("cluster1:index1,index2").addPathPartAsIs("_search");
|
|
|
assertEquals("/cluster1:index1,index2/_search", endpointBuilder.build());
|
|
|
}
|
|
|
{
|
|
|
- EndpointBuilder endpointBuilder = new EndpointBuilder()
|
|
|
- .addCommaSeparatedPathParts(new String[]{"index1", "index2"}).addPathPartAsIs("cache/clear");
|
|
|
+ EndpointBuilder endpointBuilder = new EndpointBuilder().addCommaSeparatedPathParts(new String[] { "index1", "index2" })
|
|
|
+ .addPathPartAsIs("cache/clear");
|
|
|
assertEquals("/index1,index2/cache/clear", endpointBuilder.build());
|
|
|
}
|
|
|
}
|
|
@@ -1652,12 +1708,12 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
public void testEndpoint() {
|
|
|
assertEquals("/index/type/id", RequestConverters.endpoint("index", "type", "id"));
|
|
|
assertEquals("/index/type/id/_endpoint", RequestConverters.endpoint("index", "type", "id", "_endpoint"));
|
|
|
- assertEquals("/index1,index2", RequestConverters.endpoint(new String[]{"index1", "index2"}));
|
|
|
- assertEquals("/index1,index2/_endpoint", RequestConverters.endpoint(new String[]{"index1", "index2"}, "_endpoint"));
|
|
|
- assertEquals("/index1,index2/type1,type2/_endpoint", RequestConverters.endpoint(new String[]{"index1", "index2"},
|
|
|
- new String[]{"type1", "type2"}, "_endpoint"));
|
|
|
- assertEquals("/index1,index2/_endpoint/suffix1,suffix2", RequestConverters.endpoint(new String[]{"index1", "index2"},
|
|
|
- "_endpoint", new String[]{"suffix1", "suffix2"}));
|
|
|
+ assertEquals("/index1,index2", RequestConverters.endpoint(new String[] { "index1", "index2" }));
|
|
|
+ assertEquals("/index1,index2/_endpoint", RequestConverters.endpoint(new String[] { "index1", "index2" }, "_endpoint"));
|
|
|
+ assertEquals("/index1,index2/type1,type2/_endpoint",
|
|
|
+ RequestConverters.endpoint(new String[] { "index1", "index2" }, new String[] { "type1", "type2" }, "_endpoint"));
|
|
|
+ assertEquals("/index1,index2/_endpoint/suffix1,suffix2",
|
|
|
+ RequestConverters.endpoint(new String[] { "index1", "index2" }, "_endpoint", new String[] { "suffix1", "suffix2" }));
|
|
|
}
|
|
|
|
|
|
public void testCreateContentType() {
|
|
@@ -1673,20 +1729,22 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
|
|
|
XContentType bulkContentType = randomBoolean() ? xContentType : null;
|
|
|
|
|
|
- IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () ->
|
|
|
- enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.CBOR), bulkContentType));
|
|
|
+ IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.CBOR),
|
|
|
+ bulkContentType));
|
|
|
assertEquals("Unsupported content-type found for request with content-type [CBOR], only JSON and SMILE are supported",
|
|
|
exception.getMessage());
|
|
|
|
|
|
- exception = expectThrows(IllegalArgumentException.class, () ->
|
|
|
- enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.YAML), bulkContentType));
|
|
|
+ exception = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), XContentType.YAML),
|
|
|
+ bulkContentType));
|
|
|
assertEquals("Unsupported content-type found for request with content-type [YAML], only JSON and SMILE are supported",
|
|
|
exception.getMessage());
|
|
|
|
|
|
XContentType requestContentType = xContentType == XContentType.JSON ? XContentType.SMILE : XContentType.JSON;
|
|
|
|
|
|
- exception = expectThrows(IllegalArgumentException.class, () ->
|
|
|
- enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), requestContentType), xContentType));
|
|
|
+ exception = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> enforceSameContentType(new IndexRequest().source(singletonMap("field", "value"), requestContentType), xContentType));
|
|
|
assertEquals("Mismatching content-type found for request with content-type [" + requestContentType + "], "
|
|
|
+ "previous requests have content-type [" + xContentType + "]", exception.getMessage());
|
|
|
}
|
|
@@ -1754,11 +1812,10 @@ public class RequestConvertersTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
private static void setRandomIndicesOptions(Consumer<IndicesOptions> setter, Supplier<IndicesOptions> getter,
|
|
|
- Map<String, String> expectedParams) {
|
|
|
+ Map<String, String> expectedParams) {
|
|
|
|
|
|
if (randomBoolean()) {
|
|
|
- setter.accept(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(),
|
|
|
- randomBoolean()));
|
|
|
+ setter.accept(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
|
|
|
}
|
|
|
expectedParams.put("ignore_unavailable", Boolean.toString(getter.get().ignoreUnavailable()));
|
|
|
expectedParams.put("allow_no_indices", Boolean.toString(getter.get().allowNoIndices()));
|