Search in sources :

Example 6 with ReadTask

use of org.commonjava.maven.galley.cache.iotasks.ReadTask 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 7 with ReadTask

use of org.commonjava.maven.galley.cache.iotasks.ReadTask 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 8 with ReadTask

use of org.commonjava.maven.galley.cache.iotasks.ReadTask 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)

Example 9 with ReadTask

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

the class PartyLineCacheProviderConcurrentIOTest method testReadWrite.

@Test
@BMScript("TryToReadWhileWriting.btm")
public void testReadWrite() throws Exception {
    final ConcreteResource resource = createTestResource("file_read_write.txt");
    testPool.execute(new WriteTask(provider, content, resource, latch, 1000));
    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();
    assertThat(readingResult, equalTo(content));
    assertThat(provider.exists(resource), equalTo(true));
    assertThat(TestIOUtils.readFromStream(new FileInputStream(provider.getDetachedFile(resource))), equalTo(content));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) WriteTask(org.commonjava.maven.galley.cache.iotasks.WriteTask) FileInputStream(java.io.FileInputStream) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 10 with ReadTask

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

the class PartyLineCacheProviderConcurrentIOTest method testBigFileReadWrite.

@Test
@BMScript("TryToReadWhileWriting.btm")
public void testBigFileReadWrite() throws Exception {
    StringBuilder builder = new StringBuilder();
    int loop = 1024 * 1024 * 10;
    for (int i = 0; i < loop; i++) {
        builder.append(content);
    }
    final String bigContent = builder.toString();
    System.out.println(String.format("the content size is: %dm", bigContent.length() / 1024 / 1024));
    final ConcreteResource resource = createTestResource("file_read_write_bigfile.txt");
    testPool.execute(new WriteTask(provider, bigContent, 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();
    assertThat(readingResult, equalTo(bigContent));
    assertThat(provider.exists(resource), equalTo(true));
    assertThat(TestIOUtils.readFromStream(new FileInputStream(provider.getDetachedFile(resource))), equalTo(bigContent));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) WriteTask(org.commonjava.maven.galley.cache.iotasks.WriteTask) FileInputStream(java.io.FileInputStream) ReadTask(org.commonjava.maven.galley.cache.iotasks.ReadTask) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

ReadTask (org.commonjava.maven.galley.cache.iotasks.ReadTask)13 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)13 Test (org.junit.Test)13 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)12 WriteTask (org.commonjava.maven.galley.cache.iotasks.WriteTask)8 DeleteTask (org.commonjava.maven.galley.cache.iotasks.DeleteTask)4 FileInputStream (java.io.FileInputStream)2