Skip to content

Commit

Permalink
Enhance unit tests for CodecService methods (elastic#111382)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivamly authored Jul 31, 2024
1 parent b3e8dae commit 67e8b97
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/src/test/java/org/elasticsearch/index/codec/CodecTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.hamcrest.Matchers;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.instanceOf;

Expand Down Expand Up @@ -96,6 +98,29 @@ public void testLegacyBestCompression() throws Exception {
}
}

public void testCodecRetrievalForUnknownCodec() throws Exception {
CodecService codecService = createCodecService();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> codecService.codec("unknown_codec"));
assertEquals("failed to find codec [unknown_codec]", exception.getMessage());
}

public void testAvailableCodecsContainsExpectedCodecs() throws Exception {
CodecService codecService = createCodecService();
String[] availableCodecs = codecService.availableCodecs();
List<String> codecList = Arrays.asList(availableCodecs);
int expectedCodecCount = Codec.availableCodecs().size() + 5;

assertTrue(codecList.contains(CodecService.DEFAULT_CODEC));
assertTrue(codecList.contains(CodecService.LEGACY_DEFAULT_CODEC));
assertTrue(codecList.contains(CodecService.BEST_COMPRESSION_CODEC));
assertTrue(codecList.contains(CodecService.LEGACY_BEST_COMPRESSION_CODEC));
assertTrue(codecList.contains(CodecService.LUCENE_DEFAULT_CODEC));

assertFalse(codecList.contains("unknown_codec"));

assertEquals(expectedCodecCount, availableCodecs.length);
}

private CodecService createCodecService() throws IOException {
Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
IndexSettings settings = IndexSettingsModule.newIndexSettings("_na", nodeSettings);
Expand Down

0 comments on commit 67e8b97

Please sign in to comment.