Search in sources :

Example 1 with EphemeralFileSystemAbstraction

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;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 2 with EphemeralFileSystemAbstraction

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();
        }
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) Test(org.junit.Test)

Example 3 with EphemeralFileSystemAbstraction

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));
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 4 with EphemeralFileSystemAbstraction

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

Example 5 with EphemeralFileSystemAbstraction

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));
    }
}
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)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)39 Test (org.junit.Test)27 File (java.io.File)20 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 StoreChannel (org.neo4j.io.fs.StoreChannel)6 IOException (java.io.IOException)5 CountingAdversary (org.neo4j.adversaries.CountingAdversary)5 MethodGuardedAdversary (org.neo4j.adversaries.MethodGuardedAdversary)5 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)5 StateRecoveryManager (org.neo4j.causalclustering.core.state.StateRecoveryManager)5 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)5 Transaction (org.neo4j.graphdb.Transaction)5 ByteBuffer (java.nio.ByteBuffer)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SelectiveFileSystemAbstraction (org.neo4j.graphdb.mockfs.SelectiveFileSystemAbstraction)4 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 Before (org.junit.Before)3 Node (org.neo4j.graphdb.Node)3 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)3