Search in sources :

Example 1 with StateRecoveryManager

use of org.neo4j.causalclustering.core.state.StateRecoveryManager 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 2 with StateRecoveryManager

use of org.neo4j.causalclustering.core.state.StateRecoveryManager 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 3 with StateRecoveryManager

use of org.neo4j.causalclustering.core.state.StateRecoveryManager 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 4 with StateRecoveryManager

use of org.neo4j.causalclustering.core.state.StateRecoveryManager 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 5 with StateRecoveryManager

use of org.neo4j.causalclustering.core.state.StateRecoveryManager 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

Test (org.junit.Test)5 StateRecoveryManager (org.neo4j.causalclustering.core.state.StateRecoveryManager)5 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)5 File (java.io.File)4 StoreChannel (org.neo4j.io.fs.StoreChannel)3 ByteBuffer (java.nio.ByteBuffer)2