Index: test/unit/src/org/openide/text/Deadlock40766Test.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/text/Deadlock40766Test.java,v retrieving revision 1.1 diff -u -r1.1 Deadlock40766Test.java --- test/unit/src/org/openide/text/Deadlock40766Test.java 11 Mar 2004 09:43:55 -0000 1.1 +++ test/unit/src/org/openide/text/Deadlock40766Test.java 12 Mar 2004 10:42:11 -0000 @@ -36,10 +36,8 @@ import org.openide.util.RequestProcessor; /** - * Exception during load of the document can cause starvation - * in the thread that waits for that to happen. * - * @author Jaroslav Tulach + * @author Petr Nejedly, Jaroslav Tulach */ public class Deadlock40766Test extends NbTestCase implements CloneableEditorSupport.Env { /** the support to work with */ @@ -107,6 +105,50 @@ }); } + + + public void testCreatePositionCanBeCalledFromWriteLockOnDocument () throws Exception { + final StyledDocument doc = support.openDocument (); + + class R implements Runnable { + boolean inAtomic; + PositionRef ref; + + public void run () { + if (!inAtomic) { + inAtomic = true; + NbDocument.runAtomic (doc, this); + return; + } + + synchronized (this) { + notifyAll (); + try { + wait (1000); + } catch (InterruptedException ex) { + fail (ex.getMessage ()); + } + } + ref = support.createPositionRef (0, Position.Bias.Backward); + } + } + + RequestProcessor.Task task; + R r = new R (); + synchronized (r) { + task = RequestProcessor.getDefault ().post (r); + r.wait (); + } + + // now R holds write lock on the document, and will wake up soon + // grab the lock from oposite site + PositionRef ref = support.createPositionRef (1, Position.Bias.Backward); + + assertNotNull ("Ref created", ref); + task.waitFinished (); + assertNotNull ("Ref1 crated", r.ref); + + } // end of testCreatePositionCanBeCalledFromWriteLockOnDocument // // Implementation of the CloneableEditorSupport.Env