use of com.alipay.sofa.jraft.entity.RaftOutter.SnapshotMeta 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.entity.RaftOutter.SnapshotMeta in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotLoadStale.
@Test
public void testOnSnapshotLoadStale() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = SnapshotMeta.newBuilder().setLastIncludedIndex(5).setLastIncludedTerm(1).build();
Mockito.when(reader.load()).thenReturn(meta);
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals(RaftError.ESTALE, status.getRaftError());
latch.countDown();
}
@Override
public SnapshotReader start() {
return reader;
}
});
latch.await();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 10);
}
use of com.alipay.sofa.jraft.entity.RaftOutter.SnapshotMeta in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotLoad.
@Test
public void testOnSnapshotLoad() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = SnapshotMeta.newBuilder().setLastIncludedIndex(12).setLastIncludedTerm(1).build();
Mockito.when(reader.load()).thenReturn(meta);
Mockito.when(this.fsm.onSnapshotLoad(reader)).thenReturn(true);
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
@Override
public SnapshotReader start() {
return reader;
}
});
latch.await();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 12);
Mockito.verify(this.fsm).onConfigurationCommitted(Mockito.any());
}
use of com.alipay.sofa.jraft.entity.RaftOutter.SnapshotMeta 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.entity.RaftOutter.SnapshotMeta in project sofa-jraft by sofastack.
the class FSMCallerTest method testOnSnapshotLoadFSMError.
@Test
public void testOnSnapshotLoadFSMError() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = SnapshotMeta.newBuilder().setLastIncludedIndex(12).setLastIncludedTerm(1).build();
Mockito.when(reader.load()).thenReturn(meta);
Mockito.when(this.fsm.onSnapshotLoad(reader)).thenReturn(false);
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals(-1, status.getCode());
assertEquals("StateMachine onSnapshotLoad failed", status.getErrorMsg());
latch.countDown();
}
@Override
public SnapshotReader start() {
return reader;
}
});
latch.await();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 10);
}
Aggregations