Skip to content

Commit af15b92

Browse files
committed
Test: Fix dv date bwc tests when no docs have a value (#32798)
This commit adds a guard around the rare case that no documents in the 10 iterations actually have any values, thus making the warning check incorrect. closes #32779
1 parent fccf35a commit af15b92

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesDatesTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ public void assertDateDocValues(boolean useJavaTime, String... expectedWarnings)
8888
}
8989
);
9090

91+
boolean valuesExist = false;
9192
for (int round = 0; round < 10; round++) {
9293
int d = between(0, values.length - 1);
9394
dates.setNextDocId(d);
9495
Object dateValue = AccessController.doPrivileged((PrivilegedAction<Object>) dates::getValue, noPermissionsAcc);
9596
assertEquals(expectedDates[d].length > 0 ? expectedDates[d][0] : new DateTime(0, DateTimeZone.UTC), dateValue);
9697
Object bwcDateValue = AccessController.doPrivileged((PrivilegedAction<Object>) dates::getDate, noPermissionsAcc);
9798
assertEquals(expectedDates[d].length > 0 ? expectedDates[d][0] : new DateTime(0, DateTimeZone.UTC), bwcDateValue);
99+
valuesExist |= expectedDates[d].length > 0;
98100

99101
AccessController.doPrivileged((PrivilegedAction<Object>) dates::getDates, noPermissionsAcc);
100102
assertEquals(values[d].length, dates.size());
@@ -107,7 +109,9 @@ public void assertDateDocValues(boolean useJavaTime, String... expectedWarnings)
107109
// using "hasItems" here instead of "containsInAnyOrder",
108110
// because values are randomly initialized, sometimes some of docs will not have any values
109111
// and warnings in this case will contain another deprecation warning on missing values
110-
assertThat(warnings, hasItems(expectedWarnings));
112+
if (valuesExist) {
113+
assertThat(warnings, hasItems(expectedWarnings));
114+
}
111115
}
112116

113117
private Dates wrap(long[][] values, BiConsumer<String, String> deprecationHandler, boolean useJavaTime) {

0 commit comments

Comments
 (0)