8134459: java/util/stream/test/org/openjdk/tests/java/util/stream/WhileOpTest.java timed out
authorredestad
Wed, 10 Jan 2018 00:08:46 +0100
changeset 48453 37d2147852fc
parent 48452 d3b1fc1bda9c
child 48454 50cd89fe209f
8134459: java/util/stream/test/org/openjdk/tests/java/util/stream/WhileOpTest.java timed out Reviewed-by: psandoz, rriggs
test/jdk/java/util/stream/test/org/openjdk/tests/java/util/stream/WhileOpTest.java
test/jdk/lib/testlibrary/bootlib/java.base/java/util/stream/LambdaTestHelpers.java
--- a/test/jdk/java/util/stream/test/org/openjdk/tests/java/util/stream/WhileOpTest.java	Wed Jan 03 13:17:35 2018 -0800
+++ b/test/jdk/java/util/stream/test/org/openjdk/tests/java/util/stream/WhileOpTest.java	Wed Jan 10 00:08:46 2018 +0100
@@ -47,6 +47,7 @@
 /*
  * @test
  * @bug 8071597 8193856
+ * @run main/timeout=240
  */
 @Test
 public class WhileOpTest extends OpTestCase {
--- a/test/jdk/lib/testlibrary/bootlib/java.base/java/util/stream/LambdaTestHelpers.java	Wed Jan 03 13:17:35 2018 -0800
+++ b/test/jdk/lib/testlibrary/bootlib/java.base/java/util/stream/LambdaTestHelpers.java	Wed Jan 10 00:08:46 2018 +0100
@@ -48,6 +48,7 @@
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
 
 /**
  * LambdaTestHelpers -- assertion methods and useful objects for lambda test cases
@@ -277,7 +278,7 @@
 
     public static<T> void assertContents(Iterable<T> actual, Iterable<T> expected) {
         if (actual instanceof Collection && expected instanceof Collection) {
-            assertEquals(actual, expected);
+            assertIterableEquals(actual, expected);
         } else {
             assertContents(actual.iterator(), expected.iterator());
         }
@@ -287,6 +288,42 @@
         assertEquals(toBoxedList(actual), toBoxedList(expected));
     }
 
+    // Workaround excessive String creation in inner loop in org.testng.Assert.assertEquals(Iterable<?>, Iterable<?>)
+    static public void assertIterableEquals(Iterable<?> actual, Iterable<?> expected) {
+        if(actual == expected) {
+            return;
+        }
+
+        if(actual == null || expected == null) {
+            fail("Iterables not equal: expected: " + expected + " and actual: " + actual);
+        }
+
+        assertIteratorsEquals(actual.iterator(), expected.iterator());
+    }
+
+    // Workaround excessive String creation in inner loop in org.testng.Assert.assertEquals(Iterator<?>, Iterator<?>)
+    static public void assertIteratorsEquals(Iterator<?> actual, Iterator<?> expected) {
+        if (actual == expected) {
+            return;
+        }
+
+        if (actual == null || expected == null) {
+            fail("Iterators not equal: expected: " + expected + " and actual: " + actual);
+        }
+
+        while (actual.hasNext() && expected.hasNext()) {
+            Object e = expected.next();
+            Object a = actual.next();
+            assertEquals(a, e, "Iterator contents differ");
+        }
+
+        if(actual.hasNext()) {
+            fail("Actual iterator returned more elements than the expected iterator.");
+        } else if(expected.hasNext()) {
+            fail("Expected iterator returned more elements than the actual iterator.");
+        }
+    }
+
     @SafeVarargs
     @SuppressWarnings("varargs")
     public static<T> void assertContents(Iterator<T> actual, T... expected) {