public void testSimpleMetaStoreDeletePropertyConcurrency() throws CoreException {
// create the MetaStore
IMetaStore metaStore = getMetaStore();
// create the user
UserInfo userInfo = new UserInfo();
userInfo.setUserName("anthony");
userInfo.setFullName("Anthony Hunter");
metaStore.createUser(userInfo);
// add properties to the user in multiple threads
Thread threads[] = new Thread[THREAD_COUNT];
for (int i = 0; i < threads.length; i++) {
threads[i] = createPropertyThread(i);
}
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
// just continue
}
}
// read the user and make sure the properties are there
userInfo = metaStore.readUser("anthony");
int count = 0;
Map<String, String> properties = userInfo.getProperties();
for (String key : properties.keySet()) {
if (key.startsWith("property/")) {
count++;
}
}
assertEquals("Incomplete number of properties added for the user", THREAD_COUNT * PROPERTY_COUNT, count);
// delete properties in multiple threads
threads = new Thread[THREAD_COUNT];
for (int i = 0; i < threads.length; i++) {
threads[i] = deletePropertyThread(i);
}
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
// just continue
}
}
// read the user and make sure there are no properties are there
userInfo = metaStore.readUser("anthony");
count = 0;
properties = userInfo.getProperties();
for (String key : properties.keySet()) {
if (key.startsWith("property/")) {
count++;
}
}
// delete the user
metaStore.deleteUser(userInfo.getUniqueId());
assertEquals("Incomplete number of properties deleted for the user", 0, count);
}