Search in sources :

Example 21 with EphemeralFileSystemAbstraction

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());
    }
}
Also used : MethodGuardedAdversary(org.neo4j.adversaries.MethodGuardedAdversary) CountingAdversary(org.neo4j.adversaries.CountingAdversary) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) SelectiveFileSystemAbstraction(org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) File(java.io.File) IOException(java.io.IOException) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) Test(org.junit.Test)

Example 22 with EphemeralFileSystemAbstraction

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()));
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 23 with EphemeralFileSystemAbstraction

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()));
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 24 with EphemeralFileSystemAbstraction

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();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) File(java.io.File) Test(org.junit.Test)

Example 25 with EphemeralFileSystemAbstraction

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);
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) LuceneSchemaIndexProviderFactory(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProviderFactory) Before(org.junit.Before)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)54 Test (org.junit.Test)37 File (java.io.File)27 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)10 StoreChannel (org.neo4j.io.fs.StoreChannel)8 IOException (java.io.IOException)7 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)7 Before (org.junit.Before)6 CountingAdversary (org.neo4j.adversaries.CountingAdversary)6 Transaction (org.neo4j.graphdb.Transaction)6 ByteBuffer (java.nio.ByteBuffer)5 MethodGuardedAdversary (org.neo4j.adversaries.MethodGuardedAdversary)5 StateRecoveryManager (org.neo4j.causalclustering.core.state.StateRecoveryManager)5 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Node (org.neo4j.graphdb.Node)4 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4