|
16 | 16 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
17 | 17 | import org.elasticsearch.common.settings.Settings; |
18 | 18 | import org.elasticsearch.index.IndexSettings; |
| 19 | +import org.elasticsearch.index.codec.CodecService; |
19 | 20 | import org.elasticsearch.index.codec.Elasticsearch92Lucene103Codec; |
| 21 | +import org.elasticsearch.index.codec.LegacyPerFieldMapperCodec; |
20 | 22 | import org.elasticsearch.index.engine.Engine; |
21 | 23 | import org.elasticsearch.indices.IndicesService; |
22 | 24 | import org.elasticsearch.test.ESSingleNodeTestCase; |
23 | 25 | import org.elasticsearch.xcontent.XContentFactory; |
24 | 26 |
|
25 | 27 | import java.util.Set; |
| 28 | +import java.util.function.Function; |
26 | 29 |
|
27 | 30 | import static org.hamcrest.Matchers.equalTo; |
28 | 31 | import static org.hamcrest.Matchers.greaterThan; |
@@ -86,9 +89,23 @@ private void indexDocuments(String indexName) throws Exception { |
86 | 89 | private void assertDocValuesFormat(String indexName, DocValuesFormat expectedFormat, Set<String> expectedFields) { |
87 | 90 | var indexService = getInstanceFromNode(IndicesService.class).indexServiceSafe(resolveIndex(indexName)); |
88 | 91 | var shard = indexService.getShard(0); |
89 | | - var codec = (Elasticsearch92Lucene103Codec) shard.getEngineOrNull().config().getCodec(); |
| 92 | + var codec = shard.withEngineOrNull(engine -> engine.config().getCodec()); |
| 93 | + Function<String, DocValuesFormat> docValuesFormatProvider; |
| 94 | + if (codec instanceof Elasticsearch92Lucene103Codec es92103codec) { |
| 95 | + docValuesFormatProvider = es92103codec::getDocValuesFormatForField; |
| 96 | + } else if (codec instanceof CodecService.DeduplicateFieldInfosCodec deduplicateFieldInfosCodec) { |
| 97 | + if (deduplicateFieldInfosCodec.delegate() instanceof LegacyPerFieldMapperCodec legacyPerFieldMapperCodec) { |
| 98 | + docValuesFormatProvider = legacyPerFieldMapperCodec::getDocValuesFormatForField; |
| 99 | + } else { |
| 100 | + fail("Unexpected codec type: " + codec.getClass().getName()); |
| 101 | + return; |
| 102 | + } |
| 103 | + } else { |
| 104 | + fail("Unexpected codec type: " + codec.getClass().getName()); |
| 105 | + return; |
| 106 | + } |
90 | 107 | for (String field : expectedFields) { |
91 | | - DocValuesFormat writerFormat = codec.getDocValuesFormatForField(field); |
| 108 | + DocValuesFormat writerFormat = docValuesFormatProvider.apply(field); |
92 | 109 | assertThat( |
93 | 110 | "IndexWriter codec for field [" + field + "] should return the expected TSDB doc values format instance", |
94 | 111 | writerFormat, |
|
0 commit comments