public AcquireLockCommandAnonymousInnerClass4(LockWorker outerInstance, long resource) { this.outerInstance = outerInstance; this._resource = resource; }
public AcquireLockCommandAnonymousInnerClass(LockWorker outerInstance, long resource, bool wait) { this.outerInstance = outerInstance; this._resource = resource; this._wait = wait; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testMultipleThreads() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TestMultipleThreads() { LockWorker t1 = new LockWorker("T1", Locks); LockWorker t2 = new LockWorker("T2", Locks); LockWorker t3 = new LockWorker("T3", Locks); LockWorker t4 = new LockWorker("T4", Locks); long r1 = 1L; try { t1.GetReadLock(r1, true); t2.GetReadLock(r1, true); t3.GetReadLock(r1, true); Future <Void> t4Wait = t4.GetWriteLock(r1, false); t3.ReleaseReadLock(r1); t2.ReleaseReadLock(r1); assertTrue(!t4Wait.Done); t1.ReleaseReadLock(r1); // now we can wait for write lock since it can be acquired // get write lock t4.AwaitFuture(t4Wait); t4.GetReadLock(r1, true); t4.GetReadLock(r1, true); // put readlock in queue Future <Void> t1Wait = t1.GetReadLock(r1, false); t4.GetReadLock(r1, true); t4.ReleaseReadLock(r1); t4.GetWriteLock(r1, true); t4.ReleaseWriteLock(r1); assertTrue(!t1Wait.Done); t4.ReleaseWriteLock(r1); // get read lock t1.AwaitFuture(t1Wait); t4.ReleaseReadLock(r1); // t4 now has 1 readlock and t1 one readlock // let t1 drop readlock and t4 get write lock t4Wait = t4.GetWriteLock(r1, false); t1.ReleaseReadLock(r1); t4.AwaitFuture(t4Wait); t4.ReleaseReadLock(r1); t4.ReleaseWriteLock(r1); t4.GetWriteLock(r1, true); t1Wait = t1.GetReadLock(r1, false); Future <Void> t2Wait = t2.GetReadLock(r1, false); Future <Void> t3Wait = t3.GetReadLock(r1, false); t4.GetReadLock(r1, true); t4.ReleaseWriteLock(r1); t1.AwaitFuture(t1Wait); t2.AwaitFuture(t2Wait); t3.AwaitFuture(t3Wait); t1Wait = t1.GetWriteLock(r1, false); t2.ReleaseReadLock(r1); t4.ReleaseReadLock(r1); t3.ReleaseReadLock(r1); t1.AwaitFuture(t1Wait); t1.ReleaseWriteLock(r1); t2.GetReadLock(r1, true); t1.ReleaseReadLock(r1); t2.GetWriteLock(r1, true); t2.ReleaseWriteLock(r1); t2.ReleaseReadLock(r1); } catch (Exception e) { LockWorkFailureDump dumper = new LockWorkFailureDump(TestDir.file(this.GetType().Name)); File file = dumper.DumpState(Locks, t1, t2, t3, t4); throw new Exception("Failed, forensics information dumped to " + file.AbsolutePath, e); } finally { t1.Dispose(); t2.Dispose(); t3.Dispose(); t4.Dispose(); } }