hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [hadoop] bharatviswa504 commented on a change in pull request #1564: HDDS-2223. Support ReadWrite lock in LockManager.
Date Tue, 01 Oct 2019 22:27:18 GMT
bharatviswa504 commented on a change in pull request #1564: HDDS-2223. Support ReadWrite lock
in LockManager.
URL: https://github.com/apache/hadoop/pull/1564#discussion_r330304195
 
 

 ##########
 File path: hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/lock/TestLockManager.java
 ##########
 @@ -29,34 +29,143 @@
 public class TestLockManager {
 
   @Test(timeout = 1000)
-  public void testWithDifferentResource() {
-    LockManager<String> manager = new LockManager<>(new OzoneConfiguration());
-    manager.lock("/resourceOne");
+  public void testWriteLockWithDifferentResource() {
+    final LockManager<String> manager =
+        new LockManager<>(new OzoneConfiguration());
+    manager.writeLock("/resourceOne");
     // This should work, as they are different resource.
-    manager.lock("/resourceTwo");
-    manager.unlock("/resourceOne");
-    manager.unlock("/resourceTwo");
+    manager.writeLock("/resourceTwo");
+    manager.writeUnlock("/resourceOne");
+    manager.writeUnlock("/resourceTwo");
     Assert.assertTrue(true);
   }
 
   @Test
-  public void testWithSameResource() throws Exception {
-    LockManager<String> manager = new LockManager<>(new OzoneConfiguration());
-    manager.lock("/resourceOne");
-    AtomicBoolean gotLock = new AtomicBoolean(false);
+  public void testWriteLockWithSameResource() throws Exception {
+    final LockManager<String> manager =
+        new LockManager<>(new OzoneConfiguration());
+    final AtomicBoolean gotLock = new AtomicBoolean(false);
+    manager.writeLock("/resourceOne");
     new Thread(() -> {
-      manager.lock("/resourceOne");
+      manager.writeLock("/resourceOne");
       gotLock.set(true);
-      manager.unlock("/resourceOne");
+      manager.writeUnlock("/resourceOne");
     }).start();
-    // Let's give some time for the new thread to run
+    // Let's give some time for the other thread to run
     Thread.sleep(100);
-    // Since the new thread is trying to get lock on same object, it will wait.
+    // Since the other thread is trying to get write lock on same object,
+    // it will wait.
     Assert.assertFalse(gotLock.get());
-    manager.unlock("/resourceOne");
-    // Since we have released the lock, the new thread should have the lock
-    // now
-    // Let's give some time for the new thread to run
+    manager.writeUnlock("/resourceOne");
+    // Since we have released the write lock, the other thread should have
+    // the lock now
+    // Let's give some time for the other thread to run
+    Thread.sleep(100);
+    Assert.assertTrue(gotLock.get());
+  }
+
+  @Test(timeout = 1000)
+  public void testReadLockWithDifferentResource() {
+    final LockManager<String> manager =
+        new LockManager<>(new OzoneConfiguration());
+    manager.readLock("/resourceOne");
+    manager.readLock("/resourceTwo");
+    manager.readUnlock("/resourceOne");
+    manager.readUnlock("/resourceTwo");
+    Assert.assertTrue(true);
+  }
+
+  @Test
+  public void testReadLockWithSameResource() throws Exception {
+    final LockManager<String> manager =
+        new LockManager<>(new OzoneConfiguration());
+    final AtomicBoolean gotLock = new AtomicBoolean(false);
+    manager.readLock("/resourceOne");
+    new Thread(() -> {
+      manager.readLock("/resourceOne");
+      gotLock.set(true);
+      manager.readUnlock("/resourceOne");
+    }).start();
+    // Let's give some time for the other thread to run
 
 Review comment:
   Here we don't need sleep as the test acquire readLock.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org


Mime
View raw message