use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DurableStateStorageIT method shouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation.
@Test
public void shouldProperlyRecoveryAfterCrashOnFileCreationDuringRotation() throws Exception {
EphemeralFileSystemAbstraction normalFSA = fileSystemRule.get();
/*
* Magic number warning. For a rotation threshold of 14, 998 operations on file A falls on truncation of the
* file during rotation. This has been discovered via experimentation. The end result is that there is a
* failure to create the file to rotate to. This should be recoverable.
*/
AdversarialFileSystemAbstraction breakingFSA = new AdversarialFileSystemAbstraction(new MethodGuardedAdversary(new CountingAdversary(20, true), FileSystemAbstraction.class.getMethod("truncate", File.class, long.class)), 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 FSA.truncate()
ensureStackTraceContainsExpectedMethod(expected.getStackTrace(), "truncate");
}
try (LongState restoredState = new LongState(normalFSA, testDir.directory(), 14)) {
assertEquals(lastValue, restoredState.getTheState());
}
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DurableStateStorageTest method shouldMaintainStateGivenAnEmptyInitialStore.
@Test
public void shouldMaintainStateGivenAnEmptyInitialStore() throws Exception {
// given
EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
fsa.mkdir(testDir.directory());
DurableStateStorage<AtomicInteger> storage = lifeRule.add(new DurableStateStorage<>(fsa, testDir.directory(), "state", new AtomicIntegerMarshal(), 100, NullLogProvider.getInstance()));
// when
storage.persistStoreData(new AtomicInteger(99));
// then
assertEquals(4, fsa.getFileSize(stateFileA()));
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class DurableStateStorageTest method shouldRotateToOtherStoreFileAfterSufficientEntries.
@Test
public void shouldRotateToOtherStoreFileAfterSufficientEntries() throws Exception {
// given
EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
fsa.mkdir(testDir.directory());
final int numberOfEntriesBeforeRotation = 100;
DurableStateStorage<AtomicInteger> storage = lifeRule.add(new DurableStateStorage<>(fsa, testDir.directory(), "state", new AtomicIntegerMarshal(), numberOfEntriesBeforeRotation, NullLogProvider.getInstance()));
// when
for (int i = 0; i < numberOfEntriesBeforeRotation; i++) {
storage.persistStoreData(new AtomicInteger(i));
}
// Force the rotation
storage.persistStoreData(new AtomicInteger(9999));
// then
assertEquals(4, fsa.getFileSize(stateFileB()));
assertEquals(numberOfEntriesBeforeRotation * 4, fsa.getFileSize(stateFileA()));
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class ConstraintRecoveryIT method shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails.
@Test
public void shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails() throws IOException {
// given
final EphemeralFileSystemAbstraction fs = fileSystemRule.get();
fs.mkdir(new File("/tmp"));
File pathToDb = new File("/tmp/bar2");
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(fs);
final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
final AtomicBoolean monitorCalled = new AtomicBoolean(false);
Monitors monitors = new Monitors();
monitors.addMonitorListener(new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanComplete() {
monitorCalled.set(true);
db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush();
storeInNeedOfRecovery[0] = fs.snapshot();
}
});
dbFactory.setMonitors(monitors);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < 2; i++) {
Node node1 = db.createNode(LABEL);
node1.setProperty("prop", true);
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().constraintFor(LABEL).assertPropertyIsUnique("prop").create();
fail("Should have failed with ConstraintViolationException");
tx.success();
} catch (ConstraintViolationException ignored) {
}
db.shutdown();
assertTrue(monitorCalled.get());
// when
dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
// then
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(5000, TimeUnit.MILLISECONDS);
}
try (Transaction tx = db.beginTx()) {
assertEquals(2, Iterables.count(db.getAllNodes()));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getConstraints())));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getIndexes())));
}
db.shutdown();
}
use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.
the class IndexingServiceIntegrationTest method setUp.
@Before
public void setUp() {
EphemeralFileSystemAbstraction fileSystem = fileSystemRule.get();
database = new TestGraphDatabaseFactory().setFileSystem(fileSystem).addKernelExtension(new LuceneSchemaIndexProviderFactory()).newImpermanentDatabase();
createData(database, 100);
}
Aggregations