use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LegacyLogsTest method shouldMoveFiles.
@Test
public void shouldMoveFiles() throws Exception {
// given
try (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) {
fs.mkdirs(storeDir);
fs.mkdirs(migrationDir);
final Set<File> logsInStoreDir = new HashSet<>(Arrays.asList(new File(storeDir, getLegacyLogFilename(1)), new File(storeDir, getLegacyLogFilename(2))));
final List<File> logsInMigrationDir = Arrays.asList(new File(migrationDir, getLegacyLogFilename(1)), new File(migrationDir, getLegacyLogFilename(2)));
for (File file : logsInMigrationDir) {
try (StoreChannel channel = fs.create(file)) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putLong(42);
buffer.flip();
channel.write(buffer);
}
}
// should override older files
for (File file : logsInStoreDir) {
try (StoreChannel channel = fs.create(file)) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putLong(13);
buffer.flip();
channel.write(buffer);
}
}
// when
new LegacyLogs(fs, reader, writer).operate(FileOperation.MOVE, migrationDir, storeDir);
// then
assertEquals(logsInStoreDir, new HashSet<>(Arrays.asList(fs.listFiles(storeDir))));
for (File file : logsInStoreDir) {
try (StoreChannel channel = fs.open(file, "r")) {
ByteBuffer buffer = ByteBuffer.allocate(8);
channel.read(buffer);
buffer.flip();
assertEquals(42, buffer.getLong());
}
}
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class ReadAheadChannelTest method shouldReturnPositionWithinBufferedStream.
@Test
public void shouldReturnPositionWithinBufferedStream() throws Exception {
// given
EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
File file = new File("foo.txt");
int readAheadSize = 512;
int fileSize = readAheadSize * 8;
createFile(fsa, file, fileSize);
ReadAheadChannel<StoreChannel> bufferedReader = new ReadAheadChannel<>(fsa.open(file, "r"), readAheadSize);
// when
for (int i = 0; i < fileSize / Long.BYTES; i++) {
assertEquals(Long.BYTES * i, bufferedReader.position());
bufferedReader.getLong();
}
assertEquals(fileSize, bufferedReader.position());
try {
bufferedReader.getLong();
fail();
} catch (ReadPastEndException e) {
// expected
}
assertEquals(fileSize, bufferedReader.position());
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestTxEntries method testStartEntryWrittenOnceOnRollback.
/*
* Starts a JVM, executes a tx that fails on prepare and rollbacks,
* triggering a bug where an extra start entry for that tx is written
* in the xa log.
*/
@Test
public void testStartEntryWrittenOnceOnRollback() throws Exception {
final GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabase(storeDir);
createSomeTransactions(db);
EphemeralFileSystemAbstraction snapshot = fs.snapshot(() -> db.shutdown());
new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase(storeDir).shutdown();
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestEphemeralFileChannel method absoluteVersusRelative.
@Test
public void absoluteVersusRelative() throws Exception {
// GIVEN
File file = new File("myfile");
EphemeralFileSystemAbstraction fs = fileSystemRule.get();
StoreChannel channel = fs.open(file, "rw");
byte[] bytes = "test".getBytes();
channel.write(ByteBuffer.wrap(bytes));
channel.close();
// WHEN
channel = fs.open(new File(file.getAbsolutePath()), "r");
byte[] readBytes = new byte[bytes.length];
int nrOfReadBytes = channel.read(ByteBuffer.wrap(readBytes));
// THEN
assertEquals(bytes.length, nrOfReadBytes);
assertTrue(Arrays.equals(bytes, readBytes));
fs.close();
}
Aggregations