Skip to content

Commit cc93b25

Browse files
andrrossjainankitk
authored andcommitted
Replace usage of deprecated createIndex() method in tests (opensearch-project#18389)
The deprecated versions of this method take a type parameter, support for which was removed back in 2.0. The parameter is not used. I have kept the deprecated methods so as to not break downstream components that may be using them but changed all the code in server to stop passing in a type parameter. Signed-off-by: Andrew Ross <andrross@amazon.com> Signed-off-by: Ankit Jain <jainankitk@apache.org>
1 parent e390898 commit cc93b25

File tree

25 files changed

+86
-91
lines changed

25 files changed

+86
-91
lines changed

modules/analysis-common/src/test/java/org/opensearch/analysis/common/DisableGraphQueryTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ public void setup() {
9393
.put("index.analysis.analyzer.text_shingle_unigram.tokenizer", "whitespace")
9494
.put("index.analysis.analyzer.text_shingle_unigram.filter", "lowercase, shingle_unigram")
9595
.build();
96-
indexService = createIndex(
96+
indexService = createIndexWithSimpleMappings(
9797
"test",
9898
settings,
99-
"t",
10099
"text_shingle",
101100
"type=text,analyzer=text_shingle",
102101
"text_shingle_unigram",

modules/lang-painless/src/test/java/org/opensearch/painless/NeedsScoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
public class NeedsScoreTests extends OpenSearchSingleNodeTestCase {
5353

5454
public void testNeedsScores() {
55-
IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double");
55+
IndexService index = createIndexWithSimpleMappings("test", Settings.EMPTY, "d", "type=double");
5656

5757
Map<ScriptContext<?>, List<Allowlist>> contexts = new HashMap<>();
5858
contexts.put(NumberSortScript.CONTEXT, Allowlist.BASE_ALLOWLISTS);

modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteApiTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testDefaults() throws IOException {
8989

9090
public void testFilterExecutionContext() throws IOException {
9191
ScriptService scriptService = getInstanceFromNode(ScriptService.class);
92-
IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "field", "type=long");
92+
IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "field", "type=long");
9393

9494
Request.ContextSetup contextSetup = new Request.ContextSetup("index", new BytesArray("{\"field\": 3}"), null);
9595
contextSetup.setXContentType(MediaTypeRegistry.JSON);
@@ -120,7 +120,7 @@ public void testFilterExecutionContext() throws IOException {
120120

121121
public void testScoreExecutionContext() throws IOException {
122122
ScriptService scriptService = getInstanceFromNode(ScriptService.class);
123-
IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "rank", "type=long", "text", "type=text");
123+
IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "rank", "type=long", "text", "type=text");
124124

125125
Request.ContextSetup contextSetup = new Request.ContextSetup(
126126
"index",

modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public void testPercolateQueryWithNestedDocuments_doLeakFieldDataCacheEntries()
281281

282282
public void testMapUnmappedFieldAsText() throws IOException {
283283
Settings.Builder settings = Settings.builder().put("index.percolator.map_unmapped_fields_as_text", true);
284-
createIndex("test", settings.build(), "query", "query", "type=percolator");
284+
createIndexWithSimpleMappings("test", settings.build(), "query", "type=percolator");
285285
client().prepareIndex("test")
286286
.setId("1")
287287
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject())
@@ -302,10 +302,9 @@ public void testMapUnmappedFieldAsText() throws IOException {
302302
}
303303

304304
public void testRangeQueriesWithNow() throws Exception {
305-
IndexService indexService = createIndex(
305+
IndexService indexService = createIndexWithSimpleMappings(
306306
"test",
307307
Settings.builder().put("index.number_of_shards", 1).build(),
308-
"_doc",
309308
"field1",
310309
"type=keyword",
311310
"field2",

plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
6060
}
6161

6262
public void testSizeEnabled() throws Exception {
63-
IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true");
63+
IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=true");
6464
DocumentMapper docMapper = service.mapperService().documentMapper();
6565

6666
BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject());
@@ -77,7 +77,7 @@ public void testSizeEnabled() throws Exception {
7777
}
7878

7979
public void testSizeDisabled() throws Exception {
80-
IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false");
80+
IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=false");
8181
DocumentMapper docMapper = service.mapperService().documentMapper();
8282

8383
BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject());
@@ -87,7 +87,7 @@ public void testSizeDisabled() throws Exception {
8787
}
8888

8989
public void testSizeNotSet() throws Exception {
90-
IndexService service = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME);
90+
IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY);
9191
DocumentMapper docMapper = service.mapperService().documentMapper();
9292

9393
BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject());
@@ -97,7 +97,7 @@ public void testSizeNotSet() throws Exception {
9797
}
9898

9999
public void testThatDisablingWorksWhenMerging() throws Exception {
100-
IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true");
100+
IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=true");
101101
DocumentMapper docMapper = service.mapperService().documentMapper();
102102
assertThat(docMapper.metadataMapper(SizeFieldMapper.class).enabled(), is(true));
103103

server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import org.opensearch.index.engine.MergedSegmentWarmerFactory;
7878
import org.opensearch.index.engine.NoOpEngine;
7979
import org.opensearch.index.flush.FlushStats;
80-
import org.opensearch.index.mapper.MapperService;
8180
import org.opensearch.index.mapper.SourceToParse;
8281
import org.opensearch.index.seqno.RetentionLeaseSyncer;
8382
import org.opensearch.index.seqno.SequenceNumbers;
@@ -477,7 +476,7 @@ public void testMaybeRollTranslogGeneration() throws Exception {
477476
.put("index.number_of_shards", 1)
478477
.put("index.translog.generation_threshold_size", generationThreshold + "b")
479478
.build();
480-
createIndex("test", settings, MapperService.SINGLE_MAPPING_NAME);
479+
createIndexWithSimpleMappings("test", settings);
481480
ensureGreen("test");
482481
final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
483482
final IndexService test = indicesService.indexService(resolveIndex("test"));
@@ -813,7 +812,7 @@ public void testShardChangesWithDefaultDocType() throws Exception {
813812
.put("index.translog.flush_threshold_size", "512mb") // do not flush
814813
.put("index.soft_deletes.enabled", true)
815814
.build();
816-
IndexService indexService = createIndex("index", settings, "user_doc", "title", "type=keyword");
815+
IndexService indexService = createIndexWithSimpleMappings("index", settings, "title", "type=keyword");
817816
int numOps = between(1, 10);
818817
for (int i = 0; i < numOps; i++) {
819818
if (randomBoolean()) {

server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
public class FiltersAggsRewriteIT extends OpenSearchSingleNodeTestCase {
5252

5353
public void testWrapperQueryIsRewritten() throws IOException {
54-
createIndex("test", Settings.EMPTY, "test", "title", "type=text");
54+
createIndexWithSimpleMappings("test", Settings.EMPTY, "title", "type=text");
5555
client().prepareIndex("test").setId("1").setSource("title", "foo bar baz").get();
5656
client().prepareIndex("test").setId("2").setSource("title", "foo foo foo").get();
5757
client().prepareIndex("test").setId("3").setSource("title", "bar baz bax").get();

server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio
184184
.put("index.analysis.filter.my_delimited_payload.encoding", encodingString)
185185
.put("index.analysis.filter.my_delimited_payload.type", "mock_payload_filter")
186186
.build();
187-
createIndex("test", setting, "type1", mapping);
187+
createIndex("test", setting, mapping);
188188

189189
client().prepareIndex("test")
190190
.setId(Integer.toString(1))

server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void testThatAnalyzersAreUsedInMapping() throws IOException {
127127
.endObject()
128128
.endObject()
129129
.endObject();
130-
MapperService mapperService = createIndex("test", indexSettings, "type", mapping).mapperService();
130+
MapperService mapperService = createIndex("test", indexSettings, mapping).mapperService();
131131

132132
MappedFieldType fieldType = mapperService.fieldType("field");
133133
assertThat(fieldType.getTextSearchInfo().getSearchAnalyzer(), instanceOf(NamedAnalyzer.class));

server/src/test/java/org/opensearch/index/mapper/ConstantKeywordFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void testDerivedValueFetching() throws IOException {
156156
}
157157

158158
private ConstantKeywordFieldMapper getMapper(FieldMapper.CopyTo copyTo) {
159-
indexService = createIndex("test-index", Settings.EMPTY, "constant_keyword", "field", "type=constant_keyword,value=default_value");
159+
indexService = createIndexWithSimpleMappings("test-index", Settings.EMPTY, "field", "type=constant_keyword,value=default_value");
160160
ConstantKeywordFieldMapper mapper = (ConstantKeywordFieldMapper) indexService.mapperService()
161161
.documentMapper()
162162
.mappers()

0 commit comments

Comments
 (0)