Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Jun 27, 2024
1 parent bbaa1c7 commit 28e895c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.opensearch.index.codec.composite.Composite99Codec
47 changes: 47 additions & 0 deletions server/src/test/java/org/opensearch/index/codec/CodecTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.env.Environment;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.analysis.IndexAnalyzers;
import org.opensearch.index.codec.composite.Composite99Codec;
import org.opensearch.index.engine.EngineConfig;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.similarity.SimilarityService;
Expand All @@ -59,6 +60,8 @@
import java.io.IOException;
import java.util.Collections;

import org.mockito.Mockito;

import static org.opensearch.index.engine.EngineConfig.INDEX_CODEC_COMPRESSION_LEVEL_SETTING;
import static org.hamcrest.Matchers.instanceOf;

Expand Down Expand Up @@ -93,6 +96,35 @@ public void testZlib() throws Exception {
assert codec instanceof PerFieldMappingPostingFormatCodec;
}

public void testResolveDefaultCodecsWithCompositeIndex() throws Exception {
CodecService codecService = createCodecService(false, true);
assertThat(codecService.codec("default"), instanceOf(Composite99Codec.class));
}

public void testDefaultWithCompositeIndex() throws Exception {
Codec codec = createCodecService(false, true).codec("default");
assertStoredFieldsCompressionEquals(Lucene99Codec.Mode.BEST_SPEED, codec);
assert codec instanceof Composite99Codec;
}

public void testBestCompressionWithCompositeIndex() throws Exception {
Codec codec = createCodecService(false, true).codec("best_compression");
assertStoredFieldsCompressionEquals(Lucene99Codec.Mode.BEST_COMPRESSION, codec);
assert codec instanceof Composite99Codec;
}

public void testLZ4WithCompositeIndex() throws Exception {
Codec codec = createCodecService(false, true).codec("lz4");
assertStoredFieldsCompressionEquals(Lucene99Codec.Mode.BEST_SPEED, codec);
assert codec instanceof Composite99Codec;
}

public void testZlibWithCompositeIndex() throws Exception {
Codec codec = createCodecService(false, true).codec("zlib");
assertStoredFieldsCompressionEquals(Lucene99Codec.Mode.BEST_COMPRESSION, codec);
assert codec instanceof Composite99Codec;
}

public void testBestCompressionWithCompressionLevel() {
final Settings settings = Settings.builder()
.put(INDEX_CODEC_COMPRESSION_LEVEL_SETTING.getKey(), randomIntBetween(1, 6))
Expand Down Expand Up @@ -150,10 +182,17 @@ private void assertStoredFieldsCompressionEquals(Lucene99Codec.Mode expected, Co
}

private CodecService createCodecService(boolean isMapperServiceNull) throws IOException {
return createCodecService(isMapperServiceNull, false);
}

private CodecService createCodecService(boolean isMapperServiceNull, boolean isCompositeIndexPresent) throws IOException {
Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
if (isMapperServiceNull) {
return new CodecService(null, IndexSettingsModule.newIndexSettings("_na", nodeSettings), LogManager.getLogger("test"));
}
if (isCompositeIndexPresent) {
return buildCodecServiceWithCompositeIndex(nodeSettings);
}
return buildCodecService(nodeSettings);
}

Expand All @@ -176,6 +215,14 @@ private CodecService buildCodecService(Settings nodeSettings) throws IOException
return new CodecService(service, indexSettings, LogManager.getLogger("test"));
}

private CodecService buildCodecServiceWithCompositeIndex(Settings nodeSettings) throws IOException {

IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("_na", nodeSettings);
MapperService service = Mockito.mock(MapperService.class);
Mockito.when(service.isCompositeIndexPresent()).thenReturn(true);
return new CodecService(service, indexSettings, LogManager.getLogger("test"));
}

private SegmentReader getSegmentReader(Codec codec) throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(null);
Expand Down

0 comments on commit 28e895c

Please sign in to comment.