1 19 20 package org.openide.loaders; 21 22 import junit.textui.TestRunner; 23 24 import org.openide.filesystems.*; 25 import org.openide.util.Lookup; 26 import java.io.IOException ; 27 import java.util.*; 28 import org.netbeans.junit.*; 29 import java.beans.PropertyChangeListener ; 30 31 34 public class Deadlock38554Test extends NbTestCase implements FileChangeListener { 35 private FileSystem lfs; 36 private DataObject src; 37 private DataFolder tgz; 38 private Uni loader; 39 40 public Deadlock38554Test (String name) { 41 super(name); 42 } 43 44 protected void setUp() throws Exception { 45 clearWorkDir(); 46 lfs = TestUtilHid.createLocalFileSystem(getWorkDir(), new String [] { 47 "folder/", 48 "folder/f.uni", 49 "target/" 50 }); 51 52 loader = (Uni)Uni.getLoader (Uni.class); 53 AddLoaderManuallyHid.addRemoveLoader (loader, true); 54 55 src = DataObject.find (lfs.findResource("folder/f.uni")); 56 tgz = DataFolder.findFolder(lfs.findResource("target")); 57 lfs.addFileChangeListener (this); 58 } 59 60 protected void tearDown() throws Exception { 61 lfs.removeFileChangeListener (this); 62 TestUtilHid.destroyLocalFileSystem(getName()); 63 AddLoaderManuallyHid.addRemoveLoader (loader, false); 64 } 65 66 public void testEvilSynchronziedFileChangeListenerWhenCopy () throws Exception { 67 src.copy (tgz); 68 } 69 public void testEvilSynchronziedFileChangeListenerWhenMove () throws Exception { 70 src.move (tgz); 71 } 72 public void testEvilSynchronziedFileChangeListenerWhenCreateFromTemplate () throws Exception { 73 src.createFromTemplate (tgz); 74 } 75 public void testEvilSynchronziedFileChangeListenerWhenCreateFromTemplateWithName () throws Exception { 76 src.createFromTemplate (tgz, "myNewNameOfTheObject"); 77 } 78 public void testEvilSynchronziedFileChangeListenerWhenDelete () throws Exception { 79 src.delete (); 80 } 81 public void testEvilSynchronziedFileChangeListenerWhenRename () throws Exception { 82 src.rename ("myNewName"); 83 } 84 85 89 private void block (final FileObject fo) { 90 class OtherThreadAccess implements Runnable { 91 public void run () { 92 try { 93 if (fo.isValid ()) { 94 DataObject.find (fo); } 96 } catch (DataObjectNotFoundException ex) { 97 ex.printStackTrace(); 98 fail ("Error"); 99 } 100 } 101 } 102 103 OtherThreadAccess other = new OtherThreadAccess (); 104 org.openide.util.RequestProcessor.getDefault ().post (other).waitFinished (); } 106 107 public void fileAttributeChanged (FileAttributeEvent fe) { 108 block (fe.getFile ()); 109 } 110 111 public void fileChanged (FileEvent fe) { 112 block (fe.getFile ()); 113 } 114 115 public void fileDataCreated (FileEvent fe) { 116 block (fe.getFile ()); 117 } 118 119 public void fileDeleted (FileEvent fe) { 120 block (fe.getFile ()); 121 } 122 123 public void fileFolderCreated (FileEvent fe) { 124 block (fe.getFile ()); 125 } 126 127 public void fileRenamed (FileRenameEvent fe) { 128 block (fe.getFile ()); 129 } 130 131 public static final class Uni extends UniFileLoader { 132 public Uni () { 133 super(MultiDataObject.class); 134 } 135 protected String displayName() { 136 return "UniLoader"; 137 } 138 140 protected synchronized FileObject findPrimaryFile(FileObject fo) { 141 return fo.hasExt ("uni") ? fo : null; 142 } 143 protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException { 144 return new NotifyObject (primaryFile, this); 145 } 146 protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) { 147 return new FileEntry (obj, primaryFile); 148 } 149 150 private class NotifyObject extends MultiDataObject { 151 public NotifyObject (FileObject pf, Uni uni) throws DataObjectExistsException { 152 super (pf, uni); 153 } 154 155 156 protected FileObject handleRename (String name) throws IOException { 157 return getPrimaryEntry ().rename (name); 158 } 159 160 protected void handleDelete () throws IOException { 161 getPrimaryEntry ().delete (); 162 } 163 164 protected org.openide.loaders.DataObject handleCopy (org.openide.loaders.DataFolder f) throws IOException { 165 FileObject retValue = getPrimaryEntry ().copy (f.getPrimaryFile (), "suffix"); 166 return new NotifyObject (retValue, (Uni)getLoader ()); 167 } 168 169 protected org.openide.loaders.DataShadow handleCreateShadow (org.openide.loaders.DataFolder f) throws IOException { 170 DataShadow retValue; 171 retValue = super.handleCreateShadow (f); 172 return retValue; 173 } 174 175 protected org.openide.loaders.DataObject handleCreateFromTemplate (org.openide.loaders.DataFolder df, String name) throws IOException { 176 FileObject retValue = getPrimaryEntry ().createFromTemplate (df.getPrimaryFile (), name); 177 return new NotifyObject (retValue, (Uni)getLoader ()); 178 } 179 180 protected FileObject handleMove (org.openide.loaders.DataFolder df) throws IOException { 181 FileObject retValue = FileUtil.moveFile (getPrimaryFile (), df.getPrimaryFile (), getPrimaryFile ().getNameExt ()); 182 return retValue; 183 } 184 } 185 } 186 187 188 } 189 | Popular Tags |