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));
}
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);
}
Aggregations