diff options
author | Igor Murashkin <iam@google.com> | 2016-03-16 13:29:15 +0000 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-18 12:45:22 +0000 |
commit | ff18b5f136f92154f2e05217e3953d10f459e561 (patch) | |
tree | 498a25b4362ab9b966a7e4f1021c5eae3e60db71 /jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java | |
parent | 96086fd89b7abf2267055badfc3b65ddba6376f5 (diff) |
Add openJdk8 java.util.stream package
Based on openJdk 8u60 source & iam@ stream prototype in
ag/872080
Uncommented all code that was waiting for java.util.stream
to show up
Differences from original sources:
- Removed unsignedDivision usage from LongStream, it's not currently
supported and we don't expect that large workloads on mobile devices.
- Removed java.nio.file references.
- Removed (yet) not implemented stream-related methods from
other packages listed in package-info.java.
Bug: 27692239
Change-Id: Ie24e60e8248367b576ef91046837ccde152de373
(cherry picked from commit d0a2645e29a9b84d7e5ec822eb9904e93bd6c013)
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java | 124 |
1 files changed, 61 insertions, 63 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java b/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java index 1372cc48dd..37bc285605 100644 --- a/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java +++ b/jsr166-tests/src/test/java/jsr166/CompletableFutureTest.java @@ -15,9 +15,8 @@ import static java.util.concurrent.CompletableFuture.failedFuture; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -// TODO(streams): -//import java.util.stream.Collectors; -//import java.util.stream.Stream; +import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.ArrayList; import java.util.Arrays; @@ -3725,66 +3724,65 @@ public class CompletableFutureTest extends JSR166TestCase { /** * Minimal completion stages throw UOE for all non-CompletionStage methods */ - // TODO(streams): - // public void testMinimalCompletionStage_minimality() { - // if (!testImplementationDetails) return; - // Function<Method, String> toSignature = - // (method) -> method.getName() + Arrays.toString(method.getParameterTypes()); - // Predicate<Method> isNotStatic = - // (method) -> (method.getModifiers() & Modifier.STATIC) == 0; - // List<Method> minimalMethods = - // Stream.of(Object.class, CompletionStage.class) - // .flatMap((klazz) -> Stream.of(klazz.getMethods())) - // .filter(isNotStatic) - // .collect(Collectors.toList()); - // // Methods from CompletableFuture permitted NOT to throw UOE - // String[] signatureWhitelist = { - // "newIncompleteFuture[]", - // "defaultExecutor[]", - // "minimalCompletionStage[]", - // "copy[]", - // }; - // Set<String> permittedMethodSignatures = - // Stream.concat(minimalMethods.stream().map(toSignature), - // Stream.of(signatureWhitelist)) - // .collect(Collectors.toSet()); - // List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods()) - // .filter(isNotStatic) - // .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method))) - // .collect(Collectors.toList()); - - // CompletionStage<Integer> minimalStage = - // new CompletableFuture<Integer>().minimalCompletionStage(); - - // List<Method> bugs = new ArrayList<>(); - // for (Method method : allMethods) { - // Class<?>[] parameterTypes = method.getParameterTypes(); - // Object[] args = new Object[parameterTypes.length]; - // // Manufacture boxed primitives for primitive params - // for (int i = 0; i < args.length; i++) { - // Class<?> type = parameterTypes[i]; - // if (parameterTypes[i] == boolean.class) - // args[i] = false; - // else if (parameterTypes[i] == int.class) - // args[i] = 0; - // else if (parameterTypes[i] == long.class) - // args[i] = 0L; - // } - // try { - // method.invoke(minimalStage, args); - // bugs.add(method); - // } - // catch (java.lang.reflect.InvocationTargetException expected) { - // if (! (expected.getCause() instanceof UnsupportedOperationException)) { - // bugs.add(method); - // // expected.getCause().printStackTrace(); - // } - // } - // catch (ReflectiveOperationException bad) { throw new Error(bad); } - // } - // if (!bugs.isEmpty()) - // throw new Error("Methods did not throw UOE: " + bugs.toString()); - // } + public void testMinimalCompletionStage_minimality() { + if (!testImplementationDetails) return; + Function<Method, String> toSignature = + (method) -> method.getName() + Arrays.toString(method.getParameterTypes()); + Predicate<Method> isNotStatic = + (method) -> (method.getModifiers() & Modifier.STATIC) == 0; + List<Method> minimalMethods = + Stream.of(Object.class, CompletionStage.class) + .flatMap((klazz) -> Stream.of(klazz.getMethods())) + .filter(isNotStatic) + .collect(Collectors.toList()); + // Methods from CompletableFuture permitted NOT to throw UOE + String[] signatureWhitelist = { + "newIncompleteFuture[]", + "defaultExecutor[]", + "minimalCompletionStage[]", + "copy[]", + }; + Set<String> permittedMethodSignatures = + Stream.concat(minimalMethods.stream().map(toSignature), + Stream.of(signatureWhitelist)) + .collect(Collectors.toSet()); + List<Method> allMethods = Stream.of(CompletableFuture.class.getMethods()) + .filter(isNotStatic) + .filter((method) -> !permittedMethodSignatures.contains(toSignature.apply(method))) + .collect(Collectors.toList()); + + CompletionStage<Integer> minimalStage = + new CompletableFuture<Integer>().minimalCompletionStage(); + + List<Method> bugs = new ArrayList<>(); + for (Method method : allMethods) { + Class<?>[] parameterTypes = method.getParameterTypes(); + Object[] args = new Object[parameterTypes.length]; + // Manufacture boxed primitives for primitive params + for (int i = 0; i < args.length; i++) { + Class<?> type = parameterTypes[i]; + if (parameterTypes[i] == boolean.class) + args[i] = false; + else if (parameterTypes[i] == int.class) + args[i] = 0; + else if (parameterTypes[i] == long.class) + args[i] = 0L; + } + try { + method.invoke(minimalStage, args); + bugs.add(method); + } + catch (java.lang.reflect.InvocationTargetException expected) { + if (! (expected.getCause() instanceof UnsupportedOperationException)) { + bugs.add(method); + // expected.getCause().printStackTrace(); + } + } + catch (ReflectiveOperationException bad) { throw new Error(bad); } + } + if (!bugs.isEmpty()) + throw new Error("Methods did not throw UOE: " + bugs.toString()); + } static class Monad { static class ZeroException extends RuntimeException { |