Skip to content

Commit 5e8ea42

Browse files
committed
Assert per field format field info attributes.
1 parent b641e01 commit 5e8ea42

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

server/src/test/java/org/elasticsearch/index/codec/tsdb/TsdbDocValueBwcTests.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@
4949
public class TsdbDocValueBwcTests extends ESTestCase {
5050

5151
public void testMixedIndex() throws Exception {
52-
Codec oldCodec = TestUtil.alwaysDocValuesFormat(new TestES87TSDBDocValuesFormat());
53-
Codec newCodec = TestUtil.alwaysDocValuesFormat(new ES819TSDBDocValuesFormat());
52+
var oldCodec = TestUtil.alwaysDocValuesFormat(new TestES87TSDBDocValuesFormat());
53+
var newCodec = TestUtil.alwaysDocValuesFormat(new ES819TSDBDocValuesFormat());
5454
testMixedIndex(oldCodec, newCodec);
5555
}
5656

5757
public void testMixedIndex816To900Lucene101() throws Exception {
58-
Codec oldCodec = new Elasticsearch816Codec() {
58+
var oldCodec = new Elasticsearch816Codec() {
5959

6060
final DocValuesFormat docValuesFormat = new TestES87TSDBDocValuesFormat();
6161

@@ -64,7 +64,7 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
6464
return docValuesFormat;
6565
}
6666
};
67-
Codec newCodec = new Elasticsearch900Lucene101Codec() {
67+
var newCodec = new Elasticsearch900Lucene101Codec() {
6868

6969
final DocValuesFormat docValuesFormat = new ES819TSDBDocValuesFormat();
7070

@@ -129,6 +129,16 @@ void testMixedIndex(Codec oldCodec, Codec newCodec) throws IOException, NoSuchFi
129129
// Check documents before force merge:
130130
try (var reader = DirectoryReader.open(dir)) {
131131
assertOldDocValuesFormatVersion(reader);
132+
// Assert per field format field info attributes:
133+
// (XPerFieldDocValuesFormat must produce the same attributes as PerFieldDocValuesFormat for BWC.
134+
// Otherwise, doc values fields may disappear)
135+
for (var leaf : reader.leaves()) {
136+
for (var fieldInfo : leaf.reader().getFieldInfos()) {
137+
assertThat(fieldInfo.attributes(), Matchers.aMapWithSize(2));
138+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.suffix", "0"));
139+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.format", "ES87TSDB"));
140+
}
141+
}
132142

133143
var hostNameDV = MultiDocValues.getSortedValues(reader, hostnameField);
134144
assertNotNull(hostNameDV);
@@ -189,6 +199,15 @@ void testMixedIndex(Codec oldCodec, Codec newCodec) throws IOException, NoSuchFi
189199
assertEquals(numDocs, reader.maxDoc());
190200
assertNewDocValuesFormatVersion(reader);
191201
var leaf = reader.leaves().get(0).reader();
202+
// Assert per field format field info attributes:
203+
// (XPerFieldDocValuesFormat must produce the same attributes as PerFieldDocValuesFormat for BWC.
204+
// Otherwise, doc values fields may disappear)
205+
for (var fieldInfo : leaf.getFieldInfos()) {
206+
assertThat(fieldInfo.attributes(), Matchers.aMapWithSize(2));
207+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.suffix", "0"));
208+
assertThat(fieldInfo.attributes(), Matchers.hasEntry("PerFieldDocValuesFormat.format", "ES819TSDB"));
209+
}
210+
192211
var hostNameDV = leaf.getSortedDocValues(hostnameField);
193212
assertNotNull(hostNameDV);
194213
var timestampDV = DocValues.unwrapSingleton(leaf.getSortedNumericDocValues(timestampField));

0 commit comments

Comments
 (0)