use of com.google.nigori.client.accept.n.SetGetDeleteTest.IndexValue in project nigori by ucam-cl-dtg.
the class ConcurrencyTest method singleUserConcurrency.
/**
* Test that one user can do lots of things at the same time.
*
* @throws NigoriCryptographyException
* @throws IOException
* @throws UnauthorisedException
*/
@Test
public void singleUserConcurrency() throws NigoriCryptographyException, IOException, UnauthorisedException {
failed = false;
Thread[] threads = new Thread[THREADS];
final NigoriDatastore nigori = getStore();
assertTrue("Not registered", nigori.register());
try {
final List<Throwable> exceptionList = Collections.synchronizedList(new LinkedList<Throwable>());
for (int j = 0; j < THREADS; ++j) {
threads[j] = new Thread() {
@Override
public void run() {
boolean succeeded = false;
try {
Random r = new Random();
for (int i = 0; i < AcceptanceTests.REPEAT * REPEAT_FACTOR; ++i) {
// check we can do this more than once
for (IndexValue iv : SetGetDeleteTest.testCases) {
// once round for each
final Index index = new Index(new byte[16]);
// need to generate some different indices
r.nextBytes(index.getBytes());
final byte[] value = iv.revvalue.getValue();
final Revision revision = iv.revvalue.getRevision();
assertTrue("Not put" + i, nigori.put(index, revision, value));
try {
assertArrayEquals("Got different" + i, value, nigori.getRevision(index, revision));
} finally {
assertTrue("Not deleted" + i, nigori.delete(index, NULL_DELETE_TOKEN));
}
assertNull("Not deleted" + i, nigori.get(index));
}
}
succeeded = true;
} catch (Throwable e) {
exceptionList.add(e);
} finally {
if (!succeeded && !failed) {
failed = true;
}
}
}
};
}
startThenJoinThreads(threads);
ifFailedPrintFailures(failed, exceptionList);
} finally {
assertTrue(nigori.unregister());
}
}
Aggregations