Search in sources :

Example 31 with SimpleLocation

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

Example 32 with SimpleLocation

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));
}
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 33 with SimpleLocation

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));
}
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 34 with SimpleLocation

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);
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) OutputStream(java.io.OutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 35 with SimpleLocation

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
    }
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)42 Test (org.junit.Test)39 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)35 Location (org.commonjava.maven.galley.model.Location)26 Transfer (org.commonjava.maven.galley.model.Transfer)22 InputStream (java.io.InputStream)12 OutputStream (java.io.OutputStream)10 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 OutputStreamWriter (java.io.OutputStreamWriter)5 PrintWriter (java.io.PrintWriter)5 URI (java.net.URI)5 LinkedHashMap (java.util.LinkedHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)5 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)5 File (java.io.File)4