use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class RotatingFileOutputStreamSupplierTest method shouldCloseAllOutputStreams.
@Test
public void shouldCloseAllOutputStreams() throws Exception {
final List<OutputStream> mockStreams = new ArrayList<>();
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public OutputStream openAsOutputStream(File fileName, boolean append) throws IOException {
final OutputStream stream = spy(super.openAsOutputStream(fileName, append));
mockStreams.add(stream);
return stream;
}
};
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, logFile, 10, 0, 10, DIRECT_EXECUTOR);
write(supplier, "A string longer than 10 bytes");
supplier.close();
assertStreamClosed(mockStreams.get(0));
}
use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class StoreUpgraderTest method failMigrationWhenFailDuringTransactionInformationRetrieval.
@Test
public void failMigrationWhenFailDuringTransactionInformationRetrieval() throws IOException {
File storeDirectory = directory.graphDbDir();
File prepare = directory.directory("prepare");
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(fileSystem) {
@Override
public File[] listFiles(File directory, FilenameFilter filter) {
if (filter == LegacyLogFilenames.versionedLegacyLogFilesFilter) {
sneakyThrow(new IOException("Enforced IO Exception Fail to open file"));
}
return super.listFiles(directory, filter);
}
};
prepareSampleDatabase(version, fs, storeDirectory, prepare);
// and a state of the migration saying that it has done the actual migration
PageCache pageCache = pageCacheRule.getPageCache(fs);
// remove metadata store record to force tx info lookup in tx logs
MetaDataStore.setRecord(pageCache, new File(storeDirectory, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, MetaDataRecordFormat.FIELD_NOT_PRESENT);
UpgradableDatabase upgradableDatabase = new UpgradableDatabase(fs, new StoreVersionCheck(pageCache), new LegacyStoreVersionCheck(fs), getRecordFormats()) {
@Override
public RecordFormats checkUpgradeable(File storeDirectory) {
return getRecordFormats();
}
};
SilentMigrationProgressMonitor progressMonitor = new SilentMigrationProgressMonitor();
StoreMigrator defaultMigrator = new StoreMigrator(fs, pageCache, getTuningConfig(), NullLogService.getInstance(), schemaIndexProvider);
StoreUpgrader upgrader = new StoreUpgrader(upgradableDatabase, progressMonitor, allowMigrateConfig, fs, pageCache, NullLogProvider.getInstance());
upgrader.addParticipant(defaultMigrator);
expectedException.expect(UnableToUpgradeException.class);
expectedException.expectCause(instanceOf(IOException.class));
expectedException.expectCause(hasMessage(containsString("Enforced IO Exception Fail to open file")));
upgrader.migrateIfNeeded(storeDirectory);
}
Aggregations