1 19 20 package org.netbeans.modules.masterfs; 21 22 import java.io.File ; 23 import junit.framework.Test; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.junit.NbTestSuite; 26 import org.openide.filesystems.FileAttributeEvent; 27 import org.openide.filesystems.FileChangeListener; 28 import org.openide.filesystems.FileEvent; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileRenameEvent; 31 import org.openide.filesystems.FileSystem; 32 import org.openide.filesystems.FileUtil; 33 34 37 public class Deadlock54741 extends NbTestCase { 38 39 private static class DelFileChangeListener implements FileChangeListener { 40 public void fileAttributeChanged(FileAttributeEvent fe) { 41 } 42 43 public void fileChanged(FileEvent fe) { 44 } 45 46 public void fileDataCreated(FileEvent fe) { 47 } 48 49 public void fileDeleted(FileEvent fe) { 50 try { 51 synchronized (this) { 52 wait(); 53 } 54 } catch (InterruptedException e) { 55 e.printStackTrace(); 56 } 57 } 58 59 public void fileFolderCreated(FileEvent fe) { 60 } 61 62 public void fileRenamed(FileRenameEvent fe) { 63 } 64 65 } 66 67 private static class DeleteRunnable implements Runnable { 68 FileObject fo; 69 public DeleteRunnable(FileObject fo) { 70 this.fo = fo; 71 } 72 public void run() { 73 System.out.println("start delete"); 74 try { 75 fo.getFileSystem().addFileChangeListener(new DelFileChangeListener()); 76 FileSystem fs = fo.getFileSystem(); 77 FileUtil.toFile(fo).delete(); 78 fs.refresh(true); 79 } catch (Exception e) { 80 e.printStackTrace(); 81 } 82 System.out.println("end delete"); 83 } 84 } 85 86 static { 87 System.setProperty("org.openide.util.Lookup", MasterFileSystemTest.TestLookup.class.getName()); 88 } 89 90 public Deadlock54741(String testName) { 91 super(testName); 92 } 93 94 public void testDeadLock () throws Exception { 95 File f = File.createTempFile("fff","fsdfsd"); 96 FileObject tmpFo = FileUtil.toFileObject(f.getParentFile()); 97 assertNotNull(tmpFo); 98 99 FileObject fo = null; 100 fo = tmpFo.createData("ssss"); 101 Runnable deleteRunnable = new DeleteRunnable(fo); 102 Thread thread = new Thread (deleteRunnable); 103 thread.start(); 104 105 try { 106 Thread.currentThread().sleep(2000); 107 boolean isDeadlock [] = new boolean[1]; 108 makeDeadlock(tmpFo,f, isDeadlock); 109 Thread.sleep(2000); 110 boolean isD = isDeadlock[0]; 111 deleteRunnable.notify(); 113 assertFalse("deadlock!!!",isD); 114 } catch (InterruptedException ie) { 115 ie.printStackTrace(); 116 } 117 118 } 119 private Thread makeDeadlock(final FileObject fo, final File f,final boolean isDeadLock[]) { 120 isDeadLock[0] = true; 121 Thread t = new Thread () { 122 public void run() { 123 fo.getFileObject(f.getName()); 124 isDeadLock[0] = false; 125 }}; 126 t.start(); 127 return t; 128 } 129 130 public static Test suite() { 131 NbTestSuite suite = new NbTestSuite(); 132 suite.addTestSuite(Deadlock54741.class); 133 134 return new MasterFileSystemTest(suite); 135 } 136 } 137 | Popular Tags |