use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testUrlsHavingOnlyStartingSlashInCommon.
public void testUrlsHavingOnlyStartingSlashInCommon() throws Exception {
VirtualFilePointer p1 = myVirtualFilePointerManager.create("file:///a/p1", disposable, null);
VirtualFilePointer p2 = myVirtualFilePointerManager.create("file:///b/p2", disposable, null);
final LightVirtualFile root = new LightVirtualFile("/");
LightVirtualFile a = createLightFile(root, "a");
LightVirtualFile b = createLightFile(root, "b");
assertSameElements(myVirtualFilePointerManager.getPointersUnder(a, "p1"), p1);
assertSameElements(myVirtualFilePointerManager.getPointersUnder(b, "p2"), p2);
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testThreadsPerformance.
public void testThreadsPerformance() throws IOException, InterruptedException, TimeoutException, ExecutionException {
final File ioTempDir = createTempDirectory();
final File ioPtrBase = new File(ioTempDir, "parent");
final File ioPtr = new File(ioPtrBase, "f1");
final File ioSand = new File(ioTempDir, "sand");
final File ioSandPtr = new File(ioSand, "f2");
assertTrue(ioSandPtr.getParentFile().mkdirs());
assertTrue(ioSandPtr.createNewFile());
assertTrue(ioPtr.getParentFile().mkdirs());
assertTrue(ioPtr.createNewFile());
doVfsRefresh(ioTempDir);
final VirtualFilePointer pointer = createPointerByFile(ioPtr, null);
assertTrue(pointer.isValid());
final VirtualFile virtualFile = pointer.getFile();
assertNotNull(virtualFile);
assertTrue(virtualFile.isValid());
final Collection<Job<Void>> reads = ContainerUtil.newConcurrentSet();
VirtualFileAdapter listener = new VirtualFileAdapter() {
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
stressRead(pointer, reads);
}
@Override
public void fileDeleted(@NotNull VirtualFileEvent event) {
stressRead(pointer, reads);
}
};
Disposable disposable = Disposer.newDisposable();
VirtualFileManager.getInstance().addVirtualFileListener(listener, disposable);
try {
int N = Timings.adjustAccordingToMySpeed(1000, false);
System.out.println("N = " + N);
for (int i = 0; i < N; i++) {
assertNotNull(pointer.getFile());
FileUtil.delete(ioPtrBase);
doVfsRefresh(ioTempDir);
// ptr is now null, cached as map
final VirtualFile v = LocalFileSystem.getInstance().findFileByIoFile(ioSandPtr);
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
//inc FS modCount
v.delete(this);
LocalFileSystem.getInstance().findFileByIoFile(ioSand).createChildData(this, ioSandPtr.getName());
}
}.execute().throwException();
// ptr is still null
assertTrue(ioPtrBase.mkdirs());
assertTrue(ioPtr.createNewFile());
stressRead(pointer, reads);
doVfsRefresh(ioTempDir);
}
} finally {
// unregister listener early
Disposer.dispose(disposable);
for (Job<Void> read : reads) {
while (!read.isDone()) {
read.waitForCompletion(1000);
}
}
}
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testDoubleDispose.
public void testDoubleDispose() throws IOException {
final File tempDir = createTempDirectory();
final File file = new File(tempDir, "f1");
boolean created = file.createNewFile();
assertTrue(created);
final String url = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, file.getCanonicalPath().replace(File.separatorChar, '/'));
final VirtualFile vFile = refreshAndFind(url);
Disposable disposable = Disposer.newDisposable();
final VirtualFilePointer pointer = myVirtualFilePointerManager.create(vFile, disposable, new VirtualFilePointerListener() {
});
assertTrue(pointer.isValid());
Disposer.dispose(disposable);
assertFalse(pointer.isValid());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testAlienVirtualFileSystemPointerRemovedFromUrlToIdentityCacheOnDispose.
public void testAlienVirtualFileSystemPointerRemovedFromUrlToIdentityCacheOnDispose() throws IOException {
VirtualFile mockVirtualFile = new MockVirtualFile("test_name", "test_text");
Disposable disposable1 = Disposer.newDisposable();
final VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(mockVirtualFile, disposable1, null);
assertInstanceOf(pointer, IdentityVirtualFilePointer.class);
assertTrue(pointer.isValid());
VirtualFile virtualFileWithSameUrl = new MockVirtualFile("test_name", "test_text");
VirtualFilePointer updatedPointer = VirtualFilePointerManager.getInstance().create(virtualFileWithSameUrl, disposable1, null);
assertInstanceOf(updatedPointer, IdentityVirtualFilePointer.class);
assertEquals(1, ((VirtualFilePointerManagerImpl) VirtualFilePointerManager.getInstance()).numberOfCachedUrlToIdentity());
Disposer.dispose(disposable1);
assertEquals(0, ((VirtualFilePointerManagerImpl) VirtualFilePointerManager.getInstance()).numberOfCachedUrlToIdentity());
}
use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testFilePointerUpdate.
public void testFilePointerUpdate() throws Exception {
final File tempDir = createTempDirectory();
final File file = new File(tempDir, "f1");
final VirtualFilePointer pointer = createPointerByFile(file, null);
assertFalse(pointer.isValid());
boolean created = file.createNewFile();
assertTrue(created);
doVfsRefresh(tempDir);
assertTrue(pointer.isValid());
boolean deleted = file.delete();
assertTrue(deleted);
doVfsRefresh(tempDir);
assertFalse(pointer.isValid());
}
Aggregations