Search in sources :

Example 51 with VirtualFilePointer

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);
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 52 with VirtualFilePointer

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);
            }
        }
    }
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) Disposable(com.intellij.openapi.Disposable) NotNull(org.jetbrains.annotations.NotNull) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) Job(com.intellij.concurrency.Job) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File)

Example 53 with VirtualFilePointer

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());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) Disposable(com.intellij.openapi.Disposable) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 54 with VirtualFilePointer

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());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) Disposable(com.intellij.openapi.Disposable) MockVirtualFile(com.intellij.mock.MockVirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 55 with VirtualFilePointer

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());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2