From fe6f3e2439db3d75d114c98cf661e8ecb32824fc Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Tue, 5 Nov 2013 12:08:12 +0100 Subject: [PATCH] 8027712: DistinctOpTest fails for unordered test Reviewed-by: henryjen, alanb --- .../openjdk/tests/java/util/stream/DistinctOpTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java index 7d26925a1f2..69432cfedf6 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java @@ -54,10 +54,14 @@ public class DistinctOpTest extends OpTestCase { // These tests should short-circuit, otherwise will fail with a time-out // or an OOME - Integer one = Stream.iterate(1, i -> i + 1).unordered().parallel().distinct().findAny().get(); - assertEquals(one.intValue(), 1); + // Note that since the streams are unordered and any element is requested + // (a non-deterministic process) the only assertion that can be made is + // that an element should be found - Optional oi = ThreadLocalRandom.current().ints().boxed().parallel().distinct().findAny(); + Optional oi = Stream.iterate(1, i -> i + 1).unordered().parallel().distinct().findAny(); + assertTrue(oi.isPresent()); + + oi = ThreadLocalRandom.current().ints().boxed().parallel().distinct().findAny(); assertTrue(oi.isPresent()); }