@Test
public void stressTestConcurrency() throws InterruptedException, IOException {
RepositoryConfiguration conf = makeRepoConf();
conf.setConcurrency(3);
BaseRepository repo = Repository.create(conf, Files.createTempDir());
Stats stats = new Stats();
List<StressThread> threads = Lists.newArrayList();
// Write some initial changesets
writeFile(repo, "a", "123");
AddCommand.on(repo).execute();
CommitCommand.on(repo).message("a").user("setup").execute();
writeFile(repo, "b", "123");
AddCommand.on(repo).execute();
CommitCommand.on(repo).message("b").user("setup").execute();
writeFile(repo, "c", "123");
AddCommand.on(repo).execute();
CommitCommand.on(repo).message("c").user("setup").execute();
for (int i = 0; i < NUMBER_OF_THREADS; i++) {
StressThread t = new StressThread2(CYCLES_PER_THREAD * 10, i, stats, repo);
t.start();
threads.add(t);
}
for (StressThread cycleThread : threads) {
cycleThread.join();
}
Assert.assertEquals(20 * CYCLES_PER_THREAD * NUMBER_OF_THREADS, stats.changes + stats.noChanges);
System.err.println("Cache stats: " + repo.getCacheStats());
}