8203681: Miscellaneous changes imported from jsr166 CVS 2018-06
Reviewed-by: martin, psandoz
This commit is contained in:
parent
3afeb2cb48
commit
0a0a8a5791
src/java.base/share/classes/java/util/concurrent
ArrayBlockingQueue.javaConcurrentSkipListMap.javaCopyOnWriteArrayList.javaForkJoinTask.javaTimeUnit.java
locks
test/jdk/java/util
Collection
Map
concurrent
ArrayBlockingQueue
ConcurrentHashMap
locks/ReentrantReadWriteLock
tck
AbstractQueuedLongSynchronizerTest.javaAbstractQueuedSynchronizerTest.javaCompletableFutureTest.javaConcurrentHashMap8Test.javaConcurrentLinkedDequeTest.javaConcurrentLinkedQueueTest.javaConcurrentSkipListSetTest.javaConcurrentSkipListSubSetTest.javaDelayQueueTest.javaLinkedBlockingDequeTest.javaLinkedBlockingQueueTest.javaLinkedListTest.javaLinkedTransferQueueTest.javaPriorityBlockingQueueTest.javaPriorityQueueTest.javaRecursiveActionTest.javaSubmissionPublisherTest.javaTreeSetTest.javaTreeSubSetTest.java
@ -1129,7 +1129,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
|
||||
final int len = items.length;
|
||||
// how far takeIndex has advanced since the previous
|
||||
// operation of this iterator
|
||||
long dequeues = (cycles - prevCycles) * len
|
||||
long dequeues = (long) (cycles - prevCycles) * len
|
||||
+ (takeIndex - prevTakeIndex);
|
||||
|
||||
// Check indices for invalidation
|
||||
|
@ -1764,9 +1764,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch (ClassCastException unused) {
|
||||
return false;
|
||||
} catch (NullPointerException unused) {
|
||||
} catch (ClassCastException | NullPointerException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
package java.util.concurrent;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -299,6 +300,9 @@ public class CopyOnWriteArrayList<E>
|
||||
CopyOnWriteArrayList<E> clone =
|
||||
(CopyOnWriteArrayList<E>) super.clone();
|
||||
clone.resetLock();
|
||||
// Unlike in readObject, here we cannot visibility-piggyback on the
|
||||
// volatile write in setArray().
|
||||
VarHandle.releaseFence();
|
||||
return clone;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// this shouldn't happen, since we are Cloneable
|
||||
|
@ -826,7 +826,7 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
|
||||
*/
|
||||
public static <T extends ForkJoinTask<?>> Collection<T> invokeAll(Collection<T> tasks) {
|
||||
if (!(tasks instanceof RandomAccess) || !(tasks instanceof List<?>)) {
|
||||
invokeAll(tasks.toArray(new ForkJoinTask<?>[tasks.size()]));
|
||||
invokeAll(tasks.toArray(new ForkJoinTask<?>[0]));
|
||||
return tasks;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -202,6 +202,10 @@ public enum TimeUnit {
|
||||
* {@code unit.convert(Duration.of(n, unit.toChronoUnit()))}
|
||||
* is equivalent to {@code n} (in the absence of overflow).
|
||||
*
|
||||
* @apiNote
|
||||
* This method differs from {@link Duration#toNanos()} in that it
|
||||
* does not throw {@link ArithmeticException} on numeric overflow.
|
||||
*
|
||||
* @param duration the time duration
|
||||
* @return the converted duration in this unit,
|
||||
* or {@code Long.MIN_VALUE} if conversion would negatively overflow,
|
||||
@ -216,7 +220,7 @@ public enum TimeUnit {
|
||||
if (secs < 0 && nano > 0) {
|
||||
// use representation compatible with integer division
|
||||
secs++;
|
||||
nano -= SECOND_SCALE;
|
||||
nano -= (int) SECOND_SCALE;
|
||||
}
|
||||
final long s, nanoVal;
|
||||
// Optimize for the common case - NANOSECONDS without overflow
|
||||
|
@ -312,13 +312,13 @@ public interface Condition {
|
||||
* <pre> {@code
|
||||
* boolean aMethod(long timeout, TimeUnit unit)
|
||||
* throws InterruptedException {
|
||||
* long nanos = unit.toNanos(timeout);
|
||||
* long nanosRemaining = unit.toNanos(timeout);
|
||||
* lock.lock();
|
||||
* try {
|
||||
* while (!conditionBeingWaitedFor()) {
|
||||
* if (nanos <= 0L)
|
||||
* if (nanosRemaining <= 0L)
|
||||
* return false;
|
||||
* nanos = theCondition.awaitNanos(nanos);
|
||||
* nanosRemaining = theCondition.awaitNanos(nanosRemaining);
|
||||
* }
|
||||
* // ...
|
||||
* return true;
|
||||
|
@ -70,7 +70,8 @@ public class HotPotatoes {
|
||||
System.out.printf("implClazz=%s, argClazz=%s\n",
|
||||
implClazz.getName(), argClazz.getName());
|
||||
final int iterations = 100000;
|
||||
final List<Integer> list = (List<Integer>) argClazz.newInstance();
|
||||
final List<Integer> list = (List<Integer>)
|
||||
argClazz.getDeclaredConstructor().newInstance();
|
||||
final Integer one = Integer.valueOf(1);
|
||||
final List<Integer> oneElementList = Collections.singletonList(one);
|
||||
final Constructor<? extends Collection> constr
|
||||
|
@ -325,7 +325,7 @@ public class IteratorMicroBenchmark {
|
||||
}
|
||||
|
||||
@SafeVarargs @SuppressWarnings("varargs")
|
||||
private <T> Stream<T> concatStreams(Stream<T> ... streams) {
|
||||
private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
|
||||
return Stream.of(streams).flatMap(s -> s);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ public class RemoveMicroBenchmark {
|
||||
}
|
||||
|
||||
@SafeVarargs @SuppressWarnings("varargs")
|
||||
private <T> Stream<T> concatStreams(Stream<T> ... streams) {
|
||||
private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
|
||||
return Stream.of(streams).flatMap(s -> s);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
* @key randomness
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
@ -104,23 +103,21 @@ public class LockStep {
|
||||
final Random r = new Random();
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
List<Map> maps = Arrays.asList(
|
||||
new Map[] {
|
||||
new IdentityHashMap(11),
|
||||
new HashMap(16),
|
||||
new LinkedHashMap(16),
|
||||
new WeakHashMap(16),
|
||||
new Hashtable(16),
|
||||
new TreeMap(),
|
||||
new ConcurrentHashMap(16),
|
||||
new ConcurrentSkipListMap(),
|
||||
Collections.checkedMap(new HashMap(16), Integer.class, Integer.class),
|
||||
Collections.checkedSortedMap(new TreeMap(), Integer.class, Integer.class),
|
||||
Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class),
|
||||
Collections.synchronizedMap(new HashMap(16)),
|
||||
Collections.synchronizedSortedMap(new TreeMap()),
|
||||
Collections.synchronizedNavigableMap(new TreeMap())
|
||||
});
|
||||
List<Map> maps = List.of(
|
||||
new IdentityHashMap(11),
|
||||
new HashMap(16),
|
||||
new LinkedHashMap(16),
|
||||
new WeakHashMap(16),
|
||||
new Hashtable(16),
|
||||
new TreeMap(),
|
||||
new ConcurrentHashMap(16),
|
||||
new ConcurrentSkipListMap(),
|
||||
Collections.checkedMap(new HashMap(16), Integer.class, Integer.class),
|
||||
Collections.checkedSortedMap(new TreeMap(), Integer.class, Integer.class),
|
||||
Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class),
|
||||
Collections.synchronizedMap(new HashMap(16)),
|
||||
Collections.synchronizedSortedMap(new TreeMap()),
|
||||
Collections.synchronizedNavigableMap(new TreeMap()));
|
||||
|
||||
for (int j = 0; j < 10; j++)
|
||||
put(maps, r.nextInt(100), r.nextInt(100));
|
||||
|
@ -59,7 +59,6 @@ import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Test
|
||||
|
@ -109,7 +109,7 @@ public class MapCheck {
|
||||
|
||||
static Map newMap(Class cl) {
|
||||
try {
|
||||
return (Map)cl.newInstance();
|
||||
return (Map)cl.getDeclaredConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Can't instantiate " + cl + ": " + e);
|
||||
}
|
||||
@ -407,7 +407,7 @@ public class MapCheck {
|
||||
timer.start("Put (putAll) ", size * 2);
|
||||
Map s2 = null;
|
||||
try {
|
||||
s2 = (Map) (s.getClass().newInstance());
|
||||
s2 = (Map) s.getClass().getDeclaredConstructor().newInstance();
|
||||
s2.putAll(s);
|
||||
}
|
||||
catch (Exception e) { e.printStackTrace(); return; }
|
||||
|
@ -156,7 +156,8 @@ public class MapLoops {
|
||||
|
||||
static void test(int i, int nkeys, Class mapClass) throws Exception {
|
||||
System.out.print("Threads: " + i + "\t:");
|
||||
Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
|
||||
Map<Integer, Integer> map = (Map<Integer, Integer>)
|
||||
mapClass.getDeclaredConstructor().newInstance();
|
||||
Integer[] key = makeKeys(nkeys);
|
||||
// Uncomment to start with a non-empty table
|
||||
// for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
|
||||
|
@ -104,7 +104,8 @@ public class MapLoops {
|
||||
// warmup
|
||||
System.out.println("Warmup...");
|
||||
for (int k = 0; k < 2; ++k) {
|
||||
Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
|
||||
Map<Integer, Integer> map = (Map<Integer, Integer>)
|
||||
mapClass.getDeclaredConstructor().newInstance();
|
||||
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
|
||||
CyclicBarrier barrier = new CyclicBarrier(1, timer);
|
||||
new Runner(map, key, barrier, rnd.split()).run();
|
||||
@ -113,7 +114,8 @@ public class MapLoops {
|
||||
|
||||
for (int i = 1; i <= maxThreads; i += (i+1) >>> 1) {
|
||||
System.out.print("Threads: " + i + "\t:");
|
||||
Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
|
||||
Map<Integer, Integer> map = (Map<Integer, Integer>)
|
||||
mapClass.getDeclaredConstructor().newInstance();
|
||||
LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
|
||||
CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
|
||||
for (int k = 0; k < i; ++k)
|
||||
|
@ -251,8 +251,8 @@ public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
|
||||
assertTrue(c.await(timeoutMillis, MILLISECONDS));
|
||||
break;
|
||||
case awaitNanos:
|
||||
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(nanosTimeout);
|
||||
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(timeoutNanos);
|
||||
assertTrue(nanosRemaining > 0);
|
||||
break;
|
||||
case awaitUntil:
|
||||
@ -279,8 +279,8 @@ public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase {
|
||||
break;
|
||||
case awaitNanos:
|
||||
startTime = System.nanoTime();
|
||||
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(nanosTimeout);
|
||||
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(timeoutNanos);
|
||||
assertTrue(nanosRemaining <= 0);
|
||||
assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
|
||||
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
|
||||
|
@ -255,8 +255,8 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
|
||||
assertTrue(c.await(timeoutMillis, MILLISECONDS));
|
||||
break;
|
||||
case awaitNanos:
|
||||
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(nanosTimeout);
|
||||
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(timeoutNanos);
|
||||
assertTrue(nanosRemaining > 0);
|
||||
break;
|
||||
case awaitUntil:
|
||||
@ -283,8 +283,8 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
|
||||
break;
|
||||
case awaitNanos:
|
||||
startTime = System.nanoTime();
|
||||
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(nanosTimeout);
|
||||
long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
|
||||
long nanosRemaining = c.awaitNanos(timeoutNanos);
|
||||
assertTrue(nanosRemaining <= 0);
|
||||
assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
|
||||
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
|
||||
|
@ -4415,7 +4415,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
||||
f.complete(null);
|
||||
|
||||
f = new CompletableFuture<>();
|
||||
CompletableFuture.anyOf(new CompletableFuture<?>[] { f, incomplete });
|
||||
CompletableFuture.anyOf(f, incomplete);
|
||||
f.complete(null);
|
||||
}
|
||||
|
||||
@ -4433,7 +4433,7 @@ public class CompletableFutureTest extends JSR166TestCase {
|
||||
f.complete(null);
|
||||
|
||||
f = new CompletableFuture<>();
|
||||
CompletableFuture.anyOf(new CompletableFuture<?>[] { incomplete, f });
|
||||
CompletableFuture.anyOf(incomplete, f);
|
||||
f.complete(null);
|
||||
}
|
||||
}
|
||||
|
@ -200,8 +200,8 @@ public class ConcurrentHashMap8Test extends JSR166TestCase {
|
||||
static Set populatedSet(Integer[] elements) {
|
||||
Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
|
||||
assertTrue(a.isEmpty());
|
||||
for (int i = 0; i < elements.length; i++)
|
||||
assertTrue(a.add(elements[i]));
|
||||
for (Integer element : elements)
|
||||
assertTrue(a.add(element));
|
||||
assertFalse(a.isEmpty());
|
||||
assertEquals(elements.length, a.size());
|
||||
return a;
|
||||
|
@ -689,9 +689,11 @@ public class ConcurrentLinkedDequeTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
ConcurrentLinkedDeque q = populatedDeque(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -702,8 +704,9 @@ public class ConcurrentLinkedDequeTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.poll());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -416,9 +416,11 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
ConcurrentLinkedQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,8 +431,9 @@ public class ConcurrentLinkedQueueTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.poll());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -483,9 +483,11 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
ConcurrentSkipListSet q = populatedSet(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.pollFirst());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,8 +497,9 @@ public class ConcurrentSkipListSetTest extends JSR166TestCase {
|
||||
ConcurrentSkipListSet<Integer> q = populatedSet(SIZE);
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
assertSame(ints, q.toArray(ints));
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.pollFirst());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -434,9 +434,11 @@ public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
NavigableSet q = populatedSet(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.pollFirst());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -447,8 +449,9 @@ public class ConcurrentSkipListSubSetTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.pollFirst());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -593,10 +593,12 @@ public class DelayQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() throws InterruptedException {
|
||||
DelayQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
Arrays.sort(o);
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.take());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
Arrays.sort(a);
|
||||
for (Object o : a)
|
||||
assertSame(o, q.take());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -608,8 +610,9 @@ public class DelayQueueTest extends JSR166TestCase {
|
||||
PDelay[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
Arrays.sort(ints);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.remove());
|
||||
for (PDelay o : ints)
|
||||
assertSame(o, q.remove());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1570,9 +1570,11 @@ public class LinkedBlockingDequeTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() throws InterruptedException {
|
||||
LinkedBlockingDeque q = populatedDeque(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1583,8 +1585,9 @@ public class LinkedBlockingDequeTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.remove());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.remove());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -656,9 +656,11 @@ public class LinkedBlockingQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
LinkedBlockingQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -669,8 +671,9 @@ public class LinkedBlockingQueueTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.poll());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -385,9 +385,11 @@ public class LinkedListTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
LinkedList q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -398,8 +400,9 @@ public class LinkedListTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.poll());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -502,10 +502,11 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
LinkedTransferQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
assertSame(o[i], q.poll());
|
||||
}
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -516,9 +517,9 @@ public class LinkedTransferQueueTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
assertSame(ints[i], q.poll());
|
||||
}
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -600,10 +600,12 @@ public class PriorityBlockingQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() throws InterruptedException {
|
||||
PriorityBlockingQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
Arrays.sort(o);
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.take());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
Arrays.sort(a);
|
||||
for (Object o : a)
|
||||
assertSame(o, q.take());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -615,8 +617,9 @@ public class PriorityBlockingQueueTest extends JSR166TestCase {
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
Arrays.sort(ints);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.take());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.take());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -463,10 +463,12 @@ public class PriorityQueueTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
PriorityQueue q = populatedQueue(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
Arrays.sort(o);
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.poll());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
Arrays.sort(a);
|
||||
for (Object o : a)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,8 +480,9 @@ public class PriorityQueueTest extends JSR166TestCase {
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
Arrays.sort(ints);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.poll());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.poll());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,8 +364,8 @@ public class RecursiveActionTest extends JSR166TestCase {
|
||||
fibActions[4].cancel(true);
|
||||
fibActions[5].completeExceptionally(new FJException());
|
||||
|
||||
for (int i = 0; i < fibActions.length; i++)
|
||||
fibActions[i].fork();
|
||||
for (FibAction fibAction : fibActions)
|
||||
fibAction.fork();
|
||||
|
||||
sq.put(fibActions);
|
||||
|
||||
|
@ -361,9 +361,7 @@ public class SubmissionPublisherTest extends JSR166TestCase {
|
||||
TestSubscriber s = new TestSubscriber();
|
||||
SubmissionPublisher<Integer> p = basicPublisher();
|
||||
s.throwOnCall = true;
|
||||
try {
|
||||
p.subscribe(s);
|
||||
} catch (Exception ok) {}
|
||||
p.subscribe(s);
|
||||
s.awaitError();
|
||||
assertEquals(0, s.nexts);
|
||||
assertEquals(1, s.errors);
|
||||
|
@ -481,9 +481,11 @@ public class TreeSetTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
TreeSet q = populatedSet(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.pollFirst());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -494,8 +496,9 @@ public class TreeSetTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.pollFirst());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -432,9 +432,11 @@ public class TreeSubSetTest extends JSR166TestCase {
|
||||
*/
|
||||
public void testToArray() {
|
||||
NavigableSet q = populatedSet(SIZE);
|
||||
Object[] o = q.toArray();
|
||||
for (int i = 0; i < o.length; i++)
|
||||
assertSame(o[i], q.pollFirst());
|
||||
Object[] a = q.toArray();
|
||||
assertSame(Object[].class, a.getClass());
|
||||
for (Object o : a)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,8 +447,9 @@ public class TreeSubSetTest extends JSR166TestCase {
|
||||
Integer[] ints = new Integer[SIZE];
|
||||
Integer[] array = q.toArray(ints);
|
||||
assertSame(ints, array);
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
assertSame(ints[i], q.pollFirst());
|
||||
for (Integer o : ints)
|
||||
assertSame(o, q.pollFirst());
|
||||
assertTrue(q.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user