Search in sources :

Example 11 with BMScript

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 12 with BMScript

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 13 with BMScript

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));
}
Also used : SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 14 with BMScript

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 15 with BMScript

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

BMScript (org.jboss.byteman.contrib.bmunit.BMScript)17 Test (org.junit.Test)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 CountDownLatch (java.util.concurrent.CountDownLatch)5 Location (org.commonjava.maven.galley.model.Location)5 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)5 HashSet (java.util.HashSet)1