Search in sources :

Example 1 with RequestedTokenHelper

use of com.emc.storageos.security.geo.RequestedTokenHelper in project coprhd-controller by CoprHD.

the class TokenManagerTests method concurrentRequestedTokenMapUpdates.

/**
 * This test updates two objects in the RequestedTokenMap CF. One for token1,
 * one for token2. Each one is initially loaded with 10 entries:
 * token1: vdc1, vdc2, vdc3 ...
 * token2: vdc1, vdc2, vdc3 ...
 * 10 adder threads are adding 10 more entries to each token. vdc-11, vdc-12 ...
 * 10 remover threads are removing the 10 entries created initially
 * The result is each token should end up with 10 entries, from the adder threads.
 *
 * @throws Exception
 */
@Test
public void concurrentRequestedTokenMapUpdates() throws Exception {
    final DbClient sharedDbClient = getDbClient();
    final CoordinatorClient sharedCoordinator = new TestCoordinator();
    final RequestedTokenHelper requestedTokenMap = new RequestedTokenHelper();
    requestedTokenMap.setDbClient(sharedDbClient);
    requestedTokenMap.setCoordinator(sharedCoordinator);
    // pre load the map with 10 entries for a given token
    for (int i = 0; i < 10; i++) {
        requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token1", String.format("vdc%d", i));
    }
    // pre load the map with 10 entries for another token
    for (int i = 0; i < 10; i++) {
        requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token2", String.format("vdc%d", i));
    }
    int numAdderThreads = 10;
    int numRemoverThreads = 10;
    int numThreads = numAdderThreads + numRemoverThreads;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    final CountDownLatch waiter = new CountDownLatch(numThreads);
    final class Adders implements Callable {

        @Override
        public Object call() throws Exception {
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token1", String.format("vdc-1%d", i));
            }
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.ADD_VDC, "token2", String.format("vdc-2%d", i));
            }
            return null;
        }
    }
    final class Removers implements Callable {

        @Override
        public Object call() throws Exception {
            // synchronize all threads
            waiter.countDown();
            waiter.await();
            // pre load the map with 10 entries for a given token
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.REMOVE_VDC, "token1", String.format("vdc%d", i));
            }
            // pre load the map with 10 entries for another token
            for (int i = 0; i < 10; i++) {
                requestedTokenMap.addOrRemoveRequestingVDC(Operation.REMOVE_VDC, "token2", String.format("vdc%d", i));
            }
            return null;
        }
    }
    for (int i = 0; i < numAdderThreads; i++) {
        executor.submit(new Adders());
    }
    for (int i = 0; i < numRemoverThreads; i++) {
        executor.submit(new Removers());
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(60, TimeUnit.SECONDS));
    // Verification. We should be left with just 10 entries for each token
    // The 10 entries that were added by the adders.
    RequestedTokenMap mapToken1 = requestedTokenMap.getTokenMap("token1");
    Assert.assertEquals(10, mapToken1.getVDCIDs().size());
    StringSet entries = mapToken1.getVDCIDs();
    ArrayList<String> checkList = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
        checkList.add(String.format("vdc-1%d", i));
    }
    Assert.assertTrue(entries.containsAll(checkList));
    RequestedTokenMap mapToken2 = requestedTokenMap.getTokenMap("token2");
    Assert.assertEquals(10, mapToken2.getVDCIDs().size());
    StringSet entries2 = mapToken2.getVDCIDs();
    ArrayList<String> checkList2 = new ArrayList<String>();
    for (int i = 0; i < 10; i++) {
        checkList2.add(String.format("vdc-2%d", i));
    }
    Assert.assertTrue(entries2.containsAll(checkList2));
}
Also used : RequestedTokenMap(com.emc.storageos.db.client.model.RequestedTokenMap) DbClient(com.emc.storageos.db.client.DbClient) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) RequestedTokenHelper(com.emc.storageos.security.geo.RequestedTokenHelper) StringSet(com.emc.storageos.db.client.model.StringSet) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) Test(org.junit.Test)

Example 2 with RequestedTokenHelper

use of com.emc.storageos.security.geo.RequestedTokenHelper in project coprhd-controller by CoprHD.

the class TokenManagerTests method cleanUpDb.

/**
 * Delete all tokens for user1 before each test.
 */
@Before
public void cleanUpDb() {
    CassandraTokenManager tokenManagerCleanup = new CassandraTokenManager();
    tokenManagerCleanup.setDbClient(_dbClient);
    tokenManagerCleanup.setCoordinator(_coordinator);
    RequestedTokenHelper requestedTokenMapHelper = new RequestedTokenHelper();
    requestedTokenMapHelper.setDbClient(_dbClient);
    requestedTokenMapHelper.setCoordinator(_coordinator);
    tokenManagerCleanup.setTokenMapHelper(requestedTokenMapHelper);
    tokenManagerCleanup.deleteAllTokensForUser("user1", true);
}
Also used : RequestedTokenHelper(com.emc.storageos.security.geo.RequestedTokenHelper) CassandraTokenManager(com.emc.storageos.auth.impl.CassandraTokenManager) Before(org.junit.Before)

Aggregations

RequestedTokenHelper (com.emc.storageos.security.geo.RequestedTokenHelper)2 CassandraTokenManager (com.emc.storageos.auth.impl.CassandraTokenManager)1 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 DbClient (com.emc.storageos.db.client.DbClient)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 RequestedTokenMap (com.emc.storageos.db.client.model.RequestedTokenMap)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 Before (org.junit.Before)1 Test (org.junit.Test)1