Search in sources :

Example 11 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class CacheProviderTCK method writeAndVerifyExistence.

@Test
public void writeAndVerifyExistence() 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 CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.close();
    assertThat(provider.exists(new ConcreteResource(loc, fname)), equalTo(true));
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Example 12 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class CacheProviderTCK method lockThenWaitForLockReturnsImmediatelyInSameThread.

@Test
public void lockThenWaitForLockReturnsImmediatelyInSameThread() throws Exception {
    final Location loc = new SimpleLocation("http://foo.com");
    final String path = "my/path.txt";
    final ConcreteResource res = new ConcreteResource(loc, path);
    final CacheProvider cache = getCacheProvider();
    cache.lockWrite(res);
    cache.waitForWriteUnlock(res);
    assertThat(cache.isWriteLocked(res), equalTo(false));
}
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)

Example 13 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class CacheProviderTCK method writeAndVerifyDirectory.

@Test
public void writeAndVerifyDirectory() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String dir = "/path/to/my/";
    final String fname = dir + "file.txt";
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.close();
    assertThat(provider.isDirectory(new ConcreteResource(loc, dir)), equalTo(true));
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Example 14 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class FastLocalCacheProviderTest method ConcurrentWriteAndReadFile.

@Test
@BMScript("ConcurrentWriteAndReadFile.btm")
public void ConcurrentWriteAndReadFile() 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 ReadFileThread(loc, 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 15 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class FileCacheProvider method createAlias.

@Override
public void createAlias(final ConcreteResource from, final ConcreteResource to) throws IOException {
    // if the download landed in a different repository, copy it to the current one for
    // completeness...
    final Location fromKey = from.getLocation();
    final Location toKey = to.getLocation();
    final String fromPath = from.getPath();
    final String toPath = to.getPath();
    if (fromKey != null && toKey != null && !fromKey.equals(toKey) && fromPath != null && toPath != null && !fromPath.equals(toPath)) {
        if (config.isAliasLinking()) {
            final File fromFile = getDetachedFile(from);
            final File toFile = getDetachedFile(to);
            FileUtils.copyFile(fromFile, toFile);
        //                Files.createLink( Paths.get( fromFile.toURI() ), Paths.get( toFile.toURI() ) );
        } else {
            copy(from, to);
        }
    }
}
Also used : File(java.io.File) Location(org.commonjava.maven.galley.model.Location)

Aggregations

Location (org.commonjava.maven.galley.model.Location)58 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)28 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)26 Test (org.junit.Test)25 Transfer (org.commonjava.maven.galley.model.Transfer)14 ArrayList (java.util.ArrayList)13 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)11 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)11 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 OutputStream (java.io.OutputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 URI (java.net.URI)6 RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)6 TransferException (org.commonjava.maven.galley.TransferException)6 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)6 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)5