diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-11 15:59:10 +0000 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2016-03-15 11:14:14 +0000 |
commit | e8b323c7cb7d55be9a4df579231e44f04f53d766 (patch) | |
tree | c40a0cadb5caa371c28b117b017daddef4b72c28 /jsr166-tests/src/test/java/jsr166/Collection8Test.java | |
parent | 0eedcb21289c1916e876810982c2c8d473edf24f (diff) |
JSR-166 update without java 1.9 method/classes
Second attempt, in frist one I've submitted some code from openJdk 1.9
that shouldn't be here, orignial change can be found at
5328e07d282bef36ac8b757bbee16a761415b2c4
Adapted from sources taken from CVS using:
cvs -d ':pserver:anonymous@gee.cs.oswego.edu/home/jsr166/jsr166' checkout -D "03/03/2016 10:00:00 GMT" jsr166
This time with hidden/removed "@since 9" methods and classes
Bug: 27426599
Change-Id: Ibd8d26e13cba091bfd983c73d005e4f8d8f5946d
(cherry picked from commit b8b75116273ecfdb8ffdd1869b1c0dd04570a95e)
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/Collection8Test.java')
-rw-r--r-- | jsr166-tests/src/test/java/jsr166/Collection8Test.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/Collection8Test.java b/jsr166-tests/src/test/java/jsr166/Collection8Test.java new file mode 100644 index 0000000000..634182b967 --- /dev/null +++ b/jsr166-tests/src/test/java/jsr166/Collection8Test.java @@ -0,0 +1,104 @@ +/* + * Written by Doug Lea and Martin Buchholz with assistance from + * members of JCP JSR-166 Expert Group and released to the public + * domain, as explained at + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +package jsr166; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Consumer; + +import junit.framework.Test; + +/** + * Contains tests applicable to all jdk8+ Collection implementations. + * An extension of CollectionTest. + */ +public class Collection8Test extends JSR166TestCase { + final CollectionImplementation impl; + + /** Tests are parameterized by a Collection implementation. */ + Collection8Test(CollectionImplementation impl, String methodName) { + super(methodName); + this.impl = impl; + } + + public static Test testSuite(CollectionImplementation impl) { + return parameterizedTestSuite(Collection8Test.class, + CollectionImplementation.class, + impl); + } + + /** + * 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()); + + // 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(); + + // 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 testCollection8DebugFail() { fail(); } +} |