Search in sources :

Example 31 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class SingleFilePageSwapperTest method setUp.

@Before
public void setUp() throws IOException {
    file = new File("file").getCanonicalFile();
    ephemeralFileSystem = new EphemeralFileSystemAbstraction();
    fileSystem = new DefaultFileSystemAbstraction();
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) File(java.io.File) Before(org.junit.Before)

Example 32 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class EphemeralFileSystemRule method snapshot.

public EphemeralFileSystemAbstraction snapshot(Runnable action) throws Exception {
    EphemeralFileSystemAbstraction snapshot = fs.snapshot();
    try {
        action.run();
    } finally {
        fs.close();
        fs = snapshot;
    }
    return fs;
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)

Example 33 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class StateRecoveryManagerTest method shouldFailIfBothFilesAreEmpty.

@Test
public void shouldFailIfBothFilesAreEmpty() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    File fileA = fileA();
    fsa.create(fileA);
    File fileB = fileB();
    fsa.create(fileB);
    StateRecoveryManager<Long> manager = new StateRecoveryManager<>(fsa, new LongMarshal());
    try {
        // when
        StateRecoveryManager.RecoveryStatus recoveryStatus = manager.recover(fileA, fileB);
        fail();
    } catch (IllegalStateException ex) {
    // then
    // expected
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) StateRecoveryManager(org.neo4j.causalclustering.core.state.StateRecoveryManager) File(java.io.File) Test(org.junit.Test)

Example 34 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class StateRecoveryManagerTest method shouldReturnTheEmptyFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry.

@Test
public void shouldReturnTheEmptyFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    File fileA = fileA();
    StoreChannel channel = fsa.create(fileA);
    ByteBuffer buffer = writeLong(999);
    channel.writeAll(buffer);
    channel.force(false);
    File fileB = fileB();
    channel = fsa.create(fileB);
    channel.close();
    StateRecoveryManager<Long> manager = new StateRecoveryManager<>(fsa, new LongMarshal());
    // when
    final StateRecoveryManager.RecoveryStatus recoveryStatus = manager.recover(fileA, fileB);
    // then
    assertEquals(999L, recoveryStatus.recoveredState());
    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) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 35 with EphemeralFileSystemAbstraction

use of org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class StateRecoveryManagerTest method shouldReturnTheFullFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry.

@Test
public void shouldReturnTheFullFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry() throws Exception {
    // given
    EphemeralFileSystemAbstraction fsa = fileSystemRule.get();
    fsa.mkdir(testDir.directory());
    File fileA = fileA();
    StoreChannel channel = fsa.create(fileA);
    ByteBuffer buffer = writeLong(42);
    channel.writeAll(buffer);
    channel.force(false);
    buffer.clear();
    // extraneous bytes
    buffer.putLong(101);
    buffer.flip();
    channel.writeAll(buffer);
    channel.force(false);
    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) ByteBuffer(java.nio.ByteBuffer) 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