use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class DbGlobalLockTest method testNodesvcSharedGlobalLock.
@Test
public void testNodesvcSharedGlobalLock() throws Exception {
// NodeSvcShared MODE
_logger.info("Starting node/svc shared global lock test");
DbClientImpl dbClient = (DbClientImpl) getDbClient();
boolean flag;
String vdc = "vdc1";
// 1. basic test
String lockname = "testlock1";
GlobalLockImpl glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_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, "vdc1:vipr1");
// re-enter the lock again with the same owner
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// try to acquire the lock with a different owner
GlobalLockImpl glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 0, vdc);
flag = glock2.acquire("vipr2");
Assert.assertFalse(flag);
// try to release the lock with a different owner
flag = glock2.release("vipr2");
Assert.assertFalse(flag);
// release the lock
flag = glock.release("vipr1");
Assert.assertTrue(flag);
// 2. timeout test
glock = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 3000, vdc);
// acquire the lock
flag = glock.acquire("vipr1");
Assert.assertTrue(flag);
// try to acquire the lock with a different owner
glock2 = new GlobalLockImpl(dbClient, lockname, GlobalLock.GL_Mode.GL_NodeSvcShared_MODE, 3000, vdc);
flag = glock2.acquire("vipr2");
Assert.assertFalse(flag);
// acquire the lock (expired) again with a different owner
Thread.sleep(3000);
flag = glock2.acquire("vipr2");
Assert.assertTrue(flag);
// try to release with original owner
flag = glock.release("vipr1");
Assert.assertFalse(flag);
// release with current owner
flag = glock2.release("vipr2");
Assert.assertTrue(flag);
}
use of com.emc.storageos.db.client.impl.DbClientImpl in project coprhd-controller by CoprHD.
the class DBClientTestBase method createDbClient.
/**
* Create DbClient to embedded DB
*
* @return
*/
protected static DbClient createDbClient() {
ENCRYPTION_PROVIDER.setCoordinator(ModelTestSuite.getCoordinator());
DbClientContext localCtx = new DbClientContext();
localCtx.setClusterName("Test");
localCtx.setKeyspaceName("Test");
DbClientImpl dbClient = new DbClientImpl();
dbClient.setCoordinatorClient(ModelTestSuite.getCoordinator());
dbClient.setEncryptionProvider(ENCRYPTION_PROVIDER);
dbClient.setBypassMigrationLock(true);
dbClient.setDbVersionInfo(ModelTestSuite.getDbVersionInfo());
dbClient.setLocalContext(localCtx);
VdcUtil.setDbClient(dbClient);
dbClient.start();
return dbClient;
}
Aggregations