use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.
the class GitManagerConcurrentTest method concurrentDeleteFromRepo.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "deleteAndCommitPaths call", targetClass = "GitManager", targetMethod = "deleteAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentDeleteFromRepo() throws Exception {
final int threshold = 2;
for (int i = 0; i < threshold; i++) {
try {
final File f = new File(cloneDir, String.format("test%s.txt", i));
FileUtils.write(f, String.format("This is a test %s", i));
final String user = "test" + i;
final String log = "test commit " + i;
git.addAndCommitFiles(new ChangeSummary(user, log), f);
} catch (Exception e) {
e.printStackTrace();
failed = true;
}
}
final Executor pool = Executors.newFixedThreadPool(threshold);
CountDownLatch latch = new CountDownLatch(threshold);
for (int i = 0; i < threshold; i++) {
final int j = i;
pool.execute(() -> {
try {
final File f = new File(cloneDir, String.format("test%s.txt", j));
final String user = "test" + j;
final String log = "delete test" + j + ".txt";
git.deleteAndCommit(new ChangeSummary(user, log), f);
} catch (Exception e) {
e.printStackTrace();
failed = true;
} finally {
latch.countDown();
}
});
}
latch.await();
if (failed) {
fail();
}
}
use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.
the class ConcurrencyTest method deadlockOnListAllDuringDelete.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2)"), @BMRule(name = "delete call", targetClass = "MemoryStoreDataManager", targetMethod = "deleteArtifactStore", targetLocation = "EXIT", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": deletion thread proceeding.\")"), @BMRule(name = "streamArtifactStores call", targetClass = "MemoryStoreDataManager", targetMethod = "streamArtifactStores", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": streamArtifactStores() thread proceeding.\")") })
@Test
public void deadlockOnListAllDuringDelete() throws IndyDataException, InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(2);
ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
TestDeletingEventDispatcher dispatcher = new TestDeletingEventDispatcher(completionService);
MemoryStoreDataManager dataManager = new MemoryStoreDataManager(dispatcher, new DefaultIndyConfiguration());
dispatcher.setDataManager(dataManager);
ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test init");
dataManager.storeArtifactStore(repo, summary, false, false, new EventMetadata());
dataManager.deleteArtifactStore(repo.getKey(), new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test deletion"), new EventMetadata());
Future<String> future = completionService.take();
assertThat(future.get(), nullValue());
}
Aggregations