use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FailureStorage method readFailure.
private String readFailure(File failureFile) throws IOException {
try (StoreChannel channel = fs.open(failureFile, "r")) {
byte[] data = new byte[(int) channel.size()];
int readData = channel.read(ByteBuffer.wrap(data));
return readData <= 0 ? "" : UTF8.decode(withoutZeros(data));
}
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FailureStorage method reserveForIndex.
/**
* Create/reserve an empty failure file for the given indexId.
*
* This will overwrite any pre-existing failure file.
*
* @throws IOException if the failure file could not be created
*/
public synchronized void reserveForIndex() throws IOException {
fs.mkdirs(folderLayout.getIndexFolder());
File failureFile = failureFile();
try (StoreChannel channel = fs.create(failureFile)) {
channel.write(ByteBuffer.wrap(new byte[MAX_FAILURE_SIZE]));
channel.force(true);
}
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FileSenderTest method sendLargeFile.
@Test
public void sendLargeFile() throws Exception {
// given
int dataSize = MAX_SIZE + (MAX_SIZE / 2);
byte[] bytes = new byte[dataSize];
random.nextBytes(bytes);
File smallFile = testDirectory.file("smallFile");
try (StoreChannel storeChannel = fs.create(smallFile)) {
storeChannel.write(ByteBuffer.wrap(bytes));
}
FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
// when + then
assertFalse(fileSender.isEndOfInput());
assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, bytes.length), true), fileSender.readChunk(allocator));
assertNull(fileSender.readChunk(allocator));
assertTrue(fileSender.isEndOfInput());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FileSenderTest method sendLargeFileWithSizeMultipleOfTheChunkSize.
@Test
public void sendLargeFileWithSizeMultipleOfTheChunkSize() throws Exception {
// given
byte[] bytes = new byte[MAX_SIZE * 3];
random.nextBytes(bytes);
File smallFile = testDirectory.file("smallFile");
try (StoreChannel storeChannel = fs.create(smallFile)) {
storeChannel.write(ByteBuffer.wrap(bytes));
}
FileSender fileSender = new FileSender(fs.open(smallFile, "r"));
// when + then
assertFalse(fileSender.isEndOfInput());
assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
assertNull(fileSender.readChunk(allocator));
assertTrue(fileSender.isEndOfInput());
}
use of org.neo4j.io.fs.StoreChannel in project neo4j by neo4j.
the class FileSenderTest method sendLargeFileWithUnreliableReadBufferSize.
@Test
public void sendLargeFileWithUnreliableReadBufferSize() throws Exception {
// given
byte[] bytes = new byte[MAX_SIZE * 3];
random.nextBytes(bytes);
File smallFile = testDirectory.file("smallFile");
try (StoreChannel storeChannel = fs.create(smallFile)) {
storeChannel.write(ByteBuffer.wrap(bytes));
}
Adversary adversary = new RandomAdversary(0.9, 0.0, 0.0);
AdversarialFileSystemAbstraction afs = new AdversarialFileSystemAbstraction(adversary, fs);
FileSender fileSender = new FileSender(afs.open(smallFile, "r"));
// when + then
assertFalse(fileSender.isEndOfInput());
assertEquals(FileChunk.create(copyOfRange(bytes, 0, MAX_SIZE), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE, MAX_SIZE * 2), false), fileSender.readChunk(allocator));
assertEquals(FileChunk.create(copyOfRange(bytes, MAX_SIZE * 2, bytes.length), true), fileSender.readChunk(allocator));
assertNull(fileSender.readChunk(allocator));
assertTrue(fileSender.isEndOfInput());
}
Aggregations