Search in sources :

Example 51 with ConcreteResource

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

the class FastLocalCacheProviderIOTest method testTwoFilesOpenInDiffFolderAndSingleThreadDeSequenceCase1.

/**
 * File IO sequence as below: (file1 and file2 NOT in same folder)
 *
 *   file1 open-> file2 open-> file2 close -> file1 close
 */
@Test
public void testTwoFilesOpenInDiffFolderAndSingleThreadDeSequenceCase1() throws IOException {
    final String content1 = "This is a test for f1";
    final String content2 = "This is a test for f2";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname1 = "/path1/to1/my1/file1.txt";
    final String fname2 = "/path2/to2/my2/file2.txt";
    ConcreteResource resource1 = new ConcreteResource(loc, fname1);
    OutputStream out1 = writeWithoutClose(resource1, content1);
    ConcreteResource resource2 = new ConcreteResource(loc, fname2);
    OutputStream out2 = writeWithoutClose(resource2, content2);
    out2.close();
    provider.unlockWrite(resource2);
    out1.close();
    provider.unlockWrite(resource1);
    String result1 = readWithClose(resource1);
    assertThat(result1, equalTo(content1));
    String result2 = readWithClose(resource2);
    assertThat(result2, equalTo(content2));
}
Also used : OutputStream(java.io.OutputStream) 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) Test(org.junit.Test)

Example 52 with ConcreteResource

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

the class FastLocalCacheProviderIOTest method testTwoFilesOpenInSameFolderAndSingleThreadInSequence.

/**
 * File IO sequence as below: (file1 and file2 in same folder)
 *
 *   file1 open-> file1 close-> file2 open-> file2 close
 */
@Test
public void testTwoFilesOpenInSameFolderAndSingleThreadInSequence() throws IOException {
    final String content1 = "This is a test for f1";
    final String content2 = "This is a test for f2";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname1 = "/path/to/my/file1.txt";
    final String fname2 = "/path/to/my/file2.txt";
    ConcreteResource resource1 = new ConcreteResource(loc, fname1);
    writeWithClose(resource1, content1);
    ConcreteResource resource2 = new ConcreteResource(loc, fname2);
    writeWithClose(resource2, content2);
    String result1 = readWithClose(resource1);
    assertThat(result1, equalTo(content1));
    String result2 = readWithClose(resource2);
    assertThat(result2, equalTo(content2));
}
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) Test(org.junit.Test)

Example 53 with ConcreteResource

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

the class FastLocalCacheProviderIOTest method testTwoFilesOpenInDiffFolderAndSingleThreadInSequence.

/**
 * File IO sequence as below: (file1 and file2 NOT in same folder)
 *
 *   file1 open-> file1 close-> file2 open-> file2 close
 */
@Test
public void testTwoFilesOpenInDiffFolderAndSingleThreadInSequence() throws IOException {
    final String content1 = "This is a test for f1";
    final String content2 = "This is a test for f2";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname1 = "/path1/to1/my1/file1.txt";
    final String fname2 = "/path2/to2/my2/file2.txt";
    ConcreteResource resource1 = new ConcreteResource(loc, fname1);
    writeWithClose(resource1, content1);
    ConcreteResource resource2 = new ConcreteResource(loc, fname2);
    writeWithClose(resource2, content2);
    String result1 = readWithClose(resource1);
    assertThat(result1, equalTo(content1));
    String result2 = readWithClose(resource2);
    assertThat(result2, equalTo(content2));
}
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) Test(org.junit.Test)

Example 54 with ConcreteResource

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

the class FastLocalCacheProviderIOTest 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 55 with ConcreteResource

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

the class FastLocalCacheProviderIOTest method testTwoFilesOpenInSameFolderAndSingleThreadDeSequenceCase1.

/**
 * File IO sequence as below: (file1 and file2 in same folder)
 *
 *   file1 open-> file2 open-> file2 close -> file1 close
 */
@Test
public void testTwoFilesOpenInSameFolderAndSingleThreadDeSequenceCase1() throws IOException {
    final String content1 = "This is a test for f1";
    final String content2 = "This is a test for f2";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname1 = "/path/to/my/file1.txt";
    final String fname2 = "/path/to/my/file2.txt";
    ConcreteResource resource1 = new ConcreteResource(loc, fname1);
    OutputStream out1 = writeWithoutClose(resource1, content1);
    ConcreteResource resource2 = new ConcreteResource(loc, fname2);
    OutputStream out2 = writeWithoutClose(resource2, content2);
    out2.close();
    provider.unlockWrite(resource2);
    out1.close();
    provider.unlockWrite(resource1);
    String result1 = readWithClose(resource1);
    assertThat(result1, equalTo(content1));
    String result2 = readWithClose(resource2);
    assertThat(result2, equalTo(content2));
}
Also used : OutputStream(java.io.OutputStream) 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) 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