-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose 'features' option in Get Index API (#83083)
- Loading branch information
1 parent
836d9bc
commit 4ad7814
Showing
7 changed files
with
142 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 83083 | ||
summary: Expose 'features' option in Get Index API | ||
area: Indices APIs | ||
type: enhancement | ||
issues: | ||
- 82948 |
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
77 changes: 77 additions & 0 deletions
77
server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexRequestTests.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,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.get; | ||
|
||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.RestRequestTests; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.arrayContainingInAnyOrder; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class GetIndexRequestTests extends ESTestCase { | ||
|
||
public void testFeaturesFromRequest() { | ||
int numFeatures = randomIntBetween(1, GetIndexRequest.DEFAULT_FEATURES.length); | ||
List<String> featureNames = new ArrayList<>(); | ||
List<GetIndexRequest.Feature> expectedFeatures = new ArrayList<>(); | ||
for (int k = 0; k < numFeatures; k++) { | ||
GetIndexRequest.Feature feature = randomValueOtherThanMany( | ||
f -> featureNames.contains(f.name()), | ||
() -> randomFrom(GetIndexRequest.DEFAULT_FEATURES) | ||
); | ||
featureNames.add(feature.name()); | ||
expectedFeatures.add(feature); | ||
} | ||
|
||
RestRequest request = RestRequestTests.contentRestRequest("", Map.of("features", String.join(",", featureNames))); | ||
GetIndexRequest.Feature[] featureArray = GetIndexRequest.Feature.fromRequest(request); | ||
assertThat(featureArray, arrayContainingInAnyOrder(expectedFeatures.toArray(GetIndexRequest.Feature[]::new))); | ||
} | ||
|
||
public void testDuplicateFeatures() { | ||
int numFeatures = randomIntBetween(1, 5); | ||
GetIndexRequest.Feature feature = randomFrom(GetIndexRequest.DEFAULT_FEATURES); | ||
List<String> featureList = new ArrayList<>(); | ||
for (int k = 0; k < numFeatures; k++) { | ||
featureList.add(feature.name()); | ||
} | ||
RestRequest request = RestRequestTests.contentRestRequest("", Map.of("features", String.join(",", featureList))); | ||
GetIndexRequest.Feature[] features = GetIndexRequest.Feature.fromRequest(request); | ||
assertThat(features.length, equalTo(1)); | ||
assertThat(features[0], equalTo(feature)); | ||
} | ||
|
||
public void testMissingFeatures() { | ||
RestRequest request = RestRequestTests.contentRestRequest("", Map.of()); | ||
GetIndexRequest.Feature[] features = GetIndexRequest.Feature.fromRequest(request); | ||
assertThat(features, arrayContainingInAnyOrder(GetIndexRequest.DEFAULT_FEATURES)); | ||
} | ||
|
||
public void testInvalidFeatures() { | ||
int numFeatures = randomIntBetween(1, 4); | ||
List<String> invalidFeatures = new ArrayList<>(); | ||
for (int k = 0; k < numFeatures; k++) { | ||
invalidFeatures.add(randomAlphaOfLength(5)); | ||
} | ||
|
||
RestRequest request = RestRequestTests.contentRestRequest("", Map.of("features", String.join(",", invalidFeatures))); | ||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> GetIndexRequest.Feature.fromRequest(request)); | ||
assertThat( | ||
e.getMessage(), | ||
containsString(String.format(Locale.ROOT, "Invalid features specified [%s]", String.join(",", invalidFeatures))) | ||
); | ||
} | ||
} |
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