Search in sources :

Example 1 with ConcreteResource

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

the class EmbeddableCDI_HTTPDownload_Test method resolveFileViaHttp.

@Test
public void resolveFileViaHttp() throws Exception {
    String path = "/path/to/file.txt";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new ConcreteResource(new SimpleLocation(server.getBaseUri()), path));
    assertThat(transfer, notNullValue());
    InputStream stream = null;
    try {
        stream = transfer.openInputStream();
        assertThat(IOUtils.toString(stream), equalTo(content));
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Test(org.junit.Test)

Example 2 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource 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 3 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource 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 4 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource 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 5 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentTest method testBothReadWithNFS.

@Test
public void testBothReadWithNFS() throws Exception {
    final ConcreteResource resource = createTestResource("file_both_read_has_only_NFS.txt");
    prepareNFSResource(resource, content);
    final Future<String> readingFuture1 = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    final Future<String> readingFuture2 = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    latchWait(latch);
    final String readingResult1 = readingFuture1.get();
    assertThat(readingResult1, equalTo(content));
    final String readingResult2 = readingFuture2.get();
    assertThat(readingResult2, equalTo(content));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)206 Test (org.junit.Test)138 Transfer (org.commonjava.maven.galley.model.Transfer)92 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)55 Location (org.commonjava.maven.galley.model.Location)45 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)36 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)33 OutputStream (java.io.OutputStream)30 InputStream (java.io.InputStream)26 Group (org.commonjava.indy.model.core.Group)25 ArrayList (java.util.ArrayList)23 HostedRepository (org.commonjava.indy.model.core.HostedRepository)23 TransferException (org.commonjava.maven.galley.TransferException)23 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)23 HashSet (java.util.HashSet)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)18 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)18 Logger (org.slf4j.Logger)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16