use of com.alipay.sofa.jraft.closure.SaveSnapshotClosure in project sofa-jraft by sofastack.
the class SnapshotExecutorTest method testDoSnapshotWithIntervalDist.
@Test
public void testDoSnapshotWithIntervalDist() throws Exception {
final NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setSnapshotLogIndexMargin(5);
Mockito.when(this.node.getOptions()).thenReturn(nodeOptions);
Mockito.when(this.fSMCaller.getLastAppliedIndex()).thenReturn(6L);
final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
Mockito.when(this.fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
final SynchronizedClosure done = new SynchronizedClosure();
this.executor.doSnapshot(done);
final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
assertNotNull(closure);
closure.start(RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(6).setLastIncludedTerm(1).build());
closure.run(Status.OK());
done.await();
this.executor.join();
assertEquals(1, this.executor.getLastSnapshotTerm());
assertEquals(6, this.executor.getLastSnapshotIndex());
}
use of com.alipay.sofa.jraft.closure.SaveSnapshotClosure in project sofa-jraft by sofastack.
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) {
// TODO Auto-generated method stub
return null;
}
});
latch.await();
}
use of com.alipay.sofa.jraft.closure.SaveSnapshotClosure in project sofa-jraft by sofastack.
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.getLastIncludedIndex());
return writer;
}
};
this.fsmCaller.onSnapshotSave(done);
this.fsmCaller.flush();
Mockito.verify(this.fsm).onSnapshotSave(writer, done);
}
use of com.alipay.sofa.jraft.closure.SaveSnapshotClosure in project sofa-jraft by sofastack.
the class SnapshotExecutorTest method testDoSnapshot.
@Test
public void testDoSnapshot() throws Exception {
Mockito.when(this.fSMCaller.getLastAppliedIndex()).thenReturn(1L);
final ArgumentCaptor<SaveSnapshotClosure> saveSnapshotClosureArg = ArgumentCaptor.forClass(SaveSnapshotClosure.class);
Mockito.when(this.fSMCaller.onSnapshotSave(saveSnapshotClosureArg.capture())).thenReturn(true);
final SynchronizedClosure done = new SynchronizedClosure();
this.executor.doSnapshot(done);
final SaveSnapshotClosure closure = saveSnapshotClosureArg.getValue();
assertNotNull(closure);
closure.start(RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(2).setLastIncludedTerm(1).build());
closure.run(Status.OK());
done.await();
this.executor.join();
assertTrue(done.getStatus().isOk());
assertEquals(1, this.executor.getLastSnapshotTerm());
assertEquals(2, this.executor.getLastSnapshotIndex());
}
Aggregations