use of org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl in project ozone by apache.
the class TestAuthorizerLockImpl method testUnlockWriteInOMRequestShouldNotThrowOnFollowerOMs.
@Test
public void testUnlockWriteInOMRequestShouldNotThrowOnFollowerOMs() {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
// When a follower OM attempts to unlock write in validateAndUpdateCache,
// even though it hasn't acquired the lock in preExecute,
// the unlockWriteInOMRequest() method should not throw
// IllegalMonitorStateException as it should have been handled gracefully.
authorizerLock.unlockWriteInOMRequest();
}
use of org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl in project ozone by apache.
the class TestAuthorizerLockImpl method testStampedLockBehavior.
/**
* Tests StampedLock behavior.
*/
@Test
@SuppressFBWarnings("IMSE_DONT_CATCH_IMSE")
public void testStampedLockBehavior() throws InterruptedException {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
// Case 1: A correct stamp can unlock without an issue
long readLockStamp = authorizerLock.tryReadLock(100);
authorizerLock.unlockRead(readLockStamp);
long writeLockStamp = authorizerLock.tryWriteLock(100);
authorizerLock.unlockWrite(writeLockStamp);
// Case 1: An incorrect stamp won't be able to unlock, throws IMSE
readLockStamp = authorizerLock.tryReadLock(100);
try {
authorizerLock.unlockRead(readLockStamp - 1L);
Assert.fail("Should have thrown IllegalMonitorStateException");
} catch (IllegalMonitorStateException ignored) {
}
authorizerLock.unlockRead(readLockStamp);
writeLockStamp = authorizerLock.tryWriteLock(100);
try {
authorizerLock.unlockWrite(writeLockStamp - 1L);
Assert.fail("Should have thrown IllegalMonitorStateException");
} catch (IllegalMonitorStateException ignored) {
}
authorizerLock.unlockWrite(writeLockStamp);
// Case 2: Read lock is reentrant; Write lock is exclusive
long readLockStamp1 = authorizerLock.tryReadLock(100);
Assert.assertTrue(readLockStamp1 > 0L);
long readLockStamp2 = authorizerLock.tryReadLock(100);
Assert.assertTrue(readLockStamp2 > 0L);
// Can't acquire write lock now, as read lock has been held
long writeLockStamp1 = authorizerLock.tryWriteLock(100);
// stamp == 0L means lock failure
Assert.assertEquals(0L, writeLockStamp1);
// Release one read lock. Try again. Should fail
authorizerLock.unlockRead(readLockStamp2);
writeLockStamp1 = authorizerLock.tryWriteLock(100);
Assert.assertEquals(0L, writeLockStamp1);
// Release the other read lock. And again. Should work
authorizerLock.unlockRead(readLockStamp1);
writeLockStamp1 = authorizerLock.tryWriteLock(100);
Assert.assertTrue(writeLockStamp1 > 0L);
// But a second write lock won't work
long writeLockStamp2 = authorizerLock.tryWriteLock(100);
Assert.assertEquals(0L, writeLockStamp2);
// Read lock also won't work now that write lock is held
readLockStamp = authorizerLock.tryReadLock(100);
Assert.assertEquals(0L, readLockStamp);
authorizerLock.unlockWrite(writeLockStamp1);
}
use of org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl in project ozone by apache.
the class TestAuthorizerLockImpl method testLockInOneThreadUnlockInAnother.
@Test
public void testLockInOneThreadUnlockInAnother() {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
try {
authorizerLock.tryWriteLockInOMRequest();
// Spawn another thread to release the lock.
// Works as long as they share the same AuthorizerLockImpl instance.
final Thread thread1 = new Thread(authorizerLock::unlockWriteInOMRequest);
thread1.start();
} catch (IOException e) {
Assert.fail("Should not have thrown: " + e.getMessage());
}
}
use of org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl in project ozone by apache.
the class TestAuthorizerLockImpl method testIsWriteLockHeldByCurrentThread.
@Test
public void testIsWriteLockHeldByCurrentThread() throws IOException {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
Assert.assertFalse(authorizerLock.isWriteLockHeldByCurrentThread());
// Read lock does not affect the check
long readLockStamp = authorizerLock.tryReadLockThrowOnTimeout();
Assert.assertFalse(authorizerLock.isWriteLockHeldByCurrentThread());
authorizerLock.unlockRead(readLockStamp);
// Only a write lock acquired through InOMRequest variant affects the check
authorizerLock.tryWriteLockInOMRequest();
Assert.assertTrue(authorizerLock.isWriteLockHeldByCurrentThread());
authorizerLock.unlockWriteInOMRequest();
// Regular write lock does not affect the check as well
long writeLockStamp = authorizerLock.tryWriteLockThrowOnTimeout();
Assert.assertFalse(authorizerLock.isWriteLockHeldByCurrentThread());
authorizerLock.unlockWrite(writeLockStamp);
}
use of org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl in project ozone by apache.
the class TestS3GetSecretRequest method setUp.
@Before
public void setUp() throws Exception {
KerberosName.setRuleMechanism(DEFAULT_MECHANISM);
KerberosName.setRules("RULE:[2:$1@$0](.*@EXAMPLE.COM)s/@.*//\n" + "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\n" + "DEFAULT");
ugiAlice = UserGroupInformation.createRemoteUser(USER_ALICE);
Assert.assertEquals("alice", ugiAlice.getShortUserName());
ozoneManager = mock(OzoneManager.class);
Call call = spy(new Call(1, 1, null, null, RPC.RpcKind.RPC_BUILTIN, new byte[] { 1, 2, 3 }));
// Run as alice, so that Server.getRemoteUser() won't return null.
when(call.getRemoteUser()).thenReturn(ugiAlice);
Server.getCurCall().set(call);
omMetrics = OMMetrics.create();
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
// No need to conf.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, ...) here
// as we did the trick earlier with mockito.
omMetadataManager = new OmMetadataManagerImpl(conf);
when(ozoneManager.getMetrics()).thenReturn(omMetrics);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
when(ozoneManager.isRatisEnabled()).thenReturn(true);
auditLogger = mock(AuditLogger.class);
when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
// Multi-tenant related initializations
omMultiTenantManager = mock(OMMultiTenantManager.class);
tenant = mock(Tenant.class);
when(ozoneManager.getMultiTenantManager()).thenReturn(omMultiTenantManager);
when(tenant.getTenantAccessPolicies()).thenReturn(new ArrayList<>());
when(omMultiTenantManager.getAuthorizerLock()).thenReturn(new AuthorizerLockImpl());
TenantOp authorizerOp = mock(TenantOp.class);
TenantOp cacheOp = mock(TenantOp.class);
when(omMultiTenantManager.getAuthorizerOp()).thenReturn(authorizerOp);
when(omMultiTenantManager.getCacheOp()).thenReturn(cacheOp);
}
Aggregations