Search in sources :

Example 46 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentIOTest method testWriteWhenReadOpenWithNFS.

@Test
@BMScript("TryToWriteThenWaitReadingStreamOpen.btm")
public void testWriteWhenReadOpenWithNFS() throws Exception {
    final ConcreteResource resource = createTestResource("file_write_wait_read_has_only_NFS.txt");
    prepareNFSResource(resource, content);
    testPool.execute(new WriteTask(provider, diffContent, resource, latch));
    // make sure write task execute first
    Thread.sleep(500);
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch, 500));
    if (!TestIOUtils.latchWait(latch, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
        fail("I/O timeout");
    }
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(diffContent));
    final String changedResult = readLocalResource(resource);
    assertThat(changedResult, equalTo(diffContent));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) WriteTask(org.commonjava.maven.galley.cache.iotasks.WriteTask) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 47 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentIOTest method testDeleteWhenReadNotCompleted.

@Test
@BMScript("TryToDeleteWhileReadingNotCompleted.btm")
public void testDeleteWhenReadNotCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_delete_read_not_completed.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch, 1000));
    assertLatchWait();
    final Boolean deleted = deleteFuture.get();
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(content));
    assertThat(deleted, equalTo(false));
    assertThat(provider.exists(resource), equalTo(true));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DeleteTask(org.commonjava.maven.galley.cache.iotasks.DeleteTask) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 48 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentIOTest method testDeleteWhenReadCompleted.

@Test
@BMScript("TryToDeleteWhileReadingCompleted.btm")
public void testDeleteWhenReadCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_delete_read.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    if (!TestIOUtils.latchWait(latch, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
        fail("I/O timeout");
    }
    final Boolean deleted = deleteFuture.get();
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(content));
    assertThat(deleted, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DeleteTask(org.commonjava.maven.galley.cache.iotasks.DeleteTask) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 49 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentIOTest method testBothDelete.

@Test
public void testBothDelete() throws Exception {
    final ConcreteResource resource = createTestResource("file_both_delete.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFurture1 = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<Boolean> deleteFurture2 = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    assertLatchWait();
    final Boolean deleted1 = deleteFurture1.get();
    final Boolean deleted2 = deleteFurture2.get();
    assertThat(deleted1 && deleted2, equalTo(false));
    assertThat(deleted1 || deleted2, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DeleteTask(org.commonjava.maven.galley.cache.iotasks.DeleteTask) Test(org.junit.Test)

Example 50 with ConcreteResource

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

the class FastLocalCacheProviderConcurrentIOTest method testReadWhileDeleteCompleted.

@Test
@BMScript("TryToReadWhileDeleteCompleted.btm")
public void testReadWhileDeleteCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_read_delete_completed.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    assertLatchWait();
    final Boolean deleted = deleteFuture.get();
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(null));
    assertThat(deleted, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) DeleteTask(org.commonjava.maven.galley.cache.iotasks.DeleteTask) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

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