use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestGraphProperties method produceUncleanStore.
private EphemeralFileSystemAbstraction produceUncleanStore(EphemeralFileSystemAbstraction fileSystem, File storeDir) {
GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabase(storeDir);
Transaction tx = db.beginTx();
Node node = db.createNode();
node.setProperty("name", "Something");
properties((GraphDatabaseAPI) db).setProperty("prop", "Some value");
tx.success();
tx.close();
EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot();
db.shutdown();
return snapshot;
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestGraphProperties method twoUncleanInARow.
@Test
public void twoUncleanInARow() throws Exception {
File storeDir = new File("dir");
try (EphemeralFileSystemAbstraction snapshot = produceUncleanStore(fs.get(), storeDir)) {
try (EphemeralFileSystemAbstraction snapshot2 = produceUncleanStore(snapshot, storeDir)) {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(produceUncleanStore(snapshot2, storeDir)).newImpermanentDatabase(storeDir);
assertThat(properties(db), inTx(db, hasProperty("prop").withValue("Some value")));
db.shutdown();
}
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class TestStoreAccess method openingThroughStoreAccessShouldNotTriggerRecovery.
@Test
public void openingThroughStoreAccessShouldNotTriggerRecovery() throws Exception {
try (EphemeralFileSystemAbstraction snapshot = produceUncleanStore()) {
assertTrue("Store should be unclean", isUnclean(snapshot));
File messages = new File(storeDir, "debug.log");
snapshot.deleteFile(messages);
PageCache pageCache = pageCacheRule.getPageCache(snapshot);
new StoreAccess(snapshot, pageCache, storeDir).initialize().close();
assertTrue("Store should be unclean", isUnclean(snapshot));
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LegacyLogsTest method shouldRenameFiles.
@Test
public void shouldRenameFiles() throws Exception {
// given
try (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction()) {
fs.mkdirs(storeDir);
final File unrelated = new File(storeDir, "unrelated");
final List<File> files = Arrays.asList(new File(storeDir, "active_tx_log"), new File(storeDir, "tm_tx_log.v0"), new File(storeDir, "tm_tx_log.v1"), new File(storeDir, "nioneo_logical.log.1"), new File(storeDir, "nioneo_logical.log.2"), new File(storeDir, getLegacyLogFilename(1)), new File(storeDir, getLegacyLogFilename(2)), unrelated);
for (File file : files) {
fs.create(file).close();
}
// when
new LegacyLogs(fs, reader, writer).renameLogFiles(storeDir);
// then
final Set<File> expected = new HashSet<>(Arrays.asList(unrelated, new File(storeDir, getLogFilenameForVersion(1)), new File(storeDir, getLogFilenameForVersion(2))));
assertEquals(expected, new HashSet<>(Arrays.asList(fs.listFiles(storeDir))));
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DurableStateStorageIT method shouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation.
@Test
public void shouldProperlyRecoveryAfterCloseOnActiveFileDuringRotation() throws Exception {
EphemeralFileSystemAbstraction normalFSA = fileSystemRule.get();
AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(5, true), StoreChannel.class.getMethod("close")), normalFSA);
SelectiveFileSystemAbstraction combinedFSA = new SelectiveFileSystemAbstraction(new File(new File(testDir.directory(), "long-state"), "long.a"), breakingFSA, normalFSA);
long lastValue = 0;
try (LongState persistedState = new LongState(combinedFSA, testDir.directory(), 14)) {
while (// it will break from the Exception that AFS will throw
true) {
long tempValue = lastValue + 1;
persistedState.setTheState(tempValue);
lastValue = tempValue;
}
} catch (Exception expected) {
// this stack trace should contain close()
ensureStackTraceContainsExpectedMethod(expected.getStackTrace(), "close");
}
try (LongState restoredState = new LongState(normalFSA, testDir.directory(), 14)) {
assertThat(restoredState.getTheState(), greaterThanOrEqualTo(lastValue));
}
}
Aggregations