use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentTest method testDeleteWhenReadCompleted.
@Test
@BMScript("TryToDeleteWhileReadingCompleted.btm")
public void testDeleteWhenReadCompleted() throws Exception {
final ConcreteResource resource = createTestResource("file_delete_read.txt");
prepareBothResource(resource, content);
final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
latchWait(latch);
final Boolean deleted = deleteFuture.get();
final String readingResult = readingFuture.get();
assertThat(readingResult, equalTo(content));
assertThat(deleted, equalTo(true));
assertThat(provider.exists(resource), equalTo(false));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderTest method ConcurrentWriteAndReadFile.
@Test
@BMScript("ConcurrentWriteAndReadFile.btm")
public void ConcurrentWriteAndReadFile() throws Exception {
final String content = "This is a test";
final Location loc = new SimpleLocation("http://foo.com");
final String fname = "/path/to/my/file.txt";
CountDownLatch latch = new CountDownLatch(2);
start(new ReadFileThread(loc, fname, latch));
start(new WriteFileThread(content, loc, fname, latch));
latchWait(latch);
assertThat(result, equalTo(content));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project JGroups by belaban.
the class BecomeServerTest method testSendingOfMsgsOnUnconnectedChannel.
/**
* When we flush the server queue and one or more of the delivered messages triggers a response (in the same thread),
* we need to make sure the channel is connected, or else the JOIN will fail as the exception happens on the same
* thread. Note that the suggested fix on JGRP-1522 will solve this. Issue: https://issues.jboss.org/browse/JGRP-1522
*/
@BMScript(dir = "scripts/BecomeServerTest", value = "testSendingOfMsgsOnUnconnectedChannel")
public void testSendingOfMsgsOnUnconnectedChannel() throws Exception {
a = createChannel("A");
a.setReceiver(new ReceiverAdapter() {
public void receive(Message msg) {
System.out.println("A: received message from " + msg.getSrc() + ": " + msg.getObject());
}
});
a.connect("BecomeServerTest");
new Thread("MsgSender-A") {
public void run() {
// will be blocked by byteman rendezvous
sendMessage(a, "hello from A");
}
}.start();
b = createChannel("B");
b.setReceiver(new ReceiverAdapter() {
public void receive(Message msg) {
System.out.println("B: received message from " + msg.getSrc() + ": " + msg.getObject());
if (msg.getSrc().equals(a.getAddress())) {
try {
b.send(null, "This message would trigger an exception if the channel was not yet connected");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
});
b.connect("BecomeServerTest");
Util.waitUntilAllChannelsHaveSameView(20000, 1000, a, b);
System.out.println("\nA: " + a.getView() + "\nB: " + b.getView());
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentTest method testReadWhileDeleteCompleted.
@Test
@BMScript("TryToReadWhileDeleteCompleted.btm")
public void testReadWhileDeleteCompleted() throws Exception {
final ConcreteResource resource = createTestResource("file_read_delete_completed.txt");
prepareBothResource(resource, content);
final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
latchWait(latch);
final Boolean deleted = deleteFuture.get();
final String readingResult = readingFuture.get();
assertThat(readingResult, equalTo(null));
assertThat(deleted, equalTo(true));
assertThat(provider.exists(resource), equalTo(false));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentTest method testDeleteWhenWriteCompleted.
@Test
@BMScript("TryToDeleteWhileWritingCompleted.btm")
public void testDeleteWhenWriteCompleted() throws Exception {
final ConcreteResource resource = createTestResource("file_delete_write_completed.txt");
final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
testPool.execute(new WriteTask(provider, content, resource, latch));
latchWait(latch);
final Boolean deleted = deleteFuture.get();
assertThat(deleted, equalTo(true));
assertThat(provider.exists(resource), equalTo(false));
}
Aggregations