|
@@ -20,15 +20,11 @@
|
|
|
package org.elasticsearch.action.admin.indices.get;
|
|
|
|
|
|
import org.apache.lucene.util.CollectionUtil;
|
|
|
-import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponseTests;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponseTests;
|
|
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
|
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
|
-import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
-import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
-import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.settings.IndexScopedSettings;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
@@ -36,32 +32,16 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.index.RandomCreateIndexGenerator;
|
|
|
import org.elasticsearch.rest.BaseRestHandler;
|
|
|
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
|
|
|
-import org.junit.Assert;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.io.UncheckedIOException;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Base64;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
-import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
|
|
-import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
|
|
-import static org.elasticsearch.index.IndexSettings.INDEX_REFRESH_INTERVAL_SETTING;
|
|
|
-
|
|
|
public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<GetIndexResponse> {
|
|
|
|
|
|
- /**
|
|
|
- * The following byte response was generated from the v6.3.0 tag
|
|
|
- */
|
|
|
- private static final String TEST_6_3_0_RESPONSE_BYTES =
|
|
|
- "AQhteV9pbmRleAEIbXlfaW5kZXgBA2RvYwNkb2OePID6KURGTACqVkrLTM1JiTdUsqpWKqksSFWyUiouKcrMS1eqrQUAAAD//" +
|
|
|
- "wMAAAABCG15X2luZGV4AgZhbGlhczEAAQJyMQECcjEGYWxpYXMyAX8jNXYiREZMAKpWKkktylWyqlaqTE0sUrIyMjA0q60FAAAA//" +
|
|
|
- "8DAAAAAQhteV9pbmRleAIYaW5kZXgubnVtYmVyX29mX3JlcGxpY2FzAAExFmluZGV4Lm51bWJlcl9vZl9zaGFyZHMAATI=";
|
|
|
- private static final GetIndexResponse TEST_6_3_0_RESPONSE_INSTANCE = getExpectedTest630Response();
|
|
|
-
|
|
|
@Override
|
|
|
protected GetIndexResponse doParseInstance(XContentParser parser) throws IOException {
|
|
|
return GetIndexResponse.fromXContent(parser);
|
|
@@ -115,86 +95,6 @@ public class GetIndexResponseTests extends AbstractStreamableXContentTestCase<Ge
|
|
|
f.contains(".aliases");
|
|
|
}
|
|
|
|
|
|
- private static ImmutableOpenMap<String, List<AliasMetaData>> getTestAliases(String indexName) {
|
|
|
- ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliases = ImmutableOpenMap.builder();
|
|
|
- List<AliasMetaData> indexAliases = new ArrayList<>();
|
|
|
- indexAliases.add(new AliasMetaData.Builder("alias1").routing("r1").build());
|
|
|
- indexAliases.add(new AliasMetaData.Builder("alias2").filter("{\"term\": {\"year\": 2016}}").build());
|
|
|
- aliases.put(indexName, Collections.unmodifiableList(indexAliases));
|
|
|
- return aliases.build();
|
|
|
- }
|
|
|
-
|
|
|
- private static ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> getTestMappings(String indexName) {
|
|
|
- ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> mappings = ImmutableOpenMap.builder();
|
|
|
- ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder();
|
|
|
- try {
|
|
|
- indexMappings.put(
|
|
|
- "doc",
|
|
|
- new MappingMetaData("doc",
|
|
|
- Collections.singletonMap("field_1", Collections.singletonMap("type", "string"))
|
|
|
- )
|
|
|
- );
|
|
|
- } catch (IOException e) {
|
|
|
- throw new UncheckedIOException(e);
|
|
|
- }
|
|
|
- mappings.put(indexName, indexMappings.build());
|
|
|
- return mappings.build();
|
|
|
- }
|
|
|
-
|
|
|
- private static ImmutableOpenMap<String, Settings> getTestSettings(String indexName) {
|
|
|
- ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder();
|
|
|
- Settings.Builder indexSettings = Settings.builder();
|
|
|
- indexSettings.put(SETTING_NUMBER_OF_SHARDS, 2);
|
|
|
- indexSettings.put(SETTING_NUMBER_OF_REPLICAS, 1);
|
|
|
- settings.put(indexName, indexSettings.build());
|
|
|
- return settings.build();
|
|
|
- }
|
|
|
-
|
|
|
- private static GetIndexResponse getExpectedTest630Response() {
|
|
|
- // The only difference between this snippet and the one used for generation TEST_6_3_0_RESPONSE_BYTES is the
|
|
|
- // constructor for GetIndexResponse which also takes defaultSettings now.
|
|
|
- String indexName = "my_index";
|
|
|
- String indices[] = { indexName };
|
|
|
- return
|
|
|
- new GetIndexResponse(
|
|
|
- indices, getTestMappings(indexName), getTestAliases(indexName), getTestSettings(indexName),
|
|
|
- ImmutableOpenMap.of()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- private static GetIndexResponse getResponseWithDefaultSettings() {
|
|
|
- String indexName = "my_index";
|
|
|
- String indices[] = { indexName };
|
|
|
- ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder();
|
|
|
- Settings.Builder indexDefaultSettings = Settings.builder();
|
|
|
- indexDefaultSettings.put(INDEX_REFRESH_INTERVAL_SETTING.getKey(), "1s");
|
|
|
- defaultSettings.put(indexName, indexDefaultSettings.build());
|
|
|
- return
|
|
|
- new GetIndexResponse(
|
|
|
- indices, getTestMappings(indexName), getTestAliases(indexName), getTestSettings(indexName),
|
|
|
- defaultSettings.build()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- public void testCanDecode622Response() throws IOException {
|
|
|
- StreamInput si = StreamInput.wrap(Base64.getDecoder().decode(TEST_6_3_0_RESPONSE_BYTES));
|
|
|
- si.setVersion(Version.V_6_3_0);
|
|
|
- GetIndexResponse response = new GetIndexResponse();
|
|
|
- response.readFrom(si);
|
|
|
-
|
|
|
- Assert.assertEquals(TEST_6_3_0_RESPONSE_INSTANCE, response);
|
|
|
- }
|
|
|
-
|
|
|
- public void testCanOutput622Response() throws IOException {
|
|
|
- GetIndexResponse responseWithExtraFields = getResponseWithDefaultSettings();
|
|
|
- BytesStreamOutput bso = new BytesStreamOutput();
|
|
|
- bso.setVersion(Version.V_6_3_0);
|
|
|
- responseWithExtraFields.writeTo(bso);
|
|
|
- String base64OfResponse = Base64.getEncoder().encodeToString(BytesReference.toBytes(bso.bytes()));
|
|
|
-
|
|
|
- Assert.assertEquals(TEST_6_3_0_RESPONSE_BYTES, base64OfResponse);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* For xContent roundtrip testing we force the xContent output to still contain types because the parser still expects them.
|
|
|
* The new typeless parsing is implemented in the client side GetIndexResponse.
|