Search in sources :

Example 26 with SimpleLocation

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

the class EmbeddableCDI_HTTPArtifactMetadataDownload_Test method resolveArtifactViaHttp.

@Test
public void resolveArtifactViaHttp() throws Exception {
    String path = "/group/artifact/1-SNAPSHOT/maven-metadata.xml";
    String content = "this is a test.";
    server.expect(path, 200, content);
    Transfer transfer = transfers.retrieve(new SimpleLocation(server.getBaseUri()), new SimpleProjectVersionRef("group", "artifact", "1-SNAPSHOT").asPomArtifact());
    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) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Test(org.junit.Test)

Example 27 with SimpleLocation

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

the class FastLocalCacheProviderTest method testSimultaneousWritesResourceExistence.

@Test
@BMScript("SimultaneousWritesResourceExistence.btm")
public void testSimultaneousWritesResourceExistence() 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 fname1 = dir + "file1.txt";
    final String fname2 = dir + "file2.txt";
    CountDownLatch latch = new CountDownLatch(2);
    start(new WriteFileThread(content, loc, fname1, latch));
    start(new WriteFileThread(content, loc, fname2, latch));
    latchWait(latch);
    assertThat(provider.exists(new ConcreteResource(loc, fname1)), equalTo(true));
    assertThat(provider.exists(new ConcreteResource(loc, fname2)), equalTo(true));
    assertThat(provider.isDirectory(new ConcreteResource(loc, dir)), equalTo(true));
    final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
    assertThat(listing.size() > 1, equalTo(true));
    assertThat(listing.contains("file1.txt"), equalTo(true));
    assertThat(listing.contains("file2.txt"), equalTo(true));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 28 with SimpleLocation

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

the class FastLocalCacheProviderTest method testWriteDeleteAndVerifyNonExistence.

@Test
@BMScript("WriteDeleteAndVerifyNonExistence.btm")
public void testWriteDeleteAndVerifyNonExistence() 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 WriteFileThread(content, loc, fname, latch));
    start(new DeleteFileThread(loc, fname, latch));
    latchWait(latch);
    assertThat(provider.exists(new ConcreteResource(loc, fname)), 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 29 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 30 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)

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