Ejemplo n.º 1
0
 public void TestReadWriteLock()
 {
     var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString()));
     testDir.Create();
     var locker = new DirectoryLocker(testDir.FullName);
     locker.ReadWriteLock();
     Assert.AreEqual(1, testDir.GetFiles("readwrite.lock").Count());
 }
Ejemplo n.º 2
0
 public void TestStaticWriteUnlock()
 {
     var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString()));
     testDir.Create();
     var locker = new DirectoryLocker(testDir.FullName);
     locker.WriteLock();
     Assert.AreEqual(1, testDir.GetFiles("write*.lock").Count());
     DirectoryLocker.WriteUnlock(locker.LockerId, testDir.FullName);
     Assert.AreEqual(0, testDir.GetFiles("write*.lock").Count());
 }
Ejemplo n.º 3
0
 public void TestIsReadWriteLocked()
 {
     var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString()));
     testDir.Create();
     using (var lockFile = File.Create(Path.Combine(testDir.FullName, "readwrite.lock"))) { }
     var locker = new DirectoryLocker(testDir.FullName);
     Assert.IsTrue(locker.IsReadWriteLocked);
 }
Ejemplo n.º 4
0
 private void WriteUnLock(DirectoryLocker locker, int waitSeconds)
 {
     Thread.Sleep(waitSeconds * 1000);
     locker.WriteUnlock();
 }
Ejemplo n.º 5
0
 public void TestWaitWriteUnlock()
 {
     var testDir = new DirectoryInfo(Path.Combine(tempDir.FullName, Guid.NewGuid().ToString()));
     testDir.Create();
     var testLocker = new DirectoryLocker(testDir.FullName);
     testLocker.WriteLock();
     Task.Factory.StartNew(() =>
     {
         WriteUnLock(testLocker, 10);
     });
     var start = DateTime.Now;
     testLocker.WaitWriteUnlock(100, 1000);
     var finish = DateTime.Now;
     var delta = finish - start;
     Assert.IsTrue(delta.TotalSeconds > 7);
 }