summaryrefslogtreecommitdiff
path: root/jsr166-tests/src/test/java/jsr166/Collection8Test.java
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2016-03-16 13:29:15 +0000
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>2016-03-18 12:45:22 +0000
commitff18b5f136f92154f2e05217e3953d10f459e561 (patch)
tree498a25b4362ab9b966a7e4f1021c5eae3e60db71 /jsr166-tests/src/test/java/jsr166/Collection8Test.java
parent96086fd89b7abf2267055badfc3b65ddba6376f5 (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/Collection8Test.java')
-rw-r--r--jsr166-tests/src/test/java/jsr166/Collection8Test.java101
1 files changed, 50 insertions, 51 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/Collection8Test.java b/jsr166-tests/src/test/java/jsr166/Collection8Test.java
index 634182b967..0204ce666c 100644
--- a/jsr166-tests/src/test/java/jsr166/Collection8Test.java
+++ b/jsr166-tests/src/test/java/jsr166/Collection8Test.java
@@ -44,61 +44,60 @@ public class Collection8Test extends JSR166TestCase {
/**
* stream().forEach returns elements in the collection
*/
- // TODO(streams):
- // public void testForEach() throws Throwable {
- // final Collection c = impl.emptyCollection();
- // final AtomicLong count = new AtomicLong(0L);
- // final Object x = impl.makeElement(1);
- // final Object y = impl.makeElement(2);
- // final ArrayList found = new ArrayList();
- // Consumer<Object> spy = (o) -> { found.add(o); };
- // c.stream().forEach(spy);
- // assertTrue(found.isEmpty());
+ public void testForEach() throws Throwable {
+ final Collection c = impl.emptyCollection();
+ final AtomicLong count = new AtomicLong(0L);
+ final Object x = impl.makeElement(1);
+ final Object y = impl.makeElement(2);
+ final ArrayList found = new ArrayList();
+ Consumer<Object> spy = (o) -> { found.add(o); };
+ c.stream().forEach(spy);
+ assertTrue(found.isEmpty());
- // assertTrue(c.add(x));
- // c.stream().forEach(spy);
- // assertEquals(Collections.singletonList(x), found);
- // found.clear();
+ assertTrue(c.add(x));
+ c.stream().forEach(spy);
+ assertEquals(Collections.singletonList(x), found);
+ found.clear();
- // assertTrue(c.add(y));
- // c.stream().forEach(spy);
- // assertEquals(2, found.size());
- // assertTrue(found.contains(x));
- // assertTrue(found.contains(y));
- // found.clear();
+ assertTrue(c.add(y));
+ c.stream().forEach(spy);
+ assertEquals(2, found.size());
+ assertTrue(found.contains(x));
+ assertTrue(found.contains(y));
+ found.clear();
- // c.clear();
- // c.stream().forEach(spy);
- // assertTrue(found.isEmpty());
- // }
+ c.clear();
+ c.stream().forEach(spy);
+ assertTrue(found.isEmpty());
+ }
- // public void testForEachConcurrentStressTest() throws Throwable {
- // if (!impl.isConcurrent()) return;
- // final Collection c = impl.emptyCollection();
- // final long testDurationMillis = timeoutMillis();
- // final AtomicBoolean done = new AtomicBoolean(false);
- // final Object elt = impl.makeElement(1);
- // final Future<?> f1, f2;
- // final ExecutorService pool = Executors.newCachedThreadPool();
- // try (PoolCleaner cleaner = cleaner(pool, done)) {
- // final CountDownLatch threadsStarted = new CountDownLatch(2);
- // Runnable checkElt = () -> {
- // threadsStarted.countDown();
- // while (!done.get())
- // c.stream().forEach((x) -> { assertSame(x, elt); }); };
- // Runnable addRemove = () -> {
- // threadsStarted.countDown();
- // while (!done.get()) {
- // assertTrue(c.add(elt));
- // assertTrue(c.remove(elt));
- // }};
- // f1 = pool.submit(checkElt);
- // f2 = pool.submit(addRemove);
- // Thread.sleep(testDurationMillis);
- // }
- // assertNull(f1.get(0L, MILLISECONDS));
- // assertNull(f2.get(0L, MILLISECONDS));
- // }
+ public void testForEachConcurrentStressTest() throws Throwable {
+ if (!impl.isConcurrent()) return;
+ final Collection c = impl.emptyCollection();
+ final long testDurationMillis = timeoutMillis();
+ final AtomicBoolean done = new AtomicBoolean(false);
+ final Object elt = impl.makeElement(1);
+ final Future<?> f1, f2;
+ final ExecutorService pool = Executors.newCachedThreadPool();
+ try (PoolCleaner cleaner = cleaner(pool, done)) {
+ final CountDownLatch threadsStarted = new CountDownLatch(2);
+ Runnable checkElt = () -> {
+ threadsStarted.countDown();
+ while (!done.get())
+ c.stream().forEach((x) -> { assertSame(x, elt); }); };
+ Runnable addRemove = () -> {
+ threadsStarted.countDown();
+ while (!done.get()) {
+ assertTrue(c.add(elt));
+ assertTrue(c.remove(elt));
+ }};
+ f1 = pool.submit(checkElt);
+ f2 = pool.submit(addRemove);
+ Thread.sleep(testDurationMillis);
+ }
+ assertNull(f1.get(0L, MILLISECONDS));
+ assertNull(f2.get(0L, MILLISECONDS));
+ }
// public void testCollection8DebugFail() { fail(); }
}