Search in sources :

Example 1 with WriteTask

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

the class FastLocalCacheProviderConcurrentIOTest 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.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(readLocalResource(resource), equalTo(bigContent));
    assertThat(readNFSResource(resource), equalTo(bigContent));
}
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 2 with WriteTask

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

the class FastLocalCacheProviderConcurrentIOTest method multiWriteOnFilesInFolder.

private void multiWriteOnFilesInFolder(final Map<String, String> fileFolderMap, final int threads) throws Exception {
    List<ConcreteResource> resources = new ArrayList<>(fileFolderMap.size());
    for (String fname : fileFolderMap.keySet()) {
        final String folder = fileFolderMap.get(fname);
        resources.add(createTestResource(fname, folder));
    }
    final CountDownLatch waitLatch = new CountDownLatch(resources.size() * threads);
    for (ConcreteResource resource : resources) {
        IntStream.range(0, threads).forEach(i -> testPool.execute(new WriteTask(provider, content, resource, waitLatch)));
    }
    TestIOUtils.latchWait(waitLatch, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    for (ConcreteResource resource : resources) {
        final String localResult = readLocalResource(resource);
        final String nfsResult = readNFSResource(resource);
        assertThat(localResult, equalTo(nfsResult));
    }
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) WriteTask(org.commonjava.maven.galley.cache.iotasks.WriteTask) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with WriteTask

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

the class FastLocalCacheProviderConcurrentIOTest method tesWriteReadWithLocal.

@Test
@BMScript("TryToWriteWhileReading.btm")
public void tesWriteReadWithLocal() throws Exception {
    final ConcreteResource resource = createTestResource("file_write_read.txt");
    prepareBothResource(resource, content);
    testPool.execute(new WriteTask(provider, diffContent, 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));
    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 4 with WriteTask

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

the class FastLocalCacheProviderConcurrentIOTest 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(readLocalResource(resource), equalTo(content));
    assertThat(readNFSResource(resource), 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 5 with WriteTask

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

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