Search in sources :

Example 6 with BMRules

use of org.jboss.byteman.contrib.bmunit.BMRules in project cassandra by apache.

the class CommitLogSegmentManagerTest method testCompressedCommitLogBackpressure.

@Test
@BMRules(rules = { @BMRule(name = "Acquire Semaphore before sync", targetClass = "AbstractCommitLogService$1", targetMethod = "run", targetLocation = "AT INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentManagerTest.allowSync.acquire()"), @BMRule(name = "Release Semaphore after sync", targetClass = "AbstractCommitLogService$1", targetMethod = "run", targetLocation = "AFTER INVOKE org.apache.cassandra.db.commitlog.CommitLog.sync", action = "org.apache.cassandra.db.commitlog.CommitLogSegmentManagerTest.allowSync.release()") })
public void testCompressedCommitLogBackpressure() throws Throwable {
    // Perform all initialization before making CommitLog.Sync blocking
    // Doing the initialization within the method guarantee that Byteman has performed its injections when we start
    new Random().nextBytes(entropy);
    DatabaseDescriptor.daemonInitialization();
    DatabaseDescriptor.setCommitLogCompression(new ParameterizedClass("LZ4Compressor", ImmutableMap.of()));
    DatabaseDescriptor.setCommitLogSegmentSize(1);
    DatabaseDescriptor.setCommitLogSync(CommitLogSync.periodic);
    DatabaseDescriptor.setCommitLogSyncPeriod(10 * 1000);
    DatabaseDescriptor.setCommitLogMaxCompressionBuffersPerPool(3);
    SchemaLoader.prepareServer();
    SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD1, 0, AsciiType.instance, BytesType.instance), SchemaLoader.standardCFMD(KEYSPACE1, STANDARD2, 0, AsciiType.instance, BytesType.instance));
    CompactionManager.instance.disableAutoCompaction();
    ColumnFamilyStore cfs1 = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD1);
    final Mutation m = new RowUpdateBuilder(cfs1.metadata(), 0, "k").clustering("bytes").add("val", ByteBuffer.wrap(entropy)).build();
    Thread dummyThread = new Thread(() -> {
        for (int i = 0; i < 20; i++) CommitLog.instance.add(m);
    });
    try {
        // Makes sure any call to CommitLog.sync is blocking
        allowSync.acquire();
        dummyThread.start();
        AbstractCommitLogSegmentManager clsm = CommitLog.instance.segmentManager;
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
        Thread.sleep(1000);
        // Should only be able to create 3 segments not 7 because it blocks waiting for truncation that never comes
        Assert.assertEquals(3, clsm.getActiveSegments().size());
        // Discard the currently active segments so allocation can continue.
        // Take snapshot of the list, otherwise this will also discard newly allocated segments.
        new ArrayList<>(clsm.getActiveSegments()).forEach(clsm::archiveAndDiscard);
        // The allocated count should reach the limit again.
        Util.spinAssertEquals(3, () -> clsm.getActiveSegments().size(), 5);
    } finally {
        // Allow the CommitLog.sync to perform normally.
        allowSync.release();
    }
    try {
        // Wait for the dummy thread to die
        dummyThread.join();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : Random(java.util.Random) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Mutation(org.apache.cassandra.db.Mutation) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 7 with BMRules

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

the class LockNoneWarmingTest method testQuerySetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue.

@Test
@BMRules(rules = { @BMRule(targetClass = "org.hibernate.dialect.Dialect", targetMethod = "useFollowOnLocking", action = "return true", name = "H2DialectUseFollowOnLocking") })
public void testQuerySetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
    try (Session s = openSession()) {
        final Query query = s.createQuery("from Item i join i.bids b where name = :name");
        query.setParameter("name", "ZZZZ");
        query.setLockMode("i", LockMode.NONE);
        query.setLockMode("b", LockMode.NONE);
        query.list();
        assertFalse(triggerable.triggerMessage(), triggerable.wasTriggered());
    }
}
Also used : Query(org.hibernate.query.Query) Session(org.hibernate.Session) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 8 with BMRules

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

the class RecalculateMissingChecksumForTrackingRecordTest method run.

@BMRules(rules = { @BMRule(name = "setup_metadata_retrieval_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_first_metadata_retrieval", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "getContentMetadata", 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 9 with BMRules

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

the class UseChecksumFromTransferDecoratorForTrackingRecord_Sha1FileTest 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 = "/org/bar/foo/1/foo-1.pom.sha1";
    final InputStream stream = new ByteArrayInputStream(DigestUtils.md5("This is a test with the same content each time."));
    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 10 with BMRules

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

the class GitManagerConcurrentTest method addToRepoWhileGettingHeadCommit.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getHeadCommit call", targetClass = "GitManager", targetMethod = "getHeadCommit(File)", targetLocation = "ENTRY", action = "debug(\"getHeadCommit() waiting...\"); rendezvous($0); debug(\"getHeadCommit(): thread proceeding.\")"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "debug(\"addAndCommitPaths() waiting...\"); rendezvous($0); debug(\"addAndCommitPaths(): thread proceeding.\")") })
@Test
public void addToRepoWhileGettingHeadCommit() throws Exception {
    final int threshold = 2;
    final Executor pool = Executors.newFixedThreadPool(threshold);
    CountDownLatch latch = new CountDownLatch(threshold);
    final File f = new File(cloneDir, String.format("test.txt"));
    FileUtils.write(f, "This is a test");
    final String user = "testAddAndCommit";
    git.addAndCommitFiles(new ChangeSummary(user, "first commit"), f);
    pool.execute(() -> {
        try {
            git.getHeadCommit(f);
        } catch (Exception e) {
            e.printStackTrace();
            failed = true;
        } finally {
            latch.countDown();
        }
    });
    pool.execute(() -> {
        try {
            FileUtils.write(f, "This is another test");
            git.addAndCommitFiles(new ChangeSummary(user, "second commit"), 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