Skip to content

Commit

Permalink
Improving code coverage to make codcov happy
Browse files Browse the repository at this point in the history
Signed-off-by: gashutos <[email protected]>
  • Loading branch information
gashutos committed Sep 15, 2023
1 parent 2575a45 commit f61aba6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions server/src/test/java/org/opensearch/index/IndexServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
package org.opensearch.index;

import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
import org.opensearch.Version;
import org.opensearch.action.support.ActiveShardCount;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.compress.CompressedXContent;
Expand Down Expand Up @@ -526,4 +528,60 @@ public void testUpdateRemoteTranslogBufferIntervalDynamically() {
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertEquals("20s", indexMetadata.getSettings().get(IndexSettings.INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING.getKey()));
}

public void testIndexSort() {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "0ms") // disable
.putList("index.sort.field", "sortfield")
.build();
try {
// Integer index sort should be remained to int sort type
IndexService index = createIndex("test", settings, createTestMapping("integer"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.INT);

// Long index sort should be remained to long sort type
index = createIndex("test", settings, createTestMapping("long"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.LONG);

// String index sort should be remained to string sort type
index = createIndex("test", settings, createTestMapping("string"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.STRING);
} catch (IllegalArgumentException ex) {
assertEquals("failed to parse value [0ms] for setting [index.translog.sync_interval], must be >= [100ms]", ex.getMessage());
}
}

public void testIndexSortBackwardCompatible() {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "0ms") // disable
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), Version.V_2_6_1)
.putList("index.sort.field", "sortfield")
.build();
try {
// Integer index sort should be converted to long sort type
IndexService index = createIndex("test", settings, createTestMapping("integer"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.LONG);

// Long index sort should be remained to long sort type
index = createIndex("test", settings, createTestMapping("long"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.LONG);

// String index sort should be remained to string sort type
index = createIndex("test", settings, createTestMapping("string"));
assertTrue(index.getIndexSortSupplier().get().getSort()[0].getType() == SortField.Type.STRING);
} catch (IllegalArgumentException ex) {
assertEquals("failed to parse value [0ms] for setting [index.translog.sync_interval], must be >= [100ms]", ex.getMessage());
}
}

private static String createTestMapping(String type) {
return " \"properties\": {\n"
+ " \"test\": {\n"
+ " \"type\": \"text\"\n"
+ " },\n"
+ " \"sortfield\": {\n"
+ " \"type\": \" + type + \"\n"
+ " }\n"
+ " }";
}
}

0 comments on commit f61aba6

Please sign in to comment.