Search in sources :

Example 16 with EphemeralFileSystemAbstraction

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()));
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Test(org.junit.Test)

Example 17 with EphemeralFileSystemAbstraction

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;
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap)

Example 18 with EphemeralFileSystemAbstraction

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());
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StateRecoveryManager(org.neo4j.causalclustering.core.state.StateRecoveryManager) Test(org.junit.Test)

Example 19 with EphemeralFileSystemAbstraction

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());
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) StateRecoveryManager(org.neo4j.causalclustering.core.state.StateRecoveryManager) File(java.io.File) Test(org.junit.Test)

Example 20 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)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