519 |
|
* the same test have no effect. |
520 |
|
*/ |
521 |
|
public void threadRecordFailure(Throwable t) { |
522 |
+ |
threadDump(); |
523 |
|
threadFailure.compareAndSet(null, t); |
524 |
|
} |
525 |
|
|
530 |
|
void tearDownFail(String format, Object... args) { |
531 |
|
String msg = toString() + ": " + String.format(format, args); |
532 |
|
System.err.println(msg); |
533 |
< |
printAllStackTraces(); |
533 |
> |
threadDump(); |
534 |
|
throw new AssertionFailedError(msg); |
535 |
|
} |
536 |
|
|
599 |
|
fail(reason); |
600 |
|
} catch (AssertionFailedError t) { |
601 |
|
threadRecordFailure(t); |
602 |
< |
fail(reason); |
602 |
> |
throw t; |
603 |
|
} |
604 |
|
} |
605 |
|
|
779 |
|
* necessarily individually slow because they must block. |
780 |
|
*/ |
781 |
|
void testInParallel(Action ... actions) { |
782 |
< |
ExecutorService pool = Executors.newCachedThreadPool(); |
783 |
< |
try { |
782 |
> |
try (PoolCloser<ExecutorService> poolCloser |
783 |
> |
= new PoolCloser<>(Executors.newCachedThreadPool())) { |
784 |
> |
ExecutorService pool = poolCloser.pool; |
785 |
|
ArrayList<Future<?>> futures = new ArrayList<>(actions.length); |
786 |
|
for (final Action action : actions) |
787 |
|
futures.add(pool.submit(new CheckedRunnable() { |
794 |
|
} catch (Exception ex) { |
795 |
|
threadUnexpectedException(ex); |
796 |
|
} |
795 |
– |
} finally { |
796 |
– |
joinPool(pool); |
797 |
|
} |
798 |
|
} |
799 |
|
|
801 |
|
* A debugging tool to print all stack traces, as jstack does. |
802 |
|
* Uninteresting threads are filtered out. |
803 |
|
*/ |
804 |
< |
static void printAllStackTraces() { |
804 |
> |
static void threadDump() { |
805 |
|
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
806 |
|
System.err.println("------ stacktrace dump start ------"); |
807 |
|
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |