mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extracted joinAll()
This commit is contained in:
@@ -37,6 +37,7 @@ import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.SkipSlowTestLocally;
|
||||
import com.intellij.testFramework.Timings;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -111,9 +112,7 @@ public class PsiConcurrencyStressTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
assertTrue("Timed out", reads.await(5, TimeUnit.MINUTES));
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}
|
||||
|
||||
private static void mark(final String s) {
|
||||
|
||||
+4
-9
@@ -33,6 +33,7 @@ import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import com.intellij.testFramework.LoggedErrorProcessor;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
@@ -156,9 +157,7 @@ public class ApplicationImplTest extends LightPlatformTestCase {
|
||||
}
|
||||
//System.out.println("write end");
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
threads.clear();
|
||||
}).cpuBound().assertTiming();
|
||||
}
|
||||
@@ -405,9 +404,7 @@ public class ApplicationImplTest extends LightPlatformTestCase {
|
||||
LOG.append("\nfinished write action");
|
||||
});
|
||||
main.join();
|
||||
for (Thread thread : readThreads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(readThreads);
|
||||
|
||||
if (exception != null) {
|
||||
System.err.println(LOG);
|
||||
@@ -528,9 +525,7 @@ public class ApplicationImplTest extends LightPlatformTestCase {
|
||||
thread.start();
|
||||
threads.add(thread);
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}).cpuBound().usesAllCPUCores().assertTiming();
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -34,6 +34,7 @@ import com.intellij.testFramework.LightPlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -186,9 +187,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
|
||||
}
|
||||
}, indicator), "indicator test"));
|
||||
threads.forEach(Thread::start);
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}
|
||||
if (exception != null) throw exception;
|
||||
}
|
||||
|
||||
+2
-8
@@ -41,6 +41,7 @@ import com.intellij.openapi.vfs.pointers.VirtualFilePointerListener;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -927,14 +928,7 @@ public class VirtualFilePointerTest extends PlatformTestCase {
|
||||
VirtualFilePointer bc = VirtualFilePointerManager.getInstance().create(fileToCreatePointer.getUrl() + "/b/c", disposable, listener);
|
||||
|
||||
run = false;
|
||||
threads.forEach(thread -> {
|
||||
try {
|
||||
thread.join();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
if (exception !=null) throw exception;
|
||||
Disposer.dispose(disposable);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.intellij.util.messages;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.messages.impl.MessageBusImpl;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -301,9 +302,7 @@ public class MessageBusTest extends TestCase {
|
||||
if (e != null) {
|
||||
throw e;
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -172,4 +172,18 @@ public class ConcurrencyUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void joinAll(@NotNull Collection<? extends Thread> threads) throws RuntimeException {
|
||||
for (Thread thread : threads) {
|
||||
try {
|
||||
thread.join();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void joinAll(@NotNull Thread... threads) throws RuntimeException {
|
||||
joinAll(Arrays.asList(threads));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.util.containers;
|
||||
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ConcurrentBitSetTest extends TestCase {
|
||||
@@ -86,9 +87,7 @@ public class ConcurrentBitSetTest extends TestCase {
|
||||
threads[i] = thread;
|
||||
thread.start();
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
|
||||
assertEquals(-1, bitSet.nextSetBit(0));
|
||||
}
|
||||
@@ -109,9 +108,7 @@ public class ConcurrentBitSetTest extends TestCase {
|
||||
threads[i] = thread;
|
||||
thread.start();
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
|
||||
assertEquals(-1, bitSet.nextSetBit(0));
|
||||
}
|
||||
|
||||
+2
-3
@@ -19,6 +19,7 @@ import com.intellij.openapi.progress.EmptyProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
|
||||
import com.intellij.testFramework.vcs.FileBasedTest;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.ThrowableConvertor;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
@@ -223,9 +224,7 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
|
||||
Assert.assertEquals(0, group.getInactiveSize());
|
||||
}
|
||||
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}
|
||||
|
||||
private boolean timeout(long start) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.semantic.SemService;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.Timings;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -141,9 +142,7 @@ public class DomConcurrencyStressTest extends DomTestCase {
|
||||
if (!exc.isNull()) {
|
||||
throw exc.get();
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
thread.join();
|
||||
}
|
||||
ConcurrencyUtil.joinAll(threads);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user