use of com.emc.storageos.db.client.impl.GlobalLockImpl in project coprhd-controller by CoprHD.
the class DbGlobalLockTest method testVdcSharedGlobalLock.
@Test
public void testVdcSharedGlobalLock() throws Exception {
// VdcShared MODE
_logger.info("Starting vdc shared global lock test");
DbClientImpl dbClient = (DbClientImpl) getDbClient();
boolean flag;
String vdc = "vdc1";
String lockname = "testlock2";
GlobalLockImpl glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, vdc);
// acquire the lock
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// get lock owner
String owner = null;
owner = glock.getOwner();
Assert.assertEquals(owner, vdc);
// re-enter the lock again with the same owner
flag = glock.acquire("vipr2");
Assert.assertTrue(flag);
// acquire the lock with a different local owner within the same Vdc
GlobalLockImpl glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, vdc);
flag = glock2.acquire("vipr2");
Assert.assertTrue(flag);
// try to acquire the lock from a different vdc
GlobalLockImpl glock3 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_VdcShared_MODE, 0, "vdc2");
flag = glock3.acquire("vipr2");
Assert.assertFalse(flag);
// release the lock from vipr2
flag = glock2.release("vipr2");
Assert.assertTrue(flag);
// get lock owner
owner = glock.getOwner();
Assert.assertEquals(owner, vdc);
// release the lock from vipr1
flag = glock.release("vipr1");
Assert.assertTrue(flag);
// get lock owner again
owner = glock.getOwner();
Assert.assertEquals(owner, null);
}
Aggregations