From 16aff4ed6068d3826d7b1dcbb4350caf4cd57e20 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Thu, 10 Mar 2022 07:38:52 -0600 Subject: [PATCH] fix failing tests Signed-off-by: Nicholas Walter Knize --- .../admin/indices/create/CreateIndexIT.java | 10 +- .../gateway/GatewayIndexStateIT.java | 14 +- .../opensearch/index/shard/IndexShardIT.java | 5 +- .../indices/exists/types/TypesExistsIT.java | 128 ------------------ .../mapping/UpdateMappingIntegrationIT.java | 4 +- 5 files changed, 17 insertions(+), 144 deletions(-) delete mode 100644 server/src/internalClusterTest/java/org/opensearch/indices/exists/types/TypesExistsIT.java diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java index 1e99b1dfcdad7..476bd72ee3ca3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java @@ -52,6 +52,7 @@ import org.opensearch.index.IndexNotFoundException; import org.opensearch.index.IndexService; import org.opensearch.index.mapper.MapperParsingException; +import org.opensearch.index.mapper.MapperService; import org.opensearch.index.query.RangeQueryBuilder; import org.opensearch.indices.IndicesService; import org.opensearch.test.OpenSearchIntegTestCase; @@ -144,11 +145,16 @@ public void testMappingParamAndNestedMismatch() throws Exception { MapperParsingException e = expectThrows( MapperParsingException.class, () -> prepareCreate("test").addMapping( - "type1", + MapperService.SINGLE_MAPPING_NAME, XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject() ).get() ); - assertThat(e.getMessage(), startsWith("Failed to parse mapping [type1]: Root mapping definition has unsupported parameters")); + assertThat( + e.getMessage(), + startsWith( + "Failed to parse mapping [" + MapperService.SINGLE_MAPPING_NAME + "]: Root mapping definition has unsupported parameters" + ) + ); } public void testEmptyMappings() throws Exception { diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java index 1779fe025887a..6fe22e2a8fde4 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java @@ -60,6 +60,7 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.env.NodeEnvironment; import org.opensearch.index.mapper.MapperParsingException; +import org.opensearch.index.mapper.MapperService; import org.opensearch.indices.IndexClosedException; import org.opensearch.indices.ShardLimitValidator; import org.opensearch.test.OpenSearchIntegTestCase; @@ -108,14 +109,7 @@ public void testMappingMetadataParsed() throws Exception { .prepareCreate("test") .addMapping( "type1", - XContentFactory.jsonBuilder() - .startObject() - .startObject("type1") - .startObject("_routing") - .field("required", true) - .endObject() - .endObject() - .endObject() + XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject() ) .execute() .actionGet(); @@ -130,7 +124,7 @@ public void testMappingMetadataParsed() throws Exception { .metadata() .index("test") .getMappings() - .get("type1"); + .get(MapperService.SINGLE_MAPPING_NAME); assertThat(mappingMd.routing().required(), equalTo(true)); logger.info("--> restarting nodes..."); @@ -149,7 +143,7 @@ public void testMappingMetadataParsed() throws Exception { .metadata() .index("test") .getMappings() - .get("type1"); + .get(MapperService.SINGLE_MAPPING_NAME); assertThat(mappingMd.routing().required(), equalTo(true)); } diff --git a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java index 11667fca8fce1..4c200720a3af6 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java @@ -74,6 +74,7 @@ import org.opensearch.index.engine.Engine; import org.opensearch.index.engine.NoOpEngine; import org.opensearch.index.flush.FlushStats; +import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.SourceToParse; import org.opensearch.index.seqno.RetentionLeaseSyncer; import org.opensearch.index.seqno.SequenceNumbers; @@ -445,7 +446,7 @@ public void testMaybeRollTranslogGeneration() throws Exception { .put("index.number_of_shards", 1) .put("index.translog.generation_threshold_size", generationThreshold + "b") .build(); - createIndex("test", settings, "test"); + createIndex("test", settings, MapperService.SINGLE_MAPPING_NAME); ensureGreen("test"); final IndicesService indicesService = getInstanceFromNode(IndicesService.class); final IndexService test = indicesService.indexService(resolveIndex("test")); @@ -459,7 +460,7 @@ public void testMaybeRollTranslogGeneration() throws Exception { final Engine.IndexResult result = shard.applyIndexOperationOnPrimary( Versions.MATCH_ANY, VersionType.INTERNAL, - new SourceToParse("test", "test", "1", new BytesArray("{}"), XContentType.JSON), + new SourceToParse("test", MapperService.SINGLE_MAPPING_NAME, "1", new BytesArray("{}"), XContentType.JSON), SequenceNumbers.UNASSIGNED_SEQ_NO, 0, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/exists/types/TypesExistsIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/exists/types/TypesExistsIT.java deleted file mode 100644 index 5d219159e1b5f..0000000000000 --- a/server/src/internalClusterTest/java/org/opensearch/indices/exists/types/TypesExistsIT.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -/* - * 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. - */ -/* - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.indices.exists.types; - -import org.opensearch.action.admin.indices.create.CreateIndexResponse; -import org.opensearch.action.admin.indices.exists.types.TypesExistsResponse; -import org.opensearch.client.Client; -import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.index.IndexNotFoundException; -import org.opensearch.plugins.Plugin; -import org.opensearch.test.OpenSearchIntegTestCase; -import org.opensearch.test.InternalSettingsPlugin; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_READ; -import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; -import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; -import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; -import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; -import static org.hamcrest.Matchers.equalTo; - -public class TypesExistsIT extends OpenSearchIntegTestCase { - - @Override - protected Collection> nodePlugins() { - return Collections.singleton(InternalSettingsPlugin.class); - } - - public void testSimple() throws Exception { - Client client = client(); - CreateIndexResponse response1 = client.admin() - .indices() - .prepareCreate("test1") - .addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()) - .execute() - .actionGet(); - CreateIndexResponse response2 = client.admin() - .indices() - .prepareCreate("test2") - .addMapping("type2", jsonBuilder().startObject().startObject("type2").endObject().endObject()) - .execute() - .actionGet(); - client.admin().indices().prepareAliases().addAlias("test1", "alias1").execute().actionGet(); - assertAcked(response1); - assertAcked(response2); - - TypesExistsResponse response = client.admin().indices().prepareTypesExists("test1").setTypes("type1").execute().actionGet(); - assertThat(response.isExists(), equalTo(true)); - response = client.admin().indices().prepareTypesExists("test1").setTypes("type2").execute().actionGet(); - assertThat(response.isExists(), equalTo(false)); - try { - client.admin().indices().prepareTypesExists("notExist").setTypes("type1").execute().actionGet(); - fail("Exception should have been thrown"); - } catch (IndexNotFoundException e) {} - try { - client.admin().indices().prepareTypesExists("notExist").setTypes("type0").execute().actionGet(); - fail("Exception should have been thrown"); - } catch (IndexNotFoundException e) {} - response = client.admin().indices().prepareTypesExists("alias1").setTypes("type1").execute().actionGet(); - assertThat(response.isExists(), equalTo(true)); - response = client.admin().indices().prepareTypesExists("*").setTypes("type1").execute().actionGet(); - assertThat(response.isExists(), equalTo(false)); - response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type1").execute().actionGet(); - assertThat(response.isExists(), equalTo(false)); - response = client.admin().indices().prepareTypesExists("test1", "test2").setTypes("type2").execute().actionGet(); - assertThat(response.isExists(), equalTo(false)); - } - - public void testTypesExistsWithBlocks() throws IOException { - assertAcked(prepareCreate("ro").addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject())); - ensureGreen("ro"); - - // Request is not blocked - for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) { - try { - enableIndexBlock("ro", block); - assertThat( - client().admin().indices().prepareTypesExists("ro").setTypes("type1").execute().actionGet().isExists(), - equalTo(true) - ); - } finally { - disableIndexBlock("ro", block); - } - } - - // Request is blocked - try { - enableIndexBlock("ro", IndexMetadata.SETTING_BLOCKS_METADATA); - assertBlocked(client().admin().indices().prepareTypesExists("ro").setTypes("type1")); - } finally { - disableIndexBlock("ro", IndexMetadata.SETTING_BLOCKS_METADATA); - } - } -} diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java index b5dff27bc1525..a325bbc62f8a8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -249,7 +249,7 @@ public void testUpdateMappingNoChanges() { .prepareCreate("test") .setSettings(Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0)) .addMapping( - "type", + MapperService.SINGLE_MAPPING_NAME, "{\"" + MapperService.SINGLE_MAPPING_NAME + "\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON ) @@ -260,7 +260,7 @@ public void testUpdateMappingNoChanges() { AcknowledgedResponse putMappingResponse = client().admin() .indices() .preparePutMapping("test") - .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}", XContentType.JSON) + .setSource("{\"properties\":{\"body\":{\"type\":\"text\"}}}", XContentType.JSON) .execute() .actionGet();