8176543: Miscellaneous changes imported from jsr166 CVS 2017-04

Reviewed-by: martin, psandoz
This commit is contained in:
Doug Lea 2017-04-10 13:46:19 -07:00
parent 05b72d87e7
commit b3ea0dd629
48 changed files with 128 additions and 149 deletions

View File

@ -48,7 +48,6 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.NoSuchElementException;
import java.util.Set;

View File

@ -43,7 +43,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;

View File

@ -2354,7 +2354,7 @@ public class ForkJoinPool extends AbstractExecutorService {
checkPermission();
}
private Object newInstanceFromSystemProperty(String property)
private static Object newInstanceFromSystemProperty(String property)
throws ReflectiveOperationException {
String className = System.getProperty(property);
return (className == null)
@ -2524,15 +2524,13 @@ public class ForkJoinPool extends AbstractExecutorService {
* @throws RejectedExecutionException if the task cannot be
* scheduled for execution
*/
@SuppressWarnings("unchecked")
public ForkJoinTask<?> submit(Runnable task) {
if (task == null)
throw new NullPointerException();
ForkJoinTask<?> job;
if (task instanceof ForkJoinTask<?>) // avoid re-wrap
job = (ForkJoinTask<?>) task;
else
job = new ForkJoinTask.AdaptedRunnableAction(task);
return externalSubmit(job);
return externalSubmit((task instanceof ForkJoinTask<?>)
? (ForkJoinTask<Void>) task // avoid re-wrap
: new ForkJoinTask.AdaptedRunnableAction(task));
}
/**

View File

@ -203,21 +203,19 @@ public class ForkJoinWorkerThread extends Thread {
static final class InnocuousForkJoinWorkerThread extends ForkJoinWorkerThread {
/** The ThreadGroup for all InnocuousForkJoinWorkerThreads */
private static final ThreadGroup innocuousThreadGroup =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public ThreadGroup run() {
ThreadGroup group = Thread.currentThread().getThreadGroup();
for (ThreadGroup p; (p = group.getParent()) != null; )
group = p;
return new ThreadGroup(group, "InnocuousForkJoinWorkerThreadGroup");
}});
AccessController.doPrivileged(new PrivilegedAction<>() {
public ThreadGroup run() {
ThreadGroup group = Thread.currentThread().getThreadGroup();
for (ThreadGroup p; (p = group.getParent()) != null; )
group = p;
return new ThreadGroup(
group, "InnocuousForkJoinWorkerThreadGroup");
}});
/** An AccessControlContext supporting no privileges */
private static final AccessControlContext INNOCUOUS_ACC =
new AccessControlContext(
new ProtectionDomain[] {
new ProtectionDomain(null, null)
});
new ProtectionDomain[] { new ProtectionDomain(null, null) });
InnocuousForkJoinWorkerThread(ForkJoinPool pool) {
super(pool,

View File

@ -444,7 +444,7 @@ public class ReentrantReadWriteLock
}
}
private IllegalMonitorStateException unmatchedUnlockException() {
private static IllegalMonitorStateException unmatchedUnlockException() {
return new IllegalMonitorStateException(
"attempt to unlock read lock, not locked by current thread");
}

View File

@ -37,7 +37,6 @@ import java.util.Collections;
import java.util.Spliterator;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ArrayDeque8Test extends JSR166TestCase {
public static void main(String[] args) {

View File

@ -35,7 +35,6 @@
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
@ -44,7 +43,6 @@ import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ArrayDequeTest extends JSR166TestCase {
public static void main(String[] args) {

View File

@ -33,11 +33,9 @@
*/
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ArrayListTest extends JSR166TestCase {
public static void main(String[] args) {

View File

@ -75,7 +75,7 @@ public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase {
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
assertFalse(seven == a.get(this));
assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}
@ -208,7 +208,7 @@ public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase {
assertTrue(a.compareAndSet(this, two, m4));
assertSame(m4, a.get(this));
assertFalse(a.compareAndSet(this, m5, seven));
assertFalse(seven == a.get(this));
assertNotSame(seven, a.get(this));
assertTrue(a.compareAndSet(this, m4, seven));
assertSame(seven, a.get(this));
}

View File

@ -153,7 +153,7 @@ public class AtomicReferenceTest extends JSR166TestCase {
AtomicReference z = serialClone(x);
assertNotSame(y, z);
assertEquals(one, x.get());
assertEquals(null, y.get());
assertNull(y.get());
assertEquals(one, z.get());
}

View File

@ -2589,28 +2589,28 @@ public class CompletableFutureTest extends JSR166TestCase {
// unspecified behavior - both source completions available
try {
assertEquals(null, h0.join());
assertNull(h0.join());
rs[0].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
assertEquals(null, h1.join());
assertNull(h1.join());
rs[1].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
assertEquals(null, h2.join());
assertNull(h2.join());
rs[2].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
assertEquals(null, h3.join());
assertNull(h3.join());
rs[3].assertValue(v1);
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);
@ -2849,28 +2849,28 @@ public class CompletableFutureTest extends JSR166TestCase {
// unspecified behavior - both source completions available
try {
assertEquals(null, h0.join());
assertNull(h0.join());
rs[0].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h0, ex);
rs[0].assertNotInvoked();
}
try {
assertEquals(null, h1.join());
assertNull(h1.join());
rs[1].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h1, ex);
rs[1].assertNotInvoked();
}
try {
assertEquals(null, h2.join());
assertNull(h2.join());
rs[2].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h2, ex);
rs[2].assertNotInvoked();
}
try {
assertEquals(null, h3.join());
assertNull(h3.join());
rs[3].assertInvoked();
} catch (CompletionException ok) {
checkCompletedWithWrappedException(h3, ex);

View File

@ -237,8 +237,8 @@ public class ConcurrentHashMap8Test extends JSR166TestCase {
Set set1 = map.keySet();
Set set2 = map.keySet(true);
set2.add(six);
assertTrue(((ConcurrentHashMap.KeySetView)set2).getMap() == map);
assertTrue(((ConcurrentHashMap.KeySetView)set1).getMap() == map);
assertSame(map, ((ConcurrentHashMap.KeySetView)set2).getMap());
assertSame(map, ((ConcurrentHashMap.KeySetView)set1).getMap());
assertEquals(set2.size(), map.size());
assertEquals(set1.size(), map.size());
assertTrue((Boolean)map.get(six));
@ -332,10 +332,10 @@ public class ConcurrentHashMap8Test extends JSR166TestCase {
assertFalse(set.add(one));
assertTrue(set.add(six));
assertTrue(set.add(seven));
assertTrue(set.getMappedValue() == one);
assertTrue(map.get(one) != one);
assertTrue(map.get(six) == one);
assertTrue(map.get(seven) == one);
assertSame(one, set.getMappedValue());
assertNotSame(one, map.get(one));
assertSame(one, map.get(six));
assertSame(one, map.get(seven));
}
void checkSpliteratorCharacteristics(Spliterator<?> sp,

View File

@ -43,8 +43,6 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import junit.framework.Test;
import junit.framework.TestSuite;
@ -148,7 +146,7 @@ public class ConcurrentHashMapTest extends JSR166TestCase {
ConcurrentHashMap<BI, Boolean> m =
new ConcurrentHashMap<BI, Boolean>();
for (int i = 0; i < size; i++) {
assertTrue(m.put(new CI(i), true) == null);
assertNull(m.put(new CI(i), true));
}
for (int i = 0; i < size; i++) {
assertTrue(m.containsKey(new CI(i)));
@ -169,7 +167,7 @@ public class ConcurrentHashMapTest extends JSR166TestCase {
BS bs = new BS(String.valueOf(i));
LexicographicList<BI> bis = new LexicographicList<BI>(bi);
LexicographicList<BS> bss = new LexicographicList<BS>(bs);
assertTrue(m.putIfAbsent(bis, true) == null);
assertNull(m.putIfAbsent(bis, true));
assertTrue(m.containsKey(bis));
if (m.putIfAbsent(bss, true) == null)
assertTrue(m.containsKey(bss));

View File

@ -43,7 +43,6 @@ import java.util.Random;
import java.util.concurrent.ConcurrentLinkedDeque;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ConcurrentLinkedDequeTest extends JSR166TestCase {
@ -67,7 +66,7 @@ public class ConcurrentLinkedDequeTest extends JSR166TestCase {
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
private ConcurrentLinkedDeque<Integer> populatedDeque(int n) {
private static ConcurrentLinkedDeque<Integer> populatedDeque(int n) {
ConcurrentLinkedDeque<Integer> q = new ConcurrentLinkedDeque<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)

View File

@ -41,7 +41,6 @@ import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import junit.framework.Test;
import junit.framework.TestSuite;
public class ConcurrentLinkedQueueTest extends JSR166TestCase {
@ -65,7 +64,7 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase {
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
private static ConcurrentLinkedQueue<Integer> populatedQueue(int n) {
ConcurrentLinkedQueue<Integer> q = new ConcurrentLinkedQueue<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)

View File

@ -64,7 +64,7 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
private ConcurrentSkipListSet<Integer> populatedSet(int n) {
private static ConcurrentSkipListSet<Integer> populatedSet(int n) {
ConcurrentSkipListSet<Integer> q =
new ConcurrentSkipListSet<Integer>();
assertTrue(q.isEmpty());
@ -80,7 +80,7 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
/**
* Returns a new set of first 5 ints.
*/
private ConcurrentSkipListSet set5() {
private static ConcurrentSkipListSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@ -229,7 +229,7 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
} catch (ClassCastException success) {
assertTrue(q.size() < 2);
for (int i = 0, size = q.size(); i < size; i++)
assertTrue(q.pollFirst().getClass() == Object.class);
assertSame(Object.class, q.pollFirst().getClass());
assertNull(q.pollFirst());
assertTrue(q.isEmpty());
assertEquals(0, q.size());

View File

@ -59,7 +59,7 @@ public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
private NavigableSet<Integer> populatedSet(int n) {
private static NavigableSet<Integer> populatedSet(int n) {
ConcurrentSkipListSet<Integer> q =
new ConcurrentSkipListSet<Integer>();
assertTrue(q.isEmpty());
@ -79,7 +79,7 @@ public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
/**
* Returns a new set of first 5 ints.
*/
private NavigableSet set5() {
private static NavigableSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
@ -97,7 +97,7 @@ public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
/**
* Returns a new set of first 5 negative ints.
*/
private NavigableSet dset5() {
private static NavigableSet dset5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(m1);

View File

@ -44,7 +44,6 @@ import java.util.NoSuchElementException;
import java.util.concurrent.CopyOnWriteArrayList;
import junit.framework.Test;
import junit.framework.TestSuite;
public class CopyOnWriteArrayListTest extends JSR166TestCase {

View File

@ -32,9 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.concurrent.CountedCompleter;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -40,7 +40,6 @@ import java.util.concurrent.CountedCompleter;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

View File

@ -160,12 +160,12 @@ public class ExchangerTest extends JSR166TestCase {
public void realRun() throws InterruptedException {
assertSame(one, e.exchange(two));
exchanged.countDown();
interrupted.await();
await(interrupted);
assertSame(three, e.exchange(one));
}});
Thread t3 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
interrupted.await();
await(interrupted);
assertSame(one, e.exchange(three));
}});

View File

@ -37,7 +37,6 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;

View File

@ -172,7 +172,7 @@ public class ExecutorCompletionServiceTest extends JSR166TestCase {
CompletionService cs = new ExecutorCompletionService(cachedThreadPool);
final CountDownLatch proceed = new CountDownLatch(1);
cs.submit(new Callable() { public String call() throws Exception {
proceed.await();
await(proceed);
return TEST_STRING;
}});
assertNull(cs.poll());

View File

@ -333,16 +333,12 @@ public class ExecutorsTest extends JSR166TestCase {
public void realRun() {
try {
Thread current = Thread.currentThread();
assertTrue(!current.isDaemon());
assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
if (s != null)
assertTrue(g == s.getThreadGroup());
else
assertTrue(g == egroup);
String name = current.getName();
assertTrue(name.endsWith("thread-1"));
assertSame(current.getThreadGroup(),
(s == null) ? egroup : s.getThreadGroup());
assertTrue(current.getName().endsWith("thread-1"));
} catch (SecurityException ok) {
// Also pass if not allowed to change setting
}
@ -370,16 +366,12 @@ public class ExecutorsTest extends JSR166TestCase {
Runnable r = new CheckedRunnable() {
public void realRun() {
Thread current = Thread.currentThread();
assertTrue(!current.isDaemon());
assertFalse(current.isDaemon());
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
ThreadGroup g = current.getThreadGroup();
SecurityManager s = System.getSecurityManager();
if (s != null)
assertTrue(g == s.getThreadGroup());
else
assertTrue(g == egroup);
String name = current.getName();
assertTrue(name.endsWith("thread-1"));
assertSame(current.getThreadGroup(),
(s == null) ? egroup : s.getThreadGroup());
assertTrue(current.getName().endsWith("thread-1"));
assertSame(thisccl, current.getContextClassLoader());
assertEquals(thisacc, AccessController.getContext());
done.countDown();

View File

@ -206,7 +206,7 @@ public class ForkJoinPool8Test extends JSR166TestCase {
public FJException(Throwable cause) { super(cause); }
}
// A simple recursive action for testing
/** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@ -224,7 +224,7 @@ public class ForkJoinPool8Test extends JSR166TestCase {
}
}
// A recursive action failing in base case
/** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;
@ -932,7 +932,7 @@ public class ForkJoinPool8Test extends JSR166TestCase {
}
}
// Version of CCF with forced failure in left completions
/** Version of CCF with forced failure in left completions. */
abstract static class FailingCCF extends CountedCompleter {
int number;
int rnumber;

View File

@ -32,8 +32,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.CountDownLatch;
@ -93,7 +91,7 @@ public class ForkJoinPool9Test extends JSR166TestCase {
Future<?> f = ForkJoinPool.commonPool().submit(runInCommonPool);
// Ensure runInCommonPool is truly running in the common pool,
// by giving this thread no opportunity to "help" on get().
assertTrue(taskStarted.await(LONG_DELAY_MS, MILLISECONDS));
await(taskStarted);
assertNull(f.get());
}

View File

@ -244,7 +244,7 @@ public class ForkJoinPoolTest extends JSR166TestCase {
taskStarted.countDown();
assertEquals(1, p.getPoolSize());
assertEquals(1, p.getActiveThreadCount());
done.await();
await(done);
}};
Future<?> future = p.submit(task);
await(taskStarted);

View File

@ -127,7 +127,8 @@ public class ForkJoinTask8Test extends JSR166TestCase {
assertNull(a.getException());
assertNull(a.getRawResult());
if (a instanceof BinaryAsyncAction)
assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == INITIAL_STATE);
assertEquals(INITIAL_STATE,
((BinaryAsyncAction)a).getForkJoinTaskTag());
try {
a.get(0L, SECONDS);
@ -148,7 +149,8 @@ public class ForkJoinTask8Test extends JSR166TestCase {
assertNull(a.getException());
assertSame(expected, a.getRawResult());
if (a instanceof BinaryAsyncAction)
assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == COMPLETE_STATE);
assertEquals(COMPLETE_STATE,
((BinaryAsyncAction)a).getForkJoinTaskTag());
{
Thread.currentThread().interrupt();

View File

@ -26,8 +26,9 @@
* However, the following notice accompanied the original version of this
* file:
*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* 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/
* Other contributors include Andrew Wright, Jeffrey Hayes,
* Pat Fisher, Mike Judd.
@ -35,32 +36,33 @@
/*
* @test
* @summary JSR-166 tck tests (conformance testing mode)
* @summary JSR-166 tck tests, in a number of variations.
* The first is the conformance testing variant,
* while others also test implementation details.
* @build *
* @modules java.management
* @run junit/othervm/timeout=1000 JSR166TestCase
*/
/*
* @test
* @summary JSR-166 tck tests (whitebox tests allowed)
* @build *
* @modules java.base/java.util.concurrent:open
* java.base/java.lang:open
* java.management
* @run junit/othervm/timeout=1000
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED
* --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
* @run junit/othervm/timeout=1000
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED
* --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=0
* JSR166TestCase
* @run junit/othervm/timeout=1000
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED
* --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1
* -Djava.util.secureRandomSeed=true
* JSR166TestCase
* @run junit/othervm/timeout=1000/policy=tck.policy
* --add-opens java.base/java.util.concurrent=ALL-UNNAMED
* --add-opens java.base/java.lang=ALL-UNNAMED
* -Djsr166.testImplementationDetails=true
* JSR166TestCase
*/
@ -79,8 +81,6 @@ import java.lang.management.ThreadMXBean;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
@ -118,7 +118,6 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.AssertionFailedError;
@ -328,9 +327,11 @@ public class JSR166TestCase extends TestCase {
// public static String cpuModel() {
// try {
// Matcher matcher = Pattern.compile("model name\\s*: (.*)")
// java.util.regex.Matcher matcher
// = Pattern.compile("model name\\s*: (.*)")
// .matcher(new String(
// Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
// java.nio.file.Files.readAllBytes(
// java.nio.file.Paths.get("/proc/cpuinfo")), "UTF-8"));
// matcher.find();
// return matcher.group(1);
// } catch (Exception ex) { return null; }

View File

@ -36,7 +36,6 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.Spliterator;
import junit.framework.Test;
import junit.framework.TestSuite;
public class LinkedBlockingDeque8Test extends JSR166TestCase {
public static void main(String[] args) {

View File

@ -85,7 +85,7 @@ public class LinkedBlockingDequeTest extends JSR166TestCase {
* Returns a new deque of given size containing consecutive
* Integers 0 ... n - 1.
*/
private LinkedBlockingDeque<Integer> populatedDeque(int n) {
private static LinkedBlockingDeque<Integer> populatedDeque(int n) {
LinkedBlockingDeque<Integer> q =
new LinkedBlockingDeque<Integer>(n);
assertTrue(q.isEmpty());
@ -801,7 +801,7 @@ public class LinkedBlockingDequeTest extends JSR166TestCase {
}
}});
aboutToWait.await();
await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);

View File

@ -36,7 +36,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.Spliterator;
import junit.framework.Test;
import junit.framework.TestSuite;
public class LinkedBlockingQueue8Test extends JSR166TestCase {
public static void main(String[] args) {

View File

@ -85,7 +85,7 @@ public class LinkedBlockingQueueTest extends JSR166TestCase {
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
private LinkedBlockingQueue<Integer> populatedQueue(int n) {
private static LinkedBlockingQueue<Integer> populatedQueue(int n) {
LinkedBlockingQueue<Integer> q =
new LinkedBlockingQueue<Integer>(n);
assertTrue(q.isEmpty());

View File

@ -40,7 +40,6 @@ import java.util.LinkedList;
import java.util.NoSuchElementException;
import junit.framework.Test;
import junit.framework.TestSuite;
public class LinkedListTest extends JSR166TestCase {
public static void main(String[] args) {
@ -70,7 +69,7 @@ public class LinkedListTest extends JSR166TestCase {
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
private LinkedList<Integer> populatedQueue(int n) {
private static LinkedList<Integer> populatedQueue(int n) {
LinkedList<Integer> q = new LinkedList<>();
assertTrue(q.isEmpty());
for (int i = 0; i < n; ++i)

View File

@ -321,7 +321,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}});
aboutToWait.await();
await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);
@ -826,7 +826,7 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
Thread first = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
q.transfer(four);
assertTrue(!q.contains(four));
assertFalse(q.contains(four));
assertEquals(1, q.size());
}});

View File

@ -93,7 +93,7 @@ public class PriorityBlockingQueueTest extends JSR166TestCase {
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
private PriorityBlockingQueue<Integer> populatedQueue(int n) {
private static PriorityBlockingQueue<Integer> populatedQueue(int n) {
PriorityBlockingQueue<Integer> q =
new PriorityBlockingQueue<Integer>(n);
assertTrue(q.isEmpty());
@ -445,7 +445,7 @@ public class PriorityBlockingQueueTest extends JSR166TestCase {
}
}});
aboutToWait.await();
await(aboutToWait);
waitForThreadToEnterWaitState(t);
t.interrupt();
awaitTermination(t);

View File

@ -42,7 +42,6 @@ import java.util.PriorityQueue;
import java.util.Queue;
import junit.framework.Test;
import junit.framework.TestSuite;
public class PriorityQueueTest extends JSR166TestCase {
public static void main(String[] args) {
@ -70,7 +69,7 @@ public class PriorityQueueTest extends JSR166TestCase {
* Returns a new queue of given size containing consecutive
* Integers 0 ... n - 1.
*/
private PriorityQueue<Integer> populatedQueue(int n) {
private static PriorityQueue<Integer> populatedQueue(int n) {
PriorityQueue<Integer> q = new PriorityQueue<>(n);
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)

View File

@ -195,7 +195,7 @@ public class RecursiveActionTest extends JSR166TestCase {
public FJException(Throwable cause) { super(cause); }
}
// A simple recursive action for testing
/** A simple recursive action for testing. */
final class FibAction extends CheckedRecursiveAction {
final int number;
int result;
@ -213,7 +213,7 @@ public class RecursiveActionTest extends JSR166TestCase {
}
}
// A recursive action failing in base case
/** A recursive action failing in base case. */
static final class FailingFibAction extends RecursiveAction {
final int number;
int result;

View File

@ -210,10 +210,10 @@ public class RecursiveTaskTest extends JSR166TestCase {
public FJException() { super(); }
}
// An invalid return value for Fib
/** An invalid return value for Fib. */
static final Integer NoResult = Integer.valueOf(-17);
// A simple recursive task for testing
/** A simple recursive task for testing. */
final class FibTask extends CheckedRecursiveTask<Integer> {
final int number;
FibTask(int n) { number = n; }
@ -231,7 +231,7 @@ public class RecursiveTaskTest extends JSR166TestCase {
}
}
// A recursive action failing in base case
/** A recursive action failing in base case. */
final class FailingFibTask extends RecursiveTask<Integer> {
final int number;
int result;

View File

@ -518,7 +518,7 @@ public class StampedLockTest extends JSR166TestCase {
lock.unlockWrite(s);
}});
aboutToLock.await();
await(aboutToLock);
waitForThreadToEnterWaitState(t);
assertFalse(lock.isWriteLocked());
assertTrue(lock.isReadLocked());
@ -777,7 +777,7 @@ public class StampedLockTest extends JSR166TestCase {
lock.writeLockInterruptibly();
}});
locked.await();
await(locked);
assertFalse(lock.validate(p));
assertEquals(0L, lock.tryOptimisticRead());
waitForThreadToEnterWaitState(t);

View File

@ -519,7 +519,7 @@ public class SubmissionPublisherTest extends JSR166TestCase {
s1.request = false;
p.subscribe(s1);
s1.awaitSubscribe();
assertTrue(p.estimateMinimumDemand() == 0);
assertEquals(0, p.estimateMinimumDemand());
TestSubscriber s2 = new TestSubscriber();
p.subscribe(s2);
p.submit(1);

View File

@ -596,7 +596,7 @@ public class SynchronousQueueTest extends JSR166TestCase {
fail("timed out");
Thread.yield();
}
assertTrue(l.size() == 1);
assertEquals(1, l.size());
assertSame(one, l.get(0));
awaitTermination(t);
}

View File

@ -265,7 +265,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
await(done);
}
}
@ -359,13 +359,13 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
threadProceed.await();
await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
threadDone.await();
await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@ -1953,7 +1953,7 @@ public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
public void realRun() {
done.countDown();
}});
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
await(done);
}
}

View File

@ -45,7 +45,6 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
@ -118,7 +117,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
final Runnable task = new CheckedRunnable() {
public void realRun() { done.countDown(); }};
p.execute(task);
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
await(done);
}
}
@ -212,13 +211,13 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
public void realRun() throws InterruptedException {
threadStarted.countDown();
assertEquals(0, p.getCompletedTaskCount());
threadProceed.await();
await(threadProceed);
threadDone.countDown();
}});
await(threadStarted);
assertEquals(0, p.getCompletedTaskCount());
threadProceed.countDown();
threadDone.await();
await(threadDone);
long startTime = System.nanoTime();
while (p.getCompletedTaskCount() != 1) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
@ -301,6 +300,20 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
}
}
/**
* The default rejected execution handler is AbortPolicy.
*/
public void testDefaultRejectedExecutionHandler() {
final ThreadPoolExecutor p =
new ThreadPoolExecutor(1, 2,
LONG_DELAY_MS, MILLISECONDS,
new ArrayBlockingQueue<Runnable>(10));
try (PoolCleaner cleaner = cleaner(p)) {
assertTrue(p.getRejectedExecutionHandler()
instanceof ThreadPoolExecutor.AbortPolicy);
}
}
/**
* getRejectedExecutionHandler returns handler in constructor if not set
*/
@ -1139,7 +1152,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
await(done);
}};
for (int i = 0; i < 2; ++i)
p.submit(Executors.callable(task));
p.execute(task);
for (int i = 0; i < 2; ++i) {
try {
p.execute(task);
@ -1955,7 +1968,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
public void realRun() {
done.countDown();
}});
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
await(done);
}
}
@ -2048,7 +2061,7 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
}
}
// enough time to run all tasks
assertTrue(done.await(nTasks * SHORT_DELAY_MS, MILLISECONDS));
await(done, nTasks * SHORT_DELAY_MS);
}
}

View File

@ -76,7 +76,7 @@ public class ThreadTest extends JSR166TestCase {
* setDefaultUncaughtExceptionHandler.
*/
public void testGetAndSetDefaultUncaughtExceptionHandler() {
assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
assertNull(Thread.getDefaultUncaughtExceptionHandler());
// failure due to SecurityException is OK.
// Would be nice to explicitly test both ways, but cannot yet.
Thread.UncaughtExceptionHandler defaultHandler

View File

@ -69,7 +69,7 @@ public class TreeSetTest extends JSR166TestCase {
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
private TreeSet<Integer> populatedSet(int n) {
private static TreeSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2)
@ -84,7 +84,7 @@ public class TreeSetTest extends JSR166TestCase {
/**
* Returns a new set of first 5 ints.
*/
private TreeSet set5() {
private static TreeSet set5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(one);

View File

@ -60,7 +60,7 @@ public class TreeSubSetTest extends JSR166TestCase {
* Returns a new set of given size containing consecutive
* Integers 0 ... n - 1.
*/
private NavigableSet<Integer> populatedSet(int n) {
private static NavigableSet<Integer> populatedSet(int n) {
TreeSet<Integer> q = new TreeSet<>();
assertTrue(q.isEmpty());
@ -79,7 +79,7 @@ public class TreeSubSetTest extends JSR166TestCase {
/**
* Returns a new set of first 5 ints.
*/
private NavigableSet set5() {
private static NavigableSet set5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(one);
@ -94,7 +94,7 @@ public class TreeSubSetTest extends JSR166TestCase {
return s;
}
private NavigableSet dset5() {
private static NavigableSet dset5() {
TreeSet q = new TreeSet();
assertTrue(q.isEmpty());
q.add(m1);

View File

@ -33,11 +33,9 @@
*/
import java.util.Vector;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
public class VectorTest extends JSR166TestCase {
public static void main(String[] args) {