mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-19 04:13:07 +00:00
8207003: Miscellaneous changes imported from jsr166 CVS 2018-09
Reviewed-by: martin, chegar
This commit is contained in:
parent
0b431957a5
commit
deb0e6503d
@ -45,6 +45,7 @@ import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertSame;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
@ -369,7 +370,7 @@ public class EmptyNavigableSet {
|
||||
|
||||
assertSame(emptyNavigableSetArray, result);
|
||||
|
||||
assertTrue(result[0] == null);
|
||||
assertNull(result[0]);
|
||||
}
|
||||
|
||||
@DataProvider(name = "NavigableSet<?>", parallel = true)
|
||||
|
||||
@ -42,6 +42,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
public class AddNonComparable {
|
||||
@ -64,7 +65,7 @@ public class AddNonComparable {
|
||||
test(new PriorityQueue<>(), AComparable::new,
|
||||
(q, e) -> {
|
||||
assertEquals(q.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
|
||||
test(new PriorityBlockingQueue<>(), NonComparable::new,
|
||||
@ -75,7 +76,7 @@ public class AddNonComparable {
|
||||
test(new PriorityBlockingQueue<>(), AComparable::new,
|
||||
(q, e) -> {
|
||||
assertEquals(q.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ public class AddNonComparable {
|
||||
test(new TreeSet<>(), AComparable::new,
|
||||
(s, e) -> {
|
||||
assertEquals(s.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
|
||||
test(new ConcurrentSkipListSet<>(), NonComparable::new,
|
||||
@ -109,7 +110,7 @@ public class AddNonComparable {
|
||||
test(new ConcurrentSkipListSet<>(), AComparable::new,
|
||||
(s, e) -> {
|
||||
assertEquals(s.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
}
|
||||
|
||||
@ -131,7 +132,7 @@ public class AddNonComparable {
|
||||
test(new TreeMap<>(), AComparable::new,
|
||||
(m, e) -> {
|
||||
assertEquals(m.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
|
||||
test(new ConcurrentSkipListMap<>(), NonComparable::new,
|
||||
@ -142,7 +143,7 @@ public class AddNonComparable {
|
||||
test(new ConcurrentSkipListMap<>(), AComparable::new,
|
||||
(s, e) -> {
|
||||
assertEquals(s.size(), 1);
|
||||
assertTrue(e == null);
|
||||
assertNull(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1310,7 +1310,7 @@ public class AbstractQueuedSynchronizerTest extends JSR166TestCase {
|
||||
try {
|
||||
s.acquireInterruptibly(1);
|
||||
shouldThrow();
|
||||
} catch (InterruptedException expected) {}
|
||||
} catch (InterruptedException success) {}
|
||||
};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Thread thread = new Thread(failedAcquire);
|
||||
|
||||
@ -135,10 +135,14 @@ public class CountedCompleterTest extends JSR166TestCase {
|
||||
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
Object v1 = null, v2 = null;
|
||||
try {
|
||||
assertNull(a.get());
|
||||
assertNull(a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertNull(v1);
|
||||
assertNull(v2);
|
||||
}
|
||||
|
||||
void checkCancelled(CountedCompleter a) {
|
||||
|
||||
@ -96,7 +96,7 @@ public class DelayQueueTest extends JSR166TestCase {
|
||||
// suppress [overrides] javac warning
|
||||
public int hashCode() { return pseudodelay; }
|
||||
public long getDelay(TimeUnit ignore) {
|
||||
return Integer.MIN_VALUE + pseudodelay;
|
||||
return (long) Integer.MIN_VALUE + pseudodelay;
|
||||
}
|
||||
public String toString() {
|
||||
return String.valueOf(pseudodelay);
|
||||
|
||||
@ -133,10 +133,14 @@ public class ForkJoinPool8Test extends JSR166TestCase {
|
||||
assertNull(a.join());
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
Object v1 = null, v2 = null;
|
||||
try {
|
||||
assertNull(a.get());
|
||||
assertNull(a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertNull(v1);
|
||||
assertNull(v2);
|
||||
}
|
||||
|
||||
void checkCancelled(ForkJoinTask a) {
|
||||
|
||||
@ -140,13 +140,13 @@ public class ForkJoinTask8Test extends JSR166TestCase {
|
||||
checkCompletedNormally(a, null);
|
||||
}
|
||||
|
||||
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
|
||||
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
|
||||
assertTrue(a.isDone());
|
||||
assertFalse(a.isCancelled());
|
||||
assertTrue(a.isCompletedNormally());
|
||||
assertFalse(a.isCompletedAbnormally());
|
||||
assertNull(a.getException());
|
||||
assertSame(expected, a.getRawResult());
|
||||
assertSame(expectedValue, a.getRawResult());
|
||||
if (a instanceof BinaryAsyncAction)
|
||||
assertEquals(COMPLETE_STATE,
|
||||
((BinaryAsyncAction)a).getForkJoinTaskTag());
|
||||
@ -154,7 +154,7 @@ public class ForkJoinTask8Test extends JSR166TestCase {
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
long startTime = System.nanoTime();
|
||||
assertSame(expected, a.join());
|
||||
assertSame(expectedValue, a.join());
|
||||
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
|
||||
Thread.interrupted();
|
||||
}
|
||||
@ -169,10 +169,14 @@ public class ForkJoinTask8Test extends JSR166TestCase {
|
||||
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
T v1 = null, v2 = null;
|
||||
try {
|
||||
assertSame(expected, a.get());
|
||||
assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertSame(expectedValue, v1);
|
||||
assertSame(expectedValue, v2);
|
||||
}
|
||||
|
||||
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
|
||||
|
||||
@ -114,18 +114,18 @@ public class ForkJoinTaskTest extends JSR166TestCase {
|
||||
checkCompletedNormally(a, null);
|
||||
}
|
||||
|
||||
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
|
||||
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
|
||||
assertTrue(a.isDone());
|
||||
assertFalse(a.isCancelled());
|
||||
assertTrue(a.isCompletedNormally());
|
||||
assertFalse(a.isCompletedAbnormally());
|
||||
assertNull(a.getException());
|
||||
assertSame(expected, a.getRawResult());
|
||||
assertSame(expectedValue, a.getRawResult());
|
||||
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
long startTime = System.nanoTime();
|
||||
assertSame(expected, a.join());
|
||||
assertSame(expectedValue, a.join());
|
||||
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
|
||||
Thread.interrupted();
|
||||
}
|
||||
@ -140,10 +140,14 @@ public class ForkJoinTaskTest extends JSR166TestCase {
|
||||
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
T v1 = null, v2 = null;
|
||||
try {
|
||||
assertSame(expected, a.get());
|
||||
assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertSame(expectedValue, v1);
|
||||
assertSame(expectedValue, v2);
|
||||
}
|
||||
|
||||
void checkCancelled(ForkJoinTask a) {
|
||||
|
||||
@ -87,8 +87,9 @@ public class FutureTaskTest extends JSR166TestCase {
|
||||
pf.run();
|
||||
pf.runAndReset();
|
||||
assertEquals(savedRunCount, pf.runCount());
|
||||
Object r2 = null;
|
||||
try {
|
||||
assertSame(r, f.get());
|
||||
r2 = f.get();
|
||||
} catch (CancellationException t) {
|
||||
assertSame(exInfo, CancellationException.class);
|
||||
} catch (ExecutionException t) {
|
||||
@ -96,6 +97,8 @@ public class FutureTaskTest extends JSR166TestCase {
|
||||
} catch (Throwable t) {
|
||||
threadUnexpectedException(t);
|
||||
}
|
||||
if (exInfo == null)
|
||||
assertSame(r, r2);
|
||||
assertTrue(f.isDone());
|
||||
}
|
||||
}
|
||||
@ -128,14 +131,17 @@ public class FutureTaskTest extends JSR166TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
<T> void checkCompletedNormally(Future<T> f, T expected) {
|
||||
<T> void checkCompletedNormally(Future<T> f, T expectedValue) {
|
||||
checkIsDone(f);
|
||||
assertFalse(f.isCancelled());
|
||||
|
||||
T v1 = null, v2 = null;
|
||||
try {
|
||||
assertSame(expected, f.get());
|
||||
assertSame(expected, f.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = f.get();
|
||||
v2 = f.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertSame(expectedValue, v1);
|
||||
assertSame(expectedValue, v2);
|
||||
}
|
||||
|
||||
void checkCancelled(Future<?> f) {
|
||||
@ -485,7 +491,7 @@ public class FutureTaskTest extends JSR166TestCase {
|
||||
try {
|
||||
task.cancel(true);
|
||||
shouldThrow();
|
||||
} catch (SecurityException expected) {}
|
||||
} catch (SecurityException success) {}
|
||||
|
||||
// We failed to deliver the interrupt, but the world retains
|
||||
// its sanity, as if we had done task.cancel(false)
|
||||
|
||||
@ -1415,9 +1415,11 @@ public class JSR166TestCase extends TestCase {
|
||||
*/
|
||||
<T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) {
|
||||
long startTime = System.nanoTime();
|
||||
T actual = null;
|
||||
try {
|
||||
assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
|
||||
actual = f.get(timeoutMillis, MILLISECONDS);
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertEquals(expectedValue, actual);
|
||||
if (millisElapsedSince(startTime) > timeoutMillis/2)
|
||||
throw new AssertionError("timed get did not return promptly");
|
||||
}
|
||||
@ -1596,13 +1598,15 @@ public class JSR166TestCase extends TestCase {
|
||||
}
|
||||
|
||||
public void await(CountDownLatch latch, long timeoutMillis) {
|
||||
boolean timedOut = false;
|
||||
try {
|
||||
if (!latch.await(timeoutMillis, MILLISECONDS))
|
||||
fail("timed out waiting for CountDownLatch for "
|
||||
+ (timeoutMillis/1000) + " sec");
|
||||
timedOut = !latch.await(timeoutMillis, MILLISECONDS);
|
||||
} catch (Throwable fail) {
|
||||
threadUnexpectedException(fail);
|
||||
}
|
||||
if (timedOut)
|
||||
fail("timed out waiting for CountDownLatch for "
|
||||
+ (timeoutMillis/1000) + " sec");
|
||||
}
|
||||
|
||||
public void await(CountDownLatch latch) {
|
||||
@ -1610,13 +1614,15 @@ public class JSR166TestCase extends TestCase {
|
||||
}
|
||||
|
||||
public void await(Semaphore semaphore) {
|
||||
boolean timedOut = false;
|
||||
try {
|
||||
if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
|
||||
fail("timed out waiting for Semaphore for "
|
||||
+ (LONG_DELAY_MS/1000) + " sec");
|
||||
timedOut = !semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS);
|
||||
} catch (Throwable fail) {
|
||||
threadUnexpectedException(fail);
|
||||
}
|
||||
if (timedOut)
|
||||
fail("timed out waiting for Semaphore for "
|
||||
+ (LONG_DELAY_MS/1000) + " sec");
|
||||
}
|
||||
|
||||
public void await(CyclicBarrier barrier) {
|
||||
@ -1802,17 +1808,17 @@ public class JSR166TestCase extends TestCase {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> T serialClone(T o) {
|
||||
T clone = null;
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream
|
||||
(new ByteArrayInputStream(serialBytes(o)));
|
||||
T clone = (T) ois.readObject();
|
||||
if (o == clone) assertImmutable(o);
|
||||
assertSame(o.getClass(), clone.getClass());
|
||||
return clone;
|
||||
clone = (T) ois.readObject();
|
||||
} catch (Throwable fail) {
|
||||
threadUnexpectedException(fail);
|
||||
return null;
|
||||
}
|
||||
if (o == clone) assertImmutable(o);
|
||||
else assertSame(o.getClass(), clone.getClass());
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1831,7 +1837,7 @@ public class JSR166TestCase extends TestCase {
|
||||
(new ByteArrayInputStream(bos.toByteArray()));
|
||||
T clone = (T) ois.readObject();
|
||||
if (o == clone) assertImmutable(o);
|
||||
assertSame(o.getClass(), clone.getClass());
|
||||
else assertSame(o.getClass(), clone.getClass());
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@ -123,10 +123,14 @@ public class RecursiveActionTest extends JSR166TestCase {
|
||||
assertNull(a.join());
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
Object v1 = null, v2 = null;
|
||||
try {
|
||||
assertNull(a.get());
|
||||
assertNull(a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertNull(v1);
|
||||
assertNull(v2);
|
||||
}
|
||||
|
||||
void checkCancelled(RecursiveAction a) {
|
||||
|
||||
@ -109,29 +109,33 @@ public class RecursiveTaskTest extends JSR166TestCase {
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
}
|
||||
|
||||
<T> void checkCompletedNormally(RecursiveTask<T> a, T expected) {
|
||||
<T> void checkCompletedNormally(RecursiveTask<T> a, T expectedValue) {
|
||||
assertTrue(a.isDone());
|
||||
assertFalse(a.isCancelled());
|
||||
assertTrue(a.isCompletedNormally());
|
||||
assertFalse(a.isCompletedAbnormally());
|
||||
assertNull(a.getException());
|
||||
assertSame(expected, a.getRawResult());
|
||||
assertSame(expected, a.join());
|
||||
assertSame(expectedValue, a.getRawResult());
|
||||
assertSame(expectedValue, a.join());
|
||||
assertFalse(a.cancel(false));
|
||||
assertFalse(a.cancel(true));
|
||||
|
||||
T v1 = null, v2 = null;
|
||||
try {
|
||||
assertSame(expected, a.get());
|
||||
assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
|
||||
v1 = a.get();
|
||||
v2 = a.get(randomTimeout(), randomTimeUnit());
|
||||
} catch (Throwable fail) { threadUnexpectedException(fail); }
|
||||
assertSame(expectedValue, v1);
|
||||
assertSame(expectedValue, v2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the task to complete, and checks that when it does,
|
||||
* it will have an Integer result equals to the given int.
|
||||
*/
|
||||
void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
|
||||
void checkCompletesNormally(RecursiveTask<Integer> a, int expectedValue) {
|
||||
Integer r = a.join();
|
||||
assertEquals(expected, (int) r);
|
||||
assertEquals(expectedValue, (int) r);
|
||||
checkCompletedNormally(a, r);
|
||||
}
|
||||
|
||||
@ -139,9 +143,9 @@ public class RecursiveTaskTest extends JSR166TestCase {
|
||||
* Like checkCompletesNormally, but verifies that the task has
|
||||
* already completed.
|
||||
*/
|
||||
void checkCompletedNormally(RecursiveTask<Integer> a, int expected) {
|
||||
void checkCompletedNormally(RecursiveTask<Integer> a, int expectedValue) {
|
||||
Integer r = a.getRawResult();
|
||||
assertEquals(expected, (int) r);
|
||||
assertEquals(expectedValue, (int) r);
|
||||
checkCompletedNormally(a, r);
|
||||
}
|
||||
|
||||
|
||||
@ -1187,7 +1187,7 @@ public class ReentrantLockTest extends JSR166TestCase {
|
||||
await(cond, awaitMethod);
|
||||
throw new AssertionError("should throw");
|
||||
}
|
||||
catch (IllegalMonitorStateException expected) {}
|
||||
catch (IllegalMonitorStateException success) {}
|
||||
catch (Throwable fail) { threadUnexpectedException(fail); }}};
|
||||
Thread rogueThread = new Thread(rogue, "rogue");
|
||||
threads.add(rogueThread);
|
||||
|
||||
@ -1029,7 +1029,9 @@ public class SubmissionPublisherTest extends JSR166TestCase {
|
||||
public void onComplete() {}
|
||||
}
|
||||
pub.subscribe(new Sub());
|
||||
CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE));
|
||||
checkTimedGet(
|
||||
CompletableFuture.runAsync(() -> pub.submit(Boolean.TRUE)),
|
||||
null);
|
||||
await(finished);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user