rakeshadr commented on code in PR #3271:
URL: https://github.com/apache/ozone/pull/3271#discussion_r845052294


##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/lock/TestOzoneManagerLock.java:
##########
@@ -393,41 +393,177 @@ private void 
testReadLockHoldCountUtil(OzoneManagerLock.Resource resource,
 
     lock.releaseReadLock(resource, resourceName);
     assertEquals(0, lock.getReadHoldCount(resourceLockName));
+
+    Assert.assertFalse(lock.isWriteLockedByCurrentThread(resourceLockName));
+    assertEquals(0, lock.getWriteHoldCount(resourceLockName));
+    lock.acquireWriteLock(resource, resourceName);
+    Assert.assertTrue(lock.isWriteLockedByCurrentThread(resourceLockName));
+    assertEquals(1, lock.getWriteHoldCount(resourceLockName));
+
+    lock.acquireWriteLock(resource, resourceName);
+    Assert.assertTrue(lock.isWriteLockedByCurrentThread(resourceLockName));
+    assertEquals(2, lock.getWriteHoldCount(resourceLockName));
+
+    lock.releaseWriteLock(resource, resourceName);
+    Assert.assertTrue(lock.isWriteLockedByCurrentThread(resourceLockName));
+    assertEquals(1, lock.getWriteHoldCount(resourceLockName));
+
+    lock.releaseWriteLock(resource, resourceName);
+    Assert.assertFalse(lock.isWriteLockedByCurrentThread(resourceLockName));
+    assertEquals(0, lock.getWriteHoldCount(resourceLockName));
   }
 
   @Test
-  public void testReadLockConcurrentStats() throws InterruptedException {
+  public void testLockConcurrentStats() throws InterruptedException {
     String[] resourceName;
     for (OzoneManagerLock.Resource resource :
         OzoneManagerLock.Resource.values()) {
       resourceName = generateResourceName(resource);
+      testReadLockConcurrentStats(resource, resourceName, 10);
+      testWriteLockConcurrentStats(resource, resourceName, 5);
+      testSyntheticReadWriteLockConcurrentStats(resource, resourceName, 10, 3);
+    }
+  }
 
-      OzoneManagerLock lock = new OzoneManagerLock(new OzoneConfiguration());
-      final int threadCount = 10;
-      Thread[] threads = new Thread[threadCount];
 
-      for (int i = 0; i < threads.length; i++) {
-        String[] finalResourceName = resourceName;
-        threads[i] = new Thread(() -> {
-          lock.acquireReadLock(resource, finalResourceName);
-          try {
-            Thread.sleep(1000);
-          } catch (InterruptedException e) {
-            e.printStackTrace();
-          }
-          lock.releaseReadLock(resource, finalResourceName);
-        });
-        threads[i].start();
-      }
+  public void testReadLockConcurrentStats(OzoneManagerLock.Resource resource,
+                                          String[] resourceName,
+                                          int threadCount)
+      throws InterruptedException {
+    OzoneManagerLock lock = new OzoneManagerLock(new OzoneConfiguration());
+    Thread[] threads = new Thread[threadCount];
+
+    for (int i = 0; i < threads.length; i++) {
+      threads[i] = new Thread(() -> {
+        lock.acquireReadLock(resource, resourceName);
+        try {
+          Thread.sleep(1000);
+        } catch (InterruptedException e) {
+          e.printStackTrace();
+        }
+        lock.releaseReadLock(resource, resourceName);
+      });
+      threads[i].start();
+    }
 
-      for (Thread t : threads) {
-        t.join();
-      }
+    for (Thread t : threads) {
+      t.join();
+    }
+
+    String readHeldStat = lock.getReadLockHeldTimeMsStat();
+    Assert.assertTrue(
+        "Expected " + threadCount +
+            " samples in readLockHeldTimeMsStat: " + readHeldStat,
+        readHeldStat.contains("Samples = " + threadCount));
+
+    String readWaitingStat = lock.getReadLockWaitingTimeMsStat();
+    Assert.assertTrue(
+        "Expected " + threadCount +
+            " samples in readLockWaitingTimeMsStat: " + readWaitingStat,
+        readWaitingStat.contains("Samples = " + threadCount));
+  }
+
+  public void testWriteLockConcurrentStats(OzoneManagerLock.Resource resource,
+                                           String[] resourceName,
+                                           int threadCount)
+      throws InterruptedException {
+    OzoneManagerLock lock = new OzoneManagerLock(new OzoneConfiguration());
+    Thread[] threads = new Thread[threadCount];
 
-      String readHeldStat = lock.getReadLockHeldTimeMsStat();
-      Assert.assertTrue(
-          "Expected " + threadCount + " samples in " + readHeldStat,
-          readHeldStat.contains("Samples = " + threadCount));
+    for (int i = 0; i < threads.length; i++) {
+      threads[i] = new Thread(() -> {
+        lock.acquireWriteLock(resource, resourceName);
+        try {
+          Thread.sleep(500);

Review Comment:
   Can you reduce sleep time to run the test quickly .
   write Thread sleeping time -> Thread.sleep(100);



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to