use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode();
tx.commit();
}
managementService.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
PageCache pageCache = createPageCache(fileSystem, scheduler, PageCacheTracer.NULL)) {
MetaDataStore.setRecord(pageCache, databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"), databaseLayout.getDatabaseName(), NULL);
}
managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
assertThrows(DatabaseShutdownException.class, databaseService::beginTx);
DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
Throwable throwable = findCauseOrSuppressed(dbStateService.causeOfFailure(databaseService.databaseId()).get(), e -> e instanceof IllegalArgumentException).get();
assertEquals("Unknown store version 'bad'", throwable.getMessage());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.io.fs.DefaultFileSystemAbstraction in project neo4j by neo4j.
the class RotatingLogFileWriter method setupLogFile.
private static Neo4jLoggerContext setupLogFile(FileSystemAbstraction fileSystemAbstraction, Path logPath, long rotationThreshold, int maxArchives, String fileSuffix, String header) {
try {
Closeable additionalCloseable = null;
Configuration configuration = new DefaultConfiguration() {
@Override
protected void setToDefault() {
// no defaults
}
};
// Just adds a header to the beginning of each file - no transformation will be done on the log messages.
PatternLayout layout = PatternLayout.newBuilder().withConfiguration(configuration).withHeader(header).build();
Appender appender;
if (fileSystemAbstraction instanceof DefaultFileSystemAbstraction) {
appender = RollingFileAppender.newBuilder().setName(APPENDER_NAME).setLayout(layout).withFileName(logPath.toString()).withFilePattern(logPath + ".%i" + fileSuffix).withPolicy(SizeBasedTriggeringPolicy.createPolicy(String.valueOf(rotationThreshold))).withStrategy(DefaultRolloverStrategy.newBuilder().withMax(String.valueOf(maxArchives)).withFileIndex("min").build()).build();
} else {
// When using a different file system than DefaultFileSystemAbstraction for tests, we cannot use log4j file appenders since
// it will create files directly in the real filesystem ignoring our abstraction.
fileSystemAbstraction.mkdirs(logPath.getParent());
OutputStream outputStream = fileSystemAbstraction.openAsOutputStream(logPath, true);
additionalCloseable = outputStream;
appender = ((OutputStreamAppender.Builder<?>) OutputStreamAppender.newBuilder().setName(APPENDER_NAME).setLayout(layout)).setTarget(outputStream).build();
}
appender.start();
configuration.addAppender(appender);
LoggerConfig rootLogger = configuration.getRootLogger();
rootLogger.addAppender(appender, null, null);
rootLogger.setLevel(Level.DEBUG);
LoggerContext context = new LoggerContext("loggercontext");
context.setConfiguration(configuration);
return new Neo4jLoggerContext(context, additionalCloseable);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations