use of de.tudarmstadt.ukp.clarin.webanno.api.CasProvider in project webanno by webanno.
the class CasStorageServiceImplTest method testHighConcurrencyIncludingDeletion.
@Test
public void testHighConcurrencyIncludingDeletion() throws Exception {
CasProvider initializer = () -> {
try {
CAS cas = createCas(mergeTypeSystems(asList(createTypeSystemDescription(), getInternalTypeSystem())));
cas.setDocumentText(repeat("This is a test.\n", 100_000));
return cas;
} catch (ResourceInitializationException e) {
throw new IOException(e);
}
};
SourceDocument doc = makeSourceDocument(7l, 7l, "doc");
String user = "annotator";
// We interleave all the primary and secondary tasks into the main tasks list
// Primary tasks run for a certain number of iterations
// Secondary tasks run as long as any primary task is still running
List<Thread> tasks = new ArrayList<>();
List<Thread> primaryTasks = new ArrayList<>();
List<Thread> secondaryTasks = new ArrayList<>();
int threadGroupCount = 4;
int iterations = 100;
for (int n = 0; n < threadGroupCount; n++) {
Thread rw = new ExclusiveReadWriteTask(n, doc, user, initializer, iterations);
primaryTasks.add(rw);
tasks.add(rw);
Thread ro = new SharedReadOnlyTask(n, doc, user, initializer);
secondaryTasks.add(ro);
tasks.add(ro);
Thread un = new UnmanagedTask(n, doc, user, initializer);
secondaryTasks.add(un);
tasks.add(un);
Thread uni = new UnmanagedNonInitializingTask(n, doc, user);
secondaryTasks.add(uni);
tasks.add(uni);
DeleterTask xx = new DeleterTask(n, doc, user);
secondaryTasks.add(xx);
tasks.add(xx);
}
log.info("---- Starting all threads ----");
tasks.forEach(Thread::start);
log.info("---- Wait for primary threads to complete ----");
boolean done = false;
while (!done) {
long running = primaryTasks.stream().filter(Thread::isAlive).count();
done = running == 0l;
sleep(1000);
log.info("running {} complete {}% rw {} ro {} un {} uni {} xx {} XX {}", running, (writeCounter.get() * 100) / (threadGroupCount * iterations), writeCounter, managedReadCounter, unmanagedReadCounter, unmanagedNonInitializingReadCounter, deleteCounter, deleteInitialCounter);
}
log.info("---- Wait for threads secondary threads to wrap up ----");
rwTasksCompleted.set(true);
for (Thread thread : secondaryTasks) {
thread.join();
}
log.info("---- Test is done ----");
assertThat(exception).isFalse();
}
use of de.tudarmstadt.ukp.clarin.webanno.api.CasProvider in project webanno by webanno.
the class CasStorageServiceImplTest method testHighConcurrencyWithoutDeletion.
@Test
public void testHighConcurrencyWithoutDeletion() throws Exception {
CasProvider initializer = () -> {
try {
CAS cas = createCas(mergeTypeSystems(asList(createTypeSystemDescription(), getInternalTypeSystem())));
cas.setDocumentText(repeat("This is a test.\n", 100_000));
return cas;
} catch (ResourceInitializationException e) {
throw new IOException(e);
}
};
CasProvider badSeed = () -> {
throw new IOException("This initializer should never be called!");
};
SourceDocument doc = makeSourceDocument(8l, 8l, "doc");
String user = "annotator";
try (CasStorageSession session = openNested()) {
// Make sure the CAS exists so that the threads should never be forced to call the
// the initializer
sut.readOrCreateCas(doc, user, FORCE_CAS_UPGRADE, initializer, EXCLUSIVE_WRITE_ACCESS);
}
// We interleave all the primary and secondary tasks into the main tasks list
// Primary tasks run for a certain number of iterations
// Secondary tasks run as long as any primary task is still running
List<Thread> tasks = new ArrayList<>();
List<Thread> primaryTasks = new ArrayList<>();
List<Thread> secondaryTasks = new ArrayList<>();
int threadGroupCount = 4;
int iterations = 100;
for (int n = 0; n < threadGroupCount; n++) {
ExclusiveReadWriteTask rw = new ExclusiveReadWriteTask(n, doc, user, badSeed, iterations);
primaryTasks.add(rw);
tasks.add(rw);
Thread ro = new SharedReadOnlyTask(n, doc, user, badSeed);
secondaryTasks.add(ro);
tasks.add(ro);
Thread un = new UnmanagedTask(n, doc, user, badSeed);
secondaryTasks.add(un);
tasks.add(un);
Thread uni = new UnmanagedNonInitializingTask(n, doc, user);
secondaryTasks.add(uni);
tasks.add(uni);
}
log.info("---- Starting all threads ----");
tasks.forEach(Thread::start);
log.info("---- Wait for primary threads to complete ----");
boolean done = false;
while (!done) {
long running = primaryTasks.stream().filter(Thread::isAlive).count();
done = running == 0l;
sleep(1000);
log.info("running {} complete {}% rw {} ro {} un {} uni {}", running, (writeCounter.get() * 100) / (threadGroupCount * iterations), writeCounter, managedReadCounter, unmanagedReadCounter, unmanagedNonInitializingReadCounter);
}
log.info("---- Wait for threads secondary threads to wrap up ----");
rwTasksCompleted.set(true);
for (Thread thread : secondaryTasks) {
thread.join();
}
log.info("---- Test is done ----");
assertThat(exception).isFalse();
}
Aggregations