smengcl commented on code in PR #3725:
URL: https://github.com/apache/ozone/pull/3725#discussion_r960218606
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java:
##########
@@ -132,14 +132,15 @@ public void
testUnlockWriteInOMRequestShouldNotThrowOnFollowerOMs() {
}
@Test
- public void testIsWriteLockHeldByCurrentThread() throws IOException {
+ public void testIsWriteLockHeldByCurrentThread() throws IOException,
+ InterruptedException {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
Assert.assertFalse(authorizerLock.isWriteLockHeldByCurrentThread());
// Read lock does not affect the check
- long readLockStamp = authorizerLock.tryReadLockThrowOnTimeout();
+ long readLockStamp = authorizerLock.tryReadLock(100);
Review Comment:
nit
```suggestion
long readLockStamp = authorizerLock.tryReadLock(100L);
```
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java:
##########
@@ -153,4 +154,38 @@ public void testIsWriteLockHeldByCurrentThread() throws
IOException {
Assert.assertFalse(authorizerLock.isWriteLockHeldByCurrentThread());
authorizerLock.unlockWrite(writeLockStamp);
}
+
+ @Test
+ public void testOptimisticRead() throws Exception {
+ final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
+
+ // With no competing operations, an optimistic read should be valid.
+ long stamp = authorizerLock.tryOptimisticReadThrowOnTimeout();
+ Assert.assertTrue(authorizerLock.validateOptimisticRead(stamp));
+
+ // With only competing reads, an optimistic read should be valid.
+ long optStamp = authorizerLock.tryOptimisticReadThrowOnTimeout();
+ long readStamp = authorizerLock.tryReadLock(100);
Review Comment:
```suggestion
long readStamp = authorizerLock.tryReadLock(100L);
```
--
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]