[
https://issues.apache.org/jira/browse/HDDS-2223?focusedWorklogId=321598&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-321598
]
ASF GitHub Bot logged work on HDDS-2223:
----------------------------------------
Author: ASF GitHub Bot
Created on: 01/Oct/19 22:27
Start Date: 01/Oct/19 22:27
Worklog Time Spent: 10m
Work Description: bharatviswa504 commented on 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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 321598)
Time Spent: 1.5h (was: 1h 20m)
> Support ReadWrite lock in LockManager
> -------------------------------------
>
> Key: HDDS-2223
> URL: https://issues.apache.org/jira/browse/HDDS-2223
> Project: Hadoop Distributed Data Store
> Issue Type: Bug
> Reporter: Nanda kumar
> Assignee: Nanda kumar
> Priority: Major
> Labels: pull-request-available
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> Currently {{LockManager}} is using exclusive lock, instead we should support
> {{ReadWrite}} lock.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]