use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class StoreMigratorTest method shouldNotDoActualStoreMigrationBetween3_0_5_and_next.
@Test
public void shouldNotDoActualStoreMigrationBetween3_0_5_and_next() throws Exception {
// GIVEN a store in vE.H.0 format
File storeDir = directory.directory();
new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, HighLimitV3_0_0.NAME).newGraphDatabase().shutdown();
Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), "8m"));
try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
PageCache pageCache = new ConfiguringPageCacheFactory(fs, config, NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance()).getOrCreatePageCache()) {
// For test code sanity
String fromStoreVersion = StoreVersion.HIGH_LIMIT_V3_0_0.versionString();
Result hasVersionResult = new StoreVersionCheck(pageCache).hasVersion(new File(storeDir, NEO_STORE.fileName(STORE)), fromStoreVersion);
assertTrue(hasVersionResult.actualVersion, hasVersionResult.outcome.isSuccessful());
// WHEN
StoreMigrator migrator = new StoreMigrator(fs, pageCache, config, NullLogService.getInstance(), NO_INDEX_PROVIDER);
MigrationProgressMonitor.Section monitor = mock(MigrationProgressMonitor.Section.class);
File migrationDir = new File(storeDir, "migration");
fs.mkdirs(migrationDir);
migrator.migrate(storeDir, migrationDir, monitor, fromStoreVersion, StoreVersion.HIGH_LIMIT_V3_0_6.versionString());
// THEN
verifyNoMoreInteractions(monitor);
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class BatchInserterImplTest method testFailsOnExistingStoreLockFile.
@Test
public void testFailsOnExistingStoreLockFile() throws IOException {
// Given
File parent = testDirectory.graphDbDir();
try (FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction();
StoreLocker lock = new StoreLocker(fileSystemAbstraction)) {
lock.checkLock(parent);
// Then
expected.expect(StoreLockException.class);
expected.expectMessage("Unable to obtain lock on store lock file");
// When
BatchInserters.inserter(parent.getAbsoluteFile(), fileSystemAbstraction);
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class RotatingFileOutputStreamSupplierTest method rotationShouldNotDeadlockOnListener.
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void rotationShouldNotDeadlockOnListener() throws Exception {
String logContent = "Output file created";
final AtomicReference<Exception> listenerException = new AtomicReference<>(null);
CountDownLatch latch = new CountDownLatch(1);
RotationListener listener = new RotationListener() {
@Override
public void outputFileCreated(OutputStream out) {
try {
Thread thread = new Thread(() -> {
try {
out.write(logContent.getBytes());
out.flush();
} catch (IOException e) {
listenerException.set(e);
}
});
thread.start();
thread.join();
} catch (Exception e) {
listenerException.set(e);
}
super.outputFileCreated(out);
}
@Override
public void rotationCompleted(OutputStream out) {
latch.countDown();
}
};
ExecutorService executor = Executors.newSingleThreadExecutor();
DefaultFileSystemAbstraction defaultFileSystemAbstraction = new DefaultFileSystemAbstraction();
RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(defaultFileSystemAbstraction, logFile, 0, 0, 10, executor, listener);
OutputStream outputStream = supplier.get();
LockingPrintWriter lockingPrintWriter = new LockingPrintWriter(outputStream);
lockingPrintWriter.withLock(() -> {
supplier.rotate();
latch.await();
return Void.TYPE;
});
executor.shutdown();
boolean terminated = executor.awaitTermination(TEST_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
if (!terminated) {
throw new IllegalStateException("Rotation execution failed to complete within reasonable time.");
}
List<String> strings = Files.readAllLines(logFile.toPath());
String actual = String.join("", strings);
assertEquals(logContent, actual);
assertNull(listenerException.get());
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class AbstractInProcessServerBuilder method newServer.
@Override
public ServerControls newServer() {
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
final OutputStream logOutputStream;
try {
logOutputStream = createOrOpenAsOuputStream(fileSystem, new File(serverFolder, "neo4j.log"), true);
} catch (IOException e) {
throw new RuntimeException("Unable to create log file", e);
}
config.put(ServerSettings.third_party_packages.name(), toStringForThirdPartyPackageProperty(extensions.toList()));
final FormattedLogProvider userLogProvider = FormattedLogProvider.toOutputStream(logOutputStream);
GraphDatabaseDependencies dependencies = GraphDatabaseDependencies.newDependencies();
Iterable<KernelExtensionFactory<?>> kernelExtensions = append(new Neo4jHarnessExtensions(procedures), dependencies.kernelExtensions());
dependencies = dependencies.kernelExtensions(kernelExtensions).userLogProvider(userLogProvider);
AbstractNeoServer neoServer = createNeoServer(config, dependencies, userLogProvider);
InProcessServerControls controls = new InProcessServerControls(serverFolder, neoServer, logOutputStream);
controls.start();
try {
fixtures.applyTo(controls);
} catch (Exception e) {
controls.close();
throw Exceptions.launderedException(e);
}
return controls;
} catch (IOException e) {
throw Exceptions.launderedException(e);
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.
@Test
public void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
// given
// create a store
File storeDir = testDirectory.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
db.shutdown();
// mess up the version in the metadatastore
String badStoreVersion = "bad";
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion));
}
// when
try {
new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true").newGraphDatabase();
fail("It should have failed.");
} catch (RuntimeException ex) {
// then
assertTrue(ex.getCause() instanceof LifecycleException);
assertTrue(ex.getCause().getCause() instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
}
}
Aggregations