Search in sources :

Example 1 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project hibernate-orm by hibernate.

the class CriteriaLockingTest method testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue.

@Test
@BMRules(rules = { @BMRule(targetClass = "org.hibernate.dialect.Dialect", targetMethod = "useFollowOnLocking", action = "return true", name = "H2DialectUseFollowOnLocking") })
public void testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
    buildSessionFactory();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000444");
    final Session s = openSession();
    final Transaction tx = s.beginTransaction();
    Item item = new Item();
    item.name = "ZZZZ";
    s.persist(item);
    s.flush();
    Criteria criteria = s.createCriteria(Item.class).setLockMode(LockMode.OPTIMISTIC);
    criteria.list();
    tx.rollback();
    s.close();
    releaseSessionFactory();
    assertTrue(triggerable.wasTriggered());
}
Also used : Transaction(org.hibernate.Transaction) Triggerable(org.hibernate.testing.logger.Triggerable) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 2 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project hibernate-orm by hibernate.

the class CriteriaLockingTest method testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue.

@Test
@BMRules(rules = { @BMRule(targetClass = "org.hibernate.dialect.Dialect", targetMethod = "useFollowOnLocking", action = "return true", name = "H2DialectUseFollowOnLocking") })
public void testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
    buildSessionFactory();
    Triggerable triggerable = logInspection.watchForLogMessages("HHH000444");
    final Session s = openSession();
    final Transaction tx = s.beginTransaction();
    Item item = new Item();
    item.name = "ZZZZ";
    s.persist(item);
    s.flush();
    Criteria criteria = s.createCriteria(Item.class).setLockMode(LockMode.NONE);
    criteria.list();
    tx.rollback();
    s.close();
    releaseSessionFactory();
    assertFalse(triggerable.wasTriggered());
}
Also used : Transaction(org.hibernate.Transaction) Triggerable(org.hibernate.testing.logger.Triggerable) Criteria(org.hibernate.Criteria) Session(org.hibernate.Session) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 3 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.

the class UseChecksumFromTransferDecoratorForTrackingRecordTest method run.

@BMRules(rules = { @BMRule(name = "setup_metadata_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_successive_metadata_additions", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "addMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
    final String trackingId = newName();
    final String repoId = "repo";
    final String path = "/path/to/foo.class";
    final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
    server.expect(server.formatUrl(repoId, path), 200, stream);
    RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
    rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
    IOUtils.copy(in, baos);
    in.close();
    final byte[] bytes = baos.toByteArray();
    final String md5 = md5Hex(bytes);
    final String sha256 = sha256Hex(bytes);
    assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
    assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
    waitForEventPropagation();
    assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
    final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
    assertThat(report, notNullValue());
    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    final TrackedContentEntryDTO entry = downloads.iterator().next();
    System.out.println(entry);
    assertThat(entry, notNullValue());
    assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
    assertThat(entry.getPath(), equalTo(path));
    assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
    assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
    assertThat(entry.getMd5(), equalTo(md5));
    assertThat(entry.getSha256(), equalTo(sha256));
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) BytemanTest(org.commonjava.indy.ftest.core.category.BytemanTest) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 4 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.

the class ConcurrencyTest method deadlockOnGroupContains.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getGroupsContaining call", targetClass = "MemoryStoreDataManager", targetMethod = "getGroupsContaining", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void deadlockOnGroupContains() throws IndyDataException, InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
    AtomicInteger count = new AtomicInteger(0);
    RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
    TestUpdatingEventDispatcher dispatcher = new TestUpdatingEventDispatcher(repo, completionService, count);
    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());
    for (int i = 0; i < 2; i++) {
        Group group = new Group(MAVEN_PKG_KEY, "group" + i);
        if (i % 2 == 0) {
            group.addConstituent(repo);
        }
        dataManager.storeArtifactStore(group, summary, false, false, new EventMetadata());
    }
    for (int i = 0; i < count.get(); i++) {
        Future<String> future = completionService.take();
        assertThat(future.get(), nullValue());
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 5 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.

the class GitManagerConcurrentTest method concurrentAddToRepo.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentAddToRepo() throws Exception {
    final int threshold = 2;
    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));
                FileUtils.write(f, String.format("This is a test %s", j));
                final String user = "test" + j;
                final String log = "test commit " + j;
                git.addAndCommitFiles(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) CountDownLatch(java.util.concurrent.CountDownLatch) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) File(java.io.File) 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