use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderTest method testWriteDeleteAndVerifyNonExistence.
@Test
@BMScript("WriteDeleteAndVerifyNonExistence.btm")
public void testWriteDeleteAndVerifyNonExistence() 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 WriteFileThread(content, loc, fname, latch));
start(new DeleteFileThread(loc, fname, latch));
latchWait(latch);
assertThat(provider.exists(new ConcreteResource(loc, fname)), equalTo(false));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderTest method testLockThenWaitForUnLock.
@Test
@BMScript("WriteReadLockVerify.btm")
public void testLockThenWaitForUnLock() throws Exception {
final Location loc = new SimpleLocation("http://foo.com");
final String path = "my/path.txt";
final ConcreteResource res = new ConcreteResource(loc, path);
CountDownLatch latch = new CountDownLatch(2);
start(new ReadLockThread(res, latch));
start(new WriteLockThread(res, latch));
latchWait(latch);
assertThat(provider.isWriteLocked(res), equalTo(false));
assertThat(provider.isReadLocked(res), equalTo(false));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderTest method writeCopyAndReadNewFile.
/**
* Two threads included in this test, CopyFileThread will copy the content generated by WriteFileThread and then read from the copied one.
* The matcher result is expected be equal to the original content written from WriteFileThread.
* @throws Exception
*/
@Test
@BMScript("WriteCopyAndReadNewFile.btm")
public void writeCopyAndReadNewFile() 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";
final Location loc2 = new SimpleLocation("http://bar.com");
CountDownLatch latch = new CountDownLatch(2);
start(new CopyFileThread(loc, loc2, 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 galley by Commonjava.
the class FastLocalCacheProviderConcurrentTest method testDeleteWhenWriteNotCompleted.
@Test
@BMScript("TryToDeleteWhileWritingNotCompleted.btm")
public void testDeleteWhenWriteNotCompleted() throws Exception {
final ConcreteResource resource = createTestResource("file_delete_write_not_completed.txt");
final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
testPool.execute(new WriteTask(provider, content, resource, latch, 1000));
latchWait(latch);
final Boolean deleted = deleteFuture.get();
assertThat(deleted, equalTo(false));
assertThat(provider.exists(resource), equalTo(true));
}
use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentTest method testWriteReadWithNFS.
@Test
@BMScript("TryToWriteWhileReading.btm")
public void testWriteReadWithNFS() throws Exception {
final ConcreteResource resource = createTestResource("file_write_read_has_only_NFS.txt");
prepareNFSResource(resource, content);
testPool.execute(new WriteTask(provider, diffContent, resource, latch));
final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
latchWait(latch);
final String readingResult = readingFuture.get();
assertThat(readingResult, equalTo(content));
final String changedResult = readLocalResource(resource);
assertThat(changedResult, equalTo(diffContent));
}
Aggregations