use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldWriteSomeDataIntoTheLog.
@Test
public void shouldWriteSomeDataIntoTheLog() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
Monitor monitor = mock(Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, monitor, new LogHeaderCache(10)));
// WHEN
try {
life.start();
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
writer.getCurrentPosition(positionMarker);
int intValue = 45;
long longValue = 4854587;
writer.putInt(intValue);
writer.putLong(longValue);
writer.prepareForFlush().flush();
// THEN
try (ReadableClosableChannel reader = logFile.getReader(positionMarker.newPosition())) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
}
} finally {
life.shutdown();
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldReadOlderLogs.
@Test
public void shouldReadOlderLogs() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
// WHEN
life.start();
try {
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
writer.getCurrentPosition(positionMarker);
LogPosition position1 = positionMarker.newPosition();
int intValue = 45;
long longValue = 4854587;
byte[] someBytes = someBytes(40);
writer.putInt(intValue);
writer.putLong(longValue);
writer.put(someBytes, someBytes.length);
writer.prepareForFlush().flush();
writer.getCurrentPosition(positionMarker);
LogPosition position2 = positionMarker.newPosition();
long longValue2 = 123456789L;
writer.putLong(longValue2);
writer.put(someBytes, someBytes.length);
writer.prepareForFlush().flush();
// THEN
try (ReadableClosableChannel reader = logFile.getReader(position1)) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
try (ReadableClosableChannel reader = logFile.getReader(position2)) {
assertEquals(longValue2, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
} finally {
life.shutdown();
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldVisitLogFile.
@Test
public void shouldVisitLogFile() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
life.start();
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker mark = new LogPositionMarker();
writer.getCurrentPosition(mark);
for (int i = 0; i < 5; i++) {
writer.put((byte) i);
}
writer.prepareForFlush();
// WHEN/THEN
final AtomicBoolean called = new AtomicBoolean();
logFile.accept((position, channel) -> {
for (int i = 0; i < 5; i++) {
assertEquals((byte) i, channel.get());
}
called.set(true);
return true;
}, mark.newPosition());
assertTrue(called.get());
life.shutdown();
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class ApplyRecoveredTransactionsTest method before.
@Before
public void before() {
FileSystemAbstraction fs = fsr.get();
File storeDir = new File("dir");
StoreFactory storeFactory = new StoreFactory(storeDir, Config.empty(), new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), fs, NullLogProvider.getInstance());
neoStores = storeFactory.openAllNeoStores(true);
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class StoreLockerTest method shouldNotObtainLockWhenStoreAlreadyInUse.
@Test
public void shouldNotObtainLockWhenStoreAlreadyInUse() throws Exception {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {
@Override
public boolean fileExists(File fileName) {
return false;
}
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public FileLock tryLock() throws IOException {
// 'null' implies that the file has been externally locked
return null;
}
};
}
};
try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
storeLocker.checkLock(target.directory("unused"));
fail();
} catch (StoreLockException e) {
assertThat(e.getMessage(), containsString("Store and its lock file has been locked by another process"));
}
}
Aggregations