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