Skip to content

Commit 7f7cf30

Browse files
authored
Expose a couple of primitive stream wrappers over the underlying test random instance (elastic#93479)
Expose a couple of primitive stream wrappers over the underlying test random instance. These are not yet used, but are useful in many circumstances.
1 parent f2b02ae commit 7f7cf30

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
import java.util.function.Predicate;
161161
import java.util.function.Supplier;
162162
import java.util.stream.Collectors;
163+
import java.util.stream.DoubleStream;
164+
import java.util.stream.IntStream;
165+
import java.util.stream.LongStream;
163166
import java.util.stream.Stream;
164167

165168
import static java.util.Collections.emptyMap;
@@ -804,6 +807,14 @@ public static int randomInt() {
804807
return random().nextInt();
805808
}
806809

810+
public static IntStream randomInts() {
811+
return random().ints();
812+
}
813+
814+
public static IntStream randomInts(long streamSize) {
815+
return random().ints(streamSize);
816+
}
817+
807818
/**
808819
* @return a <code>long</code> between <code>0</code> and <code>Long.MAX_VALUE</code> (inclusive) chosen uniformly at random.
809820
*/
@@ -820,6 +831,14 @@ public static double randomDouble() {
820831
return random().nextDouble();
821832
}
822833

834+
public static DoubleStream randomDoubles() {
835+
return random().doubles();
836+
}
837+
838+
public static DoubleStream randomDoubles(long streamSize) {
839+
return random().doubles(streamSize);
840+
}
841+
823842
/**
824843
* Returns a double value in the interval [start, end) if lowerInclusive is
825844
* set to true, (start, end) otherwise.
@@ -853,6 +872,14 @@ public static long randomLong() {
853872
return random().nextLong();
854873
}
855874

875+
public static LongStream randomLongs() {
876+
return random().longs();
877+
}
878+
879+
public static LongStream randomLongs(long streamSize) {
880+
return random().longs(streamSize);
881+
}
882+
856883
/**
857884
* Returns a random BigInteger uniformly distributed over the range 0 to (2^64 - 1) inclusive
858885
* Currently BigIntegers are only used for unsigned_long field type, where the max value is 2^64 - 1.

0 commit comments

Comments
 (0)