Search in sources :

Example 1 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider 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 2 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider 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 3 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider 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 4 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project galley by Commonjava.

the class FileCacheProviderTest method testGetDetachedFile.

@Test
public void testGetDetachedFile() 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 ConcreteResource resource = new ConcreteResource(loc, fname);
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(resource);
    out.write(content.getBytes("UTF-8"));
    out.close();
    File file = provider.asAdminView().getDetachedFile(resource);
    assertThat(provider.exists(resource), equalTo(true));
    assertTrue(file.exists());
}
Also used : OutputStream(java.io.OutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) File(java.io.File) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 5 with CacheProvider

use of org.commonjava.maven.galley.spi.cache.CacheProvider in project galley by Commonjava.

the class CacheProviderTCK method writeAndListDirectory.

@Test
public void writeAndListDirectory() 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.flush();
    out.close();
    // NOTE: This is NOT as tightly specified as I would like.
    // We keep the listing assertions loose (greater-than instead of equals,
    // contains instead of exact positional assertion) because the Infinispan
    // live testing has these spurious foo.txt.#0 files cropping up.
    // 
    // I have no idea what they are, but I'm sick of fighting JBoss bugs for now.
    final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
    System.out.printf("\n\nFile listing is:\n\n  %s\n\n\n", join(listing, "\n  "));
    assertThat(listing.size() > 0, equalTo(true));
    assertThat(listing.contains("file.txt"), 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)12 Location (org.commonjava.maven.galley.model.Location)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)10 Test (org.junit.Test)10 OutputStream (java.io.OutputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 File (java.io.File)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 TransferManager (org.commonjava.maven.galley.TransferManager)1 MemoryPasswordManager (org.commonjava.maven.galley.auth.MemoryPasswordManager)1 FileCacheProvider (org.commonjava.maven.galley.cache.FileCacheProvider)1 TestFileEventManager (org.commonjava.maven.galley.cache.testutil.TestFileEventManager)1 TestTransferDecorator (org.commonjava.maven.galley.cache.testutil.TestTransferDecorator)1 TransportManagerConfig (org.commonjava.maven.galley.config.TransportManagerConfig)1 NoOpFileEventManager (org.commonjava.maven.galley.event.NoOpFileEventManager)1 FileTransport (org.commonjava.maven.galley.filearc.FileTransport)1