Search in sources :

Example 1 with BMRule

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

the class PendingRangeCalculatorServiceTest method testDelayedResponse.

@Test
@BMRule(name = "Block pending range calculation", targetClass = "TokenMetadata", targetMethod = "calculatePendingRanges", targetLocation = "AT INVOKE org.apache.cassandra.locator.AbstractReplicationStrategy.getAddressRanges", action = "org.apache.cassandra.gms.PendingRangeCalculatorServiceTest.calculationLock.lock()")
public void testDelayedResponse() throws UnknownHostException, InterruptedException {
    InetAddress otherNodeAddr = InetAddress.getByName("127.0.0.2");
    UUID otherHostId = UUID.randomUUID();
    // introduce node for first major state change
    Gossiper.instance.applyStateLocally(getStates(otherNodeAddr, otherHostId, 1, false));
    // acquire lock to block pending range calculation via byteman
    calculationLock.lock();
    try {
        // spawn thread that will trigger handling of a bootstrap state change which in turn will trigger
        // the pending range calculation that will be blocked by our lock
        Thread t1 = new Thread() {

            public void run() {
                Gossiper.instance.applyStateLocally(getStates(otherNodeAddr, otherHostId, 2, true));
            }
        };
        t1.start();
        // busy-spin until t1 is blocked by lock
        while (!calculationLock.hasQueuedThreads()) ;
        // trigger further state changes in case we don't want the blocked thread from the
        // expensive range calculation to block us here as well
        Thread t2 = new Thread() {

            public void run() {
                Gossiper.instance.applyStateLocally(getStates(otherNodeAddr, otherHostId, 3, false));
                Gossiper.instance.applyStateLocally(getStates(otherNodeAddr, otherHostId, 4, false));
                Gossiper.instance.applyStateLocally(getStates(otherNodeAddr, otherHostId, 5, false));
            }
        };
        t2.start();
        t2.join(2000);
        assertFalse("Thread still blocked by pending range calculation", t2.isAlive());
        assertEquals(5, Gossiper.instance.getEndpointStateForEndpoint(otherNodeAddr).getHeartBeatState().getHeartBeatVersion());
    } finally {
        calculationLock.unlock();
    }
}
Also used : UUID(java.util.UUID) InetAddress(java.net.InetAddress) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 2 with BMRule

use of org.jboss.byteman.contrib.bmunit.BMRule in project galley by Commonjava.

the class FastLocalCacheProviderTest method testLongTimeWaitBeforeClose.

@BMRule(name = "longTimeWaitBeforeCloseTest", targetClass = "FastLocalCacheProvider", targetMethod = "openOutputStream", targetLocation = "EXIT", action = "java.lang.Thread.sleep(60*1000)")
@Test
public void testLongTimeWaitBeforeClose() throws IOException {
    final Location loc = new SimpleLocation("http://foo.com");
    ConcreteResource resource = new ConcreteResource(loc, String.format("/path/to/my/%s", "file-write-close.text"));
    provider.openOutputStream(resource);
    provider.cleanupCurrentThread();
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 3 with BMRule

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

the class RecursiveGroupMetadataClearOnUploadTest method run.

@BMRule(name = "slow_down", targetClass = "org.commonjava.indy.content.index.ContentIndexManager", targetMethod = "clearIndexedPathFrom", targetLocation = "ENTRY", binding = "tctx:org.commonjava.cdi.util.weft.ThreadContext = ThreadContext.getContext(true);" + "key:org.commonjava.indy.model.core.StoreKey = tctx.get(\"ContentIndex:originKey\");" + "isFlagged:boolean = \"groupA\".equals(key.getName());", condition = "isFlagged", action = "System.out.println(\"Slowing down 4s\");" + "Thread.sleep(4000);")
@Test
@Category(EventDependent.class)
public void run() throws Exception {
    assertContent(hostedRepo, path, firstPassContent);
    assertContent(groupA, path, firstPassContent);
    assertContent(groupB, path, firstPassContent);
    client.content().store(hostedRepo.getKey(), path, new ByteArrayInputStream(secondPassContent.getBytes("UTF-8")));
    //        waitForEventPropagation();
    //        assertContent( hostedRepo, secondPassContent );
    //        assertContent( groupA, secondPassContent );
    assertContent(groupB, path, secondPassContent);
    Thread.currentThread().sleep(4000);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Category(org.junit.experimental.categories.Category) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) BytemanTest(org.commonjava.indy.ftest.core.category.BytemanTest)

Aggregations

BMRule (org.jboss.byteman.contrib.bmunit.BMRule)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InetAddress (java.net.InetAddress)1 UUID (java.util.UUID)1 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)1 BytemanTest (org.commonjava.indy.ftest.core.category.BytemanTest)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 Location (org.commonjava.maven.galley.model.Location)1 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)1 Category (org.junit.experimental.categories.Category)1