use of org.commonjava.maven.galley.model.Location 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.commonjava.maven.galley.model.Location 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.commonjava.maven.galley.model.Location 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.commonjava.maven.galley.model.Location 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.commonjava.maven.galley.model.Location in project galley by Commonjava.
the class AbstractTransferManagerTest method retrieve_preferCachedCopy.
/**
* Test that cached content will be used...if not, this test will fail, as
* the wrong content is registered with the test transport.
*/
@Test
public void retrieve_preferCachedCopy() throws Exception {
final String testContent = "This is a test " + System.currentTimeMillis();
final Location loc = new SimpleLocation("file:///test-repo");
final String path = "/path/to/test.txt";
final ConcreteResource resource = new ConcreteResource(loc, path);
// put in some wrong content that will cause problems if the cache isn't used.
getTransport().registerDownload(resource, new TestDownload("This is WRONG".getBytes()));
// seed the cache with the file we're trying to retrieve.
OutputStream os = null;
try {
os = getCacheProvider().openOutputStream(resource);
os.write(testContent.getBytes());
} finally {
closeQuietly(os);
}
// now, use the manager to retrieve() the path...the cached content should come through here.
final Transfer transfer = getTransferManagerImpl().retrieve(resource);
assertTransferContent(transfer, testContent);
}
Aggregations