1 19 20 package org.openide.filesystems; 21 22 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 import org.netbeans.junit.*; 26 import org.openide.util.Task; 27 28 36 public class StreamPool50137Test extends NbTestCase { 37 40 private FileSystem lfs; 41 private FileObject testFo; 42 43 public StreamPool50137Test(String name) { 44 super(name); 45 } 46 47 public static void main(String [] args) throws Exception { 48 junit.textui.TestRunner.run(new NbTestSuite(StreamPool50137Test.class)); 49 } 50 51 54 protected void setUp() throws Exception { 55 56 TestUtilHid.destroyLocalFileSystem(getName()); 57 lfs = new TestFileSystem ((LocalFileSystem)TestUtilHid.createLocalFileSystem(getName(), new String []{"TestDeadlock" })); 58 testFo = lfs.findResource("TestDeadlock"); 59 assertNotNull(testFo); 60 } 61 62 63 public void testStreamPoolDeadlock () throws Exception { 64 FileLock fLock = testFo.lock(); 65 OutputStream os = null; 66 InputStream is = null; 67 68 try { 69 os = testFo.getOutputStream(fLock); 70 os.close(); os = null; 71 is = testFo.getInputStream(); 72 is.close(); is = null; 73 } finally { 74 if (fLock != null) fLock.releaseLock(); 75 if (os != null) os.close(); 76 if (is != null) is.close(); 77 } 78 } 79 80 private static final class TestFileSystem extends LocalFileSystem { 81 TestFileSystem (LocalFileSystem lfs) throws Exception { 82 super (); 83 this.info = new TestImplInfo (this); 84 setRootDirectory(lfs.getRootDirectory()); 85 } 86 } 87 88 private static final class TestImplInfo extends LocalFileSystem.Impl { 89 private final TestFileSystem tfs; 90 TestImplInfo (TestFileSystem tfs) { 91 super (tfs); 92 this.tfs = tfs; 93 94 } 95 96 public OutputStream outputStream(String name) throws java.io.IOException { 97 OutputStream retValue = super.outputStream(name); 98 deadlockSimulation (); 99 return retValue; 100 } 101 102 public InputStream inputStream(String name) throws java.io.FileNotFoundException { 103 InputStream retValue = super.inputStream(name); 104 deadlockSimulation (); 105 return retValue; 106 } 107 108 109 private void deadlockSimulation() { 110 Task task = org.openide.util.RequestProcessor.getDefault().post(new Runnable () { 111 public void run() { 112 StreamPool.find(tfs); 113 } 114 }); 115 task.waitFinished(); 116 } 117 118 } 119 120 } 121 122 123 | Popular Tags |