Search in sources :

Example 36 with Location

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

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

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

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

use of org.commonjava.maven.galley.model.Location 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)

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