use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.
the class SnapshotExecutorTest method testDoSnapshotWithIntervalDist.
@Test
public void testDoSnapshotWithIntervalDist() throws Exception {
final NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setSnapshotLogIndexMargin(5);
ExecutorService testExecutor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
executorService = testExecutor;
nodeOptions.setCommonExecutor(testExecutor);
Mockito.when(node.getOptions()).thenReturn(nodeOptions);
Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(6L);
final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
Mockito.when(fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
final SynchronizedClosure done = new SynchronizedClosure();
executor.doSnapshot(done);
final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
assertNotNull(closure);
closure.start(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(6).lastIncludedTerm(1).build());
closure.run(Status.OK());
done.await();
executor.join();
assertEquals(1, executor.getLastSnapshotTerm());
assertEquals(6, executor.getLastSnapshotIndex());
}
use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.
the class SnapshotExecutorTest method testDoSnapshot.
@Test
public void testDoSnapshot() throws Exception {
Mockito.when(fSMCaller.getLastAppliedIndex()).thenReturn(1L);
final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
Mockito.when(fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
final SynchronizedClosure done = new SynchronizedClosure();
executor.doSnapshot(done);
final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
assertNotNull(closure);
closure.start(raftOptions.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(2).lastIncludedTerm(1).build());
closure.run(Status.OK());
done.await();
executor.join();
assertTrue(done.getStatus().isOk());
assertEquals(1, executor.getLastSnapshotTerm());
assertEquals(2, executor.getLastSnapshotIndex());
}
use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotSave.
@Test
public void testOnSnapshotSave() throws Exception {
final SnapshotWriter writer = Mockito.mock(SnapshotWriter.class);
Mockito.when(this.logManager.getConfiguration(10)).thenReturn(TestUtils.getConfEntry("localhost:8081,localhost:8082,localhost:8083", "localhost:8081"));
final SaveSnapshotClosure done = new SaveSnapshotClosure() {
@Override
public void run(final Status status) {
}
@Override
public SnapshotWriter start(final SnapshotMeta meta) {
assertEquals(10, meta.lastIncludedIndex());
return writer;
}
};
this.fsmCaller.onSnapshotSave(done);
this.fsmCaller.flush();
Mockito.verify(this.fsm).onSnapshotSave(writer, done);
}
use of org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotSaveEmptyConf.
@Test
public void testOnSnapshotSaveEmptyConf() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotSave(new SaveSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals("Empty conf entry for lastAppliedIndex=10", status.getErrorMsg());
latch.countDown();
}
@Override
public SnapshotWriter start(final SnapshotMeta meta) {
return null;
}
});
latch.await();
}
Aggregations