Search in sources :

Example 11 with WriteTask

use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentIOTest method testDeleteWhenWriteNotCompleted.

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

Example 12 with WriteTask

use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentIOTest method testWriteReadWithNoResource.

@Test
@BMScript("TryToWriteWhileReading.btm")
public void testWriteReadWithNoResource() throws Exception {
    final ConcreteResource resource = createTestResource("file_write_read_no_both_resource.txt");
    testPool.execute(new WriteTask(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 String readingResult = readingFuture.get();
    assertNull(readingResult);
    final String changedResult = readLocalResource(resource);
    assertThat(changedResult, equalTo(content));
}
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 13 with WriteTask

use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentIOTest method testWriteWhenDeleteCompleted.

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

Aggregations

WriteTask (org.commonjava.maven.galley.cache.iotasks.WriteTask)13 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)13 Test (org.junit.Test)12 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)11 ReadTask (org.commonjava.maven.galley.cache.iotasks.ReadTask)8 FileInputStream (java.io.FileInputStream)3 DeleteTask (org.commonjava.maven.galley.cache.iotasks.DeleteTask)3 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1