1
0
Эх сурвалжийг харах

Add random positive time value convenience method

This commit adds a convenience method for producing random positive time
values which can be useful for places where non-negative and non-zero
time values are expected.
Jason Tedor 9 жил өмнө
parent
commit
69a3f7f590

+ 11 - 2
test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

@@ -382,9 +382,18 @@ public abstract class ESTestCase extends LuceneTestCase {
         return generateRandomStringArray(maxArraySize, maxStringSize, allowNull, true);
     }
 
+    private static String[] TIME_SUFFIXES = new String[]{"d", "H", "ms", "s", "S", "w"};
+
+    private static String randomTimeValue(int lower, int upper) {
+        return randomIntBetween(lower, upper) + randomFrom(TIME_SUFFIXES);
+    }
+
     public static String randomTimeValue() {
-        final String[] values = new String[]{"d", "H", "ms", "s", "S", "w"};
-        return randomIntBetween(0, 1000) + randomFrom(values);
+        return randomTimeValue(0, 1000);
+    }
+
+    public static String randomPositiveTimeValue() {
+        return randomTimeValue(1, 1000);
     }
 
     /**