001
014
015 package com.liferay.portal.test.log;
016
017 import java.util.Map;
018 import java.util.concurrent.ConcurrentHashMap;
019
020 import org.junit.Assert;
021
022
025 public class ConcurrentAssertUtil {
026
027 public static void caughtFailure(String message) {
028 Thread currentThread = Thread.currentThread();
029
030 if (currentThread != _thread) {
031 _concurrentFailureMessages.put(currentThread, message);
032
033 _thread.interrupt();
034 }
035 else {
036 Assert.fail(message);
037 }
038 }
039
040 public static void endAssert() {
041 _thread = null;
042
043 try {
044 for (Map.Entry<Thread, String> entry :
045 _concurrentFailureMessages.entrySet()) {
046
047 Thread thread = entry.getKey();
048
049 Assert.fail(
050 "Thread " + thread + " caught concurrent failure: " +
051 entry.getValue());
052 }
053 }
054 finally {
055 _concurrentFailureMessages.clear();
056 }
057 }
058
059 public static void startAssert() {
060 _thread = Thread.currentThread();
061 }
062
063 private static final Map<Thread, String> _concurrentFailureMessages =
064 new ConcurrentHashMap<Thread, String>();
065 private static volatile Thread _thread;
066
067 }