Search in sources :

Example 11 with BMRules

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();
    }
}
Also used : Executor(java.util.concurrent.Executor) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 12 with BMRules

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());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

BMRules (org.jboss.byteman.contrib.bmunit.BMRules)12 Test (org.junit.Test)12 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 InputStream (java.io.InputStream)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Executor (java.util.concurrent.Executor)3 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)3 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)3 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)3 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)3 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)3 StoreKey (org.commonjava.indy.model.core.StoreKey)3 Session (org.hibernate.Session)3 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)2 ExecutorService (java.util.concurrent.ExecutorService)2 DefaultIndyConfiguration (org.commonjava.indy.conf.DefaultIndyConfiguration)2