use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.
the class PartyLineCacheProviderConcurrentIOTest method testBigFileWrite.
@Test
public void testBigFileWrite() 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");
new WriteTask(provider, bigContent, resource, null).run();
assertThat(provider.exists(resource), equalTo(true));
assertThat(TestIOUtils.readFromStream(new FileInputStream(provider.getDetachedFile(resource))), equalTo(bigContent));
}
use of org.commonjava.maven.galley.cache.iotasks.WriteTask 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));
}
use of org.commonjava.maven.galley.cache.iotasks.WriteTask 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));
}
use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentIOTest method testWriteReadWithNFS.
@Test
@BMScript("TryToWriteWhileReading.btm")
public void testWriteReadWithNFS() throws Exception {
final ConcreteResource resource = createTestResource("file_write_read_has_only_NFS.txt");
prepareNFSResource(resource, content);
testPool.execute(new WriteTask(provider, diffContent, 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(content));
final String changedResult = readLocalResource(resource);
assertThat(changedResult, equalTo(diffContent));
}
use of org.commonjava.maven.galley.cache.iotasks.WriteTask in project galley by Commonjava.
the class FastLocalCacheProviderConcurrentIOTest method testDeleteWhenWriteCompleted.
@Test
@BMScript("TryToDeleteWhileWritingCompleted.btm")
public void testDeleteWhenWriteCompleted() throws Exception {
final ConcreteResource resource = createTestResource("file_delete_write_completed.txt");
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(false));
}
Aggregations