1 19 package org.netbeans.lib.cvsclient.admin; 20 21 import junit.framework.*; 22 import java.io.*; 23 import java.util.*; 24 import org.netbeans.lib.cvsclient.TestKit; 25 import org.netbeans.lib.cvsclient.command.*; 26 import org.netbeans.lib.cvsclient.file.FileUtils; 27 28 32 public class StandardAdminHandlerTest extends TestCase { 33 34 public StandardAdminHandlerTest(String testName) { 35 super(testName); 36 } 37 38 protected void setUp() throws Exception { 39 } 40 41 protected void tearDown() throws Exception { 42 } 43 44 public static Test suite() { 45 TestSuite suite = new TestSuite(StandardAdminHandlerTest.class); 46 47 return suite; 48 } 49 50 int test70625ThreadDone; 51 52 56 public void test70625() throws Exception { 57 try { 58 System.err.println("test70625()"); 59 60 File tmpDir = TestKit.createTmpFolder("test_StandardAdminHandlerTest"); 61 62 final File file = new File(tmpDir, "test70625"); 63 final Entry entry = new Entry(); 64 entry.setName("test70625"); 65 66 final StandardAdminHandler instance = new StandardAdminHandler(); 67 68 new File(tmpDir, "CVS").mkdirs(); 70 new File(tmpDir, "CVS/Entries.Backup").createNewFile(); 71 72 SyncTwo lock = new SyncTwo(); 73 instance.t9yBeforeRenameSync(lock); 74 75 final Runnable r = new Runnable () { 76 public void run() { 77 try { 78 instance.setEntry(file, entry); 79 } catch (IOException ex) { 80 System.err.println("Ignoring " + ex.getMessage() + " ..."); 81 } finally { 82 test70625ThreadDone ++; 83 synchronized(StandardAdminHandlerTest.this) { 84 StandardAdminHandlerTest.this.notifyAll(); 85 } 86 } 87 } 88 }; 89 90 final Runnable r2 = new Runnable () { 91 public void run() { 92 try { 93 instance.getEntry(file); 94 } catch (IOException ex) { 95 System.err.println("Ignoring " + ex.getMessage() + " ..."); 96 } finally { 97 test70625ThreadDone ++; 98 synchronized(StandardAdminHandlerTest.this) { 99 StandardAdminHandlerTest.this.notifyAll(); 100 } 101 } 102 } 103 }; 104 105 new Thread (r, "Update").start(); 106 new Thread (r2, "Annotator").start(); 107 108 synchronized(this) { 109 while (test70625ThreadDone < 2) { 110 wait(); 111 } 112 } 113 114 if (new File(tmpDir, "CVS/Entries").exists() == false) { 115 fail("CVS/Entries gone."); 116 } 117 } catch (Exception ex) { 118 ex.printStackTrace(); 119 throw ex; 120 } 121 } 122 123 private class SyncTwo implements Runnable { 124 125 int counter; 126 127 public synchronized void run() { 128 counter++; 129 Thread.dumpStack(); 130 while (counter < 2) { 131 try { 132 System.err.println(Thread.currentThread().getName() + " is waiting for sibling..."); 133 wait(100); return; 135 } catch (InterruptedException ex) { 136 ex.printStackTrace(); 137 } 138 } 139 notifyAll(); 140 } 141 } 142 143 } 144 | Popular Tags |