use of org.commonjava.maven.galley.model.SimpleLocation 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.SimpleLocation 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.SimpleLocation 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.SimpleLocation 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);
}
use of org.commonjava.maven.galley.model.SimpleLocation in project galley by Commonjava.
the class RoutingCacheProviderWrapperTest method test.
@Test
public void test() throws Exception {
final RoutingCacheProviderWrapper router = (RoutingCacheProviderWrapper) new RoutingCacheProviderFactory(selector, fastLocalFac, partylineFac).create(pathgen, decorator, events);
final CacheProvider partyline = partylineFac.create(pathgen, decorator, events);
final CacheProvider fastLocal = fastLocalFac.create(pathgen, decorator, events);
final String fname = "/path/to/my/file.txt";
Location loc = new SimpleLocation("remote:foo/com");
ConcreteResource resource = new ConcreteResource(loc, fname);
CacheProvider get = router.getRoutedProvider(resource);
assertThat(get, equalTo(partyline));
loc = new SimpleLocation("hosted:foo/com");
resource = new ConcreteResource(loc, fname);
get = router.getRoutedProvider(resource);
assertThat(get, equalTo(fastLocal));
loc = new SimpleLocation("group:foo/com");
resource = new ConcreteResource(loc, fname);
get = router.getRoutedProvider(resource);
assertThat(get, equalTo(partyline));
loc = new SimpleLocation("http://foo.com");
resource = new ConcreteResource(loc, fname);
get = router.getRoutedProvider(resource);
assertThat(get, equalTo(partyline));
resource = new ConcreteResource(null, null);
get = router.getRoutedProvider(resource);
assertThat(get, equalTo(partyline));
get = router.getRoutedProvider(null);
assertThat(get, equalTo(partyline));
resource = new ConcreteResource(loc, fname);
try {
router.asAdminView().getDetachedFile(resource);
fail("Should have thrown exception");
} catch (UnsupportedOperationException ex) {
// Pass
}
}
Aggregations