浏览代码

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
Ryan Ernst 7 年之前
父节点
当前提交
e5d82c3dea

+ 6 - 2
server/src/test/java/org/elasticsearch/index/fielddata/ScriptDocValuesDatesTests.java

@@ -47,7 +47,6 @@ public class ScriptDocValuesDatesTests extends ESTestCase {
         assertDateDocValues(true);
         assertDateDocValues(true);
     }
     }
 
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32779")
     public void testJodaTimeBwc() throws IOException {
     public void testJodaTimeBwc() throws IOException {
         assertDateDocValues(false, "The joda time api for doc values is deprecated." +
         assertDateDocValues(false, "The joda time api for doc values is deprecated." +
             " Use -Des.scripting.use_java_time=true to use the java time api for date field doc values");
             " Use -Des.scripting.use_java_time=true to use the java time api for date field doc values");
@@ -71,6 +70,7 @@ public class ScriptDocValuesDatesTests extends ESTestCase {
             }
             }
         }
         }
 
 
+
         Set<String> warnings = new HashSet<>();
         Set<String> warnings = new HashSet<>();
         Dates dates = wrap(values, deprecationMessage -> {
         Dates dates = wrap(values, deprecationMessage -> {
             warnings.add(deprecationMessage);
             warnings.add(deprecationMessage);
@@ -86,12 +86,14 @@ public class ScriptDocValuesDatesTests extends ESTestCase {
             }
             }
         );
         );
 
 
+        boolean valuesExist = false;
         for (int round = 0; round < 10; round++) {
         for (int round = 0; round < 10; round++) {
             int d = between(0, values.length - 1);
             int d = between(0, values.length - 1);
             dates.setNextDocId(d);
             dates.setNextDocId(d);
             if (expectedDates[d].length > 0) {
             if (expectedDates[d].length > 0) {
                 Object dateValue = AccessController.doPrivileged((PrivilegedAction<Object>) dates::getValue, noPermissionsAcc);
                 Object dateValue = AccessController.doPrivileged((PrivilegedAction<Object>) dates::getValue, noPermissionsAcc);
                 assertEquals(expectedDates[d][0] , dateValue);
                 assertEquals(expectedDates[d][0] , dateValue);
+                valuesExist = true;
             } else {
             } else {
                 Exception e = expectThrows(IllegalStateException.class, () -> dates.getValue());
                 Exception e = expectThrows(IllegalStateException.class, () -> dates.getValue());
                 assertEquals("A document doesn't have a value for a field! " +
                 assertEquals("A document doesn't have a value for a field! " +
@@ -106,7 +108,9 @@ public class ScriptDocValuesDatesTests extends ESTestCase {
             }
             }
         }
         }
 
 
-        assertThat(warnings, containsInAnyOrder(expectedWarnings));
+        if (valuesExist) {
+            assertThat(warnings, containsInAnyOrder(expectedWarnings));
+        }
     }
     }
 
 
     private Dates wrap(long[][] values, Consumer<String> deprecationHandler, boolean useJavaTime) {
     private Dates wrap(long[][] values, Consumer<String> deprecationHandler, boolean useJavaTime) {