Search in sources :

Example 26 with DbClientImpl

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);
}
Also used : DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) GlobalLockImpl(com.emc.storageos.db.client.impl.GlobalLockImpl) Test(org.junit.Test)

Example 27 with DbClientImpl

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;
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl)

Aggregations

DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)27 Test (org.junit.Test)11 URI (java.net.URI)9 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)6 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)5 Order (com.emc.storageos.db.client.model.uimodels.Order)5 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)4 Volume (com.emc.storageos.db.client.model.Volume)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)3 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)3 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)3 GlobalLockImpl (com.emc.storageos.db.client.impl.GlobalLockImpl)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)3 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2