use of org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotLoad.
@Test
public void testOnSnapshotLoad() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(12).lastIncludedTerm(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 org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotLoadFSMError.
@Test
public void testOnSnapshotLoadFSMError() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(12).lastIncludedTerm(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);
}
use of org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta in project ignite-3 by apache.
the class SnapshotExecutorImpl method installSnapshot.
@Override
public void installSnapshot(final InstallSnapshotRequest request, final InstallSnapshotResponseBuilder response, final RpcRequestClosure done) {
final SnapshotMeta meta = request.meta();
final DownloadingSnapshot ds = new DownloadingSnapshot(request, response, done);
// as the retry snapshot will replace this one.
if (!registerDownloadingSnapshot(ds)) {
LOG.warn("Fail to register downloading snapshot.");
// This RPC will be responded by the previous session
return;
}
Requires.requireNonNull(this.curCopier, "curCopier");
try {
this.curCopier.join();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
LOG.warn("Install snapshot copy job was canceled.");
return;
}
loadDownloadingSnapshot(ds, meta);
}
use of org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotLoadStale.
@Test
public void testOnSnapshotLoadStale() throws Exception {
final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(5).lastIncludedTerm(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 org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta 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);
}
Aggregations