changeset 5886:4dd29128bc9b it2-bootstrap

Bugfixes in test framework
author briangoetz
date Fri, 31 Aug 2012 22:42:01 -0400
parents e636b11d547a
children ba24de9416e3
files src/share/classes/java/lang/invoke/SerializedLambda.java test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlatMapOpTest.java test-ng/tests/org/openjdk/tests/java/util/streams/ops/MapOpTest.java test-ng/tests/org/openjdk/tests/java/util/streams/ops/MatchOpTest.java test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java
diffstat 6 files changed, 67 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/SerializedLambda.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/src/share/classes/java/lang/invoke/SerializedLambda.java	Fri Aug 31 22:42:01 2012 -0400
@@ -59,11 +59,52 @@
         this.capturedArgs = capturedArgs.clone();
     }
 
+    public String getCapturingClass() {
+        return capturingClass;
+    }
+
+    public String getFunctionalInterfaceClass() {
+        return functionalInterfaceClass;
+    }
+
+    public String getFunctionalInterfaceMethodName() {
+        return functionalInterfaceMethodName;
+    }
+
+    public String getFunctionalInterfaceMethodSignature() {
+        return functionalInterfaceMethodSignature;
+    }
+
+    public int getFunctionalInterfaceMethodKind() {
+        return functionalInterfaceMethodKind;
+    }
+
+    public String getImplClass() {
+        return implClass;
+    }
+
+    public String getImplMethodName() {
+        return implMethodName;
+    }
+
+    public String getImplMethodSignature() {
+        return implMethodSignature;
+    }
+
+    public int getImplMethodKind() {
+        return implMethodKind;
+    }
+
+    public Object[] getCapturedArgs() {
+        return capturedArgs;
+    }
+
     private Object readResolve() {
-        // @@@ 
+        // @@@
         //  - load the capturing class
         //  - pass 'this' to $deserialize$, using some privileged magic
         //  - return whatever that returns
+        return this;
     }
 
     private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
--- a/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/LambdaTestHelpers.java	Fri Aug 31 22:42:01 2012 -0400
@@ -204,18 +204,6 @@
         assertContents(pi, Arrays.asList(values).iterator());
     }
 
-    static<T extends Comparable<? super T>> void assertContentsUnordered(Iterable<T> it, Iterable<T> list) {
-        ArrayList<T> one = new ArrayList<>();
-        for (T t : it)
-            one.add(t);
-        ArrayList<T> two = new ArrayList<>();
-        for (T t : list)
-            two.add(t);
-        Collections.sort(one);
-        Collections.sort(two);
-        assertContents(one, two);
-    }
-
     static <T> void assertSplitContents(Iterable<Iterable<T>> splits, Iterable<T> list) {
         Iterator<Iterable<T>> mI = splits.iterator();
         Iterator<T> pI = null;
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlatMapOpTest.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/FlatMapOpTest.java	Fri Aug 31 22:42:01 2012 -0400
@@ -78,6 +78,9 @@
         result = exerciseOps(data, new FlatMapOp<>(mfNull));
         assertEquals(0, result.size());
 
+        result = exerciseOps(data, new FlatMapOp<>(mfId));
+        assertEquals(result.size(), data.size());
+
         exerciseOps(data, new FlatMapOp<>(mfLt));
         exerciseOps(data, new FlatMapOp<>(mfIntToBits));
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MapOpTest.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MapOpTest.java	Fri Aug 31 22:42:01 2012 -0400
@@ -36,6 +36,7 @@
  *
  * @author Brian Goetz
  */
+@Test
 public class MapOpTest extends StreamOpTestCase {
     public void testRawIterator() {
         assertCountSum(MapOp.iterator(countTo(0).iterator(), mId), 0, 0);
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MatchOpTest.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/MatchOpTest.java	Fri Aug 31 22:42:01 2012 -0400
@@ -44,10 +44,11 @@
  *
  * @author Brian Goetz
  */
+@Test
 public class MatchOpTest extends StreamOpTestCase {
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({ "unchecked", "raw" })
     private static final Predicate<Integer>[] INTEGER_PREDICATES
-            = (Predicate<Integer>[]) new Predicate[] { pTrue, pFalse, pEven, pOdd };
+            = (Predicate<Integer>[]) new Predicate<?>[] { pTrue, pFalse, pEven, pOdd };
 
     private enum MatchKind {
         ANY {
--- a/test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java	Fri Aug 31 18:42:14 2012 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/streams/ops/StreamOpTestCase.java	Fri Aug 31 22:42:01 2012 -0400
@@ -52,6 +52,7 @@
         assertEquals(refResult, newResult);
     }
 
+    @SuppressWarnings({ "raw", "unchecked" })
     protected static <T, U> StreamResult<U> exerciseOps(TestData<T> data,
                                                         IntermediateOp<T, U> op) {
         StreamResult<U> refResult = exerciseOps(data, new IntermediateOp[] { op });
@@ -68,6 +69,7 @@
         return refResult;
     }
 
+    @SuppressWarnings({ "raw", "unchecked" })
     protected static <T, U> StreamResult<U> exerciseOps(TestData<T> data,
                                                         IntermediateOp... ops) {
         StreamResult<U> refResult = new StreamResult<>(data.size());
@@ -133,6 +135,7 @@
         return exerciseOps(data, (u, v) -> u.equals(v), terminal, ops);
     }
 
+    @SuppressWarnings({ "raw", "unchecked" })
     protected static <T, U> U exerciseOps(TestData<T> data,
                                           BiPredicate<U, U> equalator,
                                           TerminalOp<T, U> terminalOp,
@@ -145,27 +148,29 @@
         }
         else {
             // First pass -- create a sink and evaluate, with no size advice
-            StatefulSink<T, U> sink = terminalOp.sink();
+            StatefulSink<T, U> terminalSink = terminalOp.sink();
+            Sink<T, ?, ?> sink = sink(terminalSink, ops);
             sink.begin(-1);
             data.forEach(sink);
             sink.end();
-            answer = sink.getAndClearState();
+            answer = terminalSink.getAndClearState();
 
             // Create a sink and evaluate, with size advice
-            StatefulSink<T, U> sink2 = terminalOp.sink();
+            StatefulSink<T, U> terminalSink2 = terminalOp.sink();
+            Sink<T, ?, ?> sink2 = sink(terminalSink2, ops);
             sink2.begin(data.size());
             data.forEach(sink2);
             sink2.end();
-            U answer2 = sink2.getAndClearState();
+            U answer2 = terminalSink2.getAndClearState();
             assertTrue(equalator.test(answer, answer2));
         }
 
         // Third pass -- wrap with SequentialPipeline.op
-        U answer3 = data.seq(terminalOp);
+        U answer3 = data.seq(terminalOp, ops);
         assertTrue(equalator.test(answer, answer3));
 
         // Fourth pass -- wrap with ParallelPipeline.op
-        U answer4 = data.par(terminalOp);
+        U answer4 = data.par(terminalOp, ops);
         assertTrue(equalator.test(answer, answer4));
 
         return answer;
@@ -190,7 +195,7 @@
 
     static class StreamResult<T> implements Sink.OfLinear<T>, Traversable<T>, Sized {
 
-        private Object[] array;
+        private T[] array;
 
         private int offset;
 
@@ -206,18 +211,16 @@
         @Override
         public void forEach(Block<? super T> block) {
             for (int i = 0; i < offset; i++) {
-                block.apply((T) array[i]);
+                block.apply(array[i]);
             }
         }
 
         @Override
-        @SuppressWarnings("unchecked")
         public Iterator<T> iterator() {
-            return (Iterator<T>) Arrays.iterator(array, 0, offset);
+            return Arrays.iterator(array, 0, offset);
         }
 
         @Override
-        @SuppressWarnings("unchecked")
         public void accept(T t) {
             if (offset == array.length) {
                 array = Arrays.copyOf(array, Math.max(array.length, 1) * 2);
@@ -240,7 +243,6 @@
         }
     }
 
-    @SuppressWarnings({ "raw", "unchecked" })
     private static class DummyParallelOpHelper<T> implements ParallelOp.ParallelOpHelper<T,T> {
         private final TestData<T> data;
 
@@ -254,22 +256,23 @@
         }
 
         @Override
-        public Spliterator spliterator() {
+        public Spliterator<T> spliterator() {
             return data.spliterator();
         }
 
         @Override
+        @SuppressWarnings({ "raw", "unchecked" })
         public Sink<T, ?, ?> sink(Sink sink) {
             return sink;
         }
 
         @Override
-        public Iterator iterator() {
+        public Iterator<T> iterator() {
             return data.iterator();
         }
 
         @Override
-        public Object invoke(ForkJoinTask task) {
+        public<Z> Z invoke(ForkJoinTask<Z> task) {
             return ForkJoinUtils.defaultFJPool().invoke(task);
         }
     }