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();
}
}
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();
}
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);
}
Aggregations