use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class NodeStoreTest method shouldTellNodeInUse.
@Test
public void shouldTellNodeInUse() throws Exception {
// Given
EphemeralFileSystemAbstraction fs = efs.get();
NodeStore store = newNodeStore(fs);
long exists = store.nextId();
store.updateRecord(new NodeRecord(exists, false, 10, 20, true));
long deleted = store.nextId();
store.updateRecord(new NodeRecord(deleted, false, 10, 20, true));
store.updateRecord(new NodeRecord(deleted, false, 10, 20, false));
// When & then
assertTrue(store.isInUse(exists));
assertFalse(store.isInUse(deleted));
assertFalse(store.isInUse(nodeStore.recordFormat.getMaxId()));
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class LegacyBatchIndexApplierTest method newIndexConfigStore.
private IndexConfigStore newIndexConfigStore(Map<String, Integer> names, String providerName) {
File dir = new File("conf");
EphemeralFileSystemAbstraction fileSystem = fs.get();
fileSystem.mkdirs(dir);
IndexConfigStore store = life.add(new IndexConfigStore(dir, fileSystem));
for (Map.Entry<String, Integer> name : names.entrySet()) {
store.set(Node.class, name.getKey(), stringMap(IndexManager.PROVIDER, providerName));
store.set(Relationship.class, name.getKey(), stringMap(IndexManager.PROVIDER, providerName));
}
return store;
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class StateRecoveryManagerTest method shouldRecoverFromPartiallyWrittenEntriesInBothFiles.
@Test
public void shouldRecoverFromPartiallyWrittenEntriesInBothFiles() throws Exception {
// given
EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
fsa.mkdir(testDir.directory());
StateRecoveryManager<Long> manager = new StateRecoveryManager<>(fsa, new LongMarshal());
writeSomeLongsIn(fsa, fileA(), 3, 4);
writeSomeLongsIn(fsa, fileB(), 5, 6);
writeSomeGarbage(fsa, fileA());
writeSomeGarbage(fsa, fileB());
// when
final StateRecoveryManager.RecoveryStatus recovered = manager.recover(fileA(), fileB());
// then
assertEquals(fileA(), recovered.activeFile());
assertEquals(6L, recovered.recoveredState());
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class StateRecoveryManagerTest method shouldReturnPreviouslyInactiveWhenOneFileFullAndOneEmpty.
@Test
public void shouldReturnPreviouslyInactiveWhenOneFileFullAndOneEmpty() throws Exception {
// given
EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
fsa.mkdir(testDir.directory());
File fileA = fileA();
StoreChannel channel = fsa.create(fileA);
fillUpAndForce(channel);
File fileB = fileB();
fsa.create(fileB);
StateRecoveryManager<Long> manager = new StateRecoveryManager<>(fsa, new LongMarshal());
// when
final StateRecoveryManager.RecoveryStatus recoveryStatus = manager.recover(fileA, fileB);
// then
assertEquals(fileB, recoveryStatus.activeFile());
}
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