use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class CompilerTestUtil method enableExternalCompiler.
@TestOnly
public static void enableExternalCompiler() {
final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
new WriteAction() {
@Override
protected void run(@NotNull final Result result) {
table.addJdk(table.getInternalJdk());
}
}.execute();
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class FileManagerImpl method checkConsistency.
@TestOnly
public void checkConsistency() {
Map<VirtualFile, FileViewProvider> fileToViewProvider = new HashMap<>(myVFileToViewProviderMap);
myVFileToViewProviderMap.clear();
for (VirtualFile vFile : fileToViewProvider.keySet()) {
final FileViewProvider fileViewProvider = fileToViewProvider.get(vFile);
LOG.assertTrue(vFile.isValid());
PsiFile psiFile1 = findFile(vFile);
if (psiFile1 != null && fileViewProvider != null && fileViewProvider.isPhysical()) {
// might get collected
PsiFile psi = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
assert psi != null : fileViewProvider + "; " + fileViewProvider.getBaseLanguage() + "; " + psiFile1;
assert psiFile1.getClass().equals(psi.getClass()) : psiFile1 + "; " + psi + "; " + psiFile1.getClass() + "; " + psi.getClass();
}
}
HashMap<VirtualFile, PsiDirectory> fileToPsiDirMap = new HashMap<>(myVFileToPsiDirMap);
myVFileToPsiDirMap.clear();
for (VirtualFile vFile : fileToPsiDirMap.keySet()) {
LOG.assertTrue(vFile.isValid());
PsiDirectory psiDir1 = findDirectory(vFile);
LOG.assertTrue(psiDir1 != null);
VirtualFile parent = vFile.getParent();
if (parent != null) {
LOG.assertTrue(myVFileToPsiDirMap.containsKey(parent));
}
}
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method disableBackgroundCommit.
@TestOnly
public void disableBackgroundCommit(@NotNull Disposable parentDisposable) {
assert myPerformBackgroundCommit;
myPerformBackgroundCommit = false;
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
myPerformBackgroundCommit = true;
}
});
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class PsiManagerImpl method setAssertOnFileLoadingFilter.
@Override
@TestOnly
public void setAssertOnFileLoadingFilter(@NotNull VirtualFileFilter filter, @NotNull Disposable parentDisposable) {
// Find something to ensure there's no changed files waiting to be processed in repository indices.
myAssertOnFileLoadingFilter = filter;
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
myAssertOnFileLoadingFilter = VirtualFileFilter.NONE;
}
});
}
use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.
the class ConcurrencyUtil method awaitQuiescence.
/**
* Awaits for all tasks in the {@code executor} to finish for the specified {@code timeout}
*/
@TestOnly
public static void awaitQuiescence(@NotNull ThreadPoolExecutor executor, long timeout, @NotNull TimeUnit unit) {
// no need for zombies in tests
executor.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
// interrupt idle workers
executor.setCorePoolSize(0);
ReentrantLock mainLock = ReflectionUtil.getField(executor.getClass(), executor, ReentrantLock.class, "mainLock");
Set workers;
mainLock.lock();
try {
HashSet workersField = ReflectionUtil.getField(executor.getClass(), executor, HashSet.class, "workers");
// to be able to iterate thread-safely outside the lock
workers = new HashSet(workersField);
} finally {
mainLock.unlock();
}
for (Object worker : workers) {
Thread thread = ReflectionUtil.getField(worker.getClass(), worker, Thread.class, "thread");
try {
thread.join(unit.toMillis(timeout));
} catch (InterruptedException e) {
String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
for (final StackTraceElement stackTraceElement : thread.getStackTrace()) {
trace += " at " + stackTraceElement + "\n";
}
trace += "---\n";
System.err.println("Executor " + executor + " is still active after " + unit.toSeconds(timeout) + " seconds://///\n" + "Thread " + thread + " dump:\n" + trace + "all thread dump:\n" + ThreadDumper.dumpThreadsToString() + "\n/////");
break;
}
}
}
Aggregations