use of org.apache.ignite.raft.jraft.rpc.RpcRequestClosure in project ignite-3 by apache.
the class SnapshotExecutorTest method testInterruptInstalling.
@Test
public void testInterruptInstalling() throws Exception {
RaftMessagesFactory msgFactory = raftOptions.getRaftMessagesFactory();
final RpcRequests.InstallSnapshotRequest irb = msgFactory.installSnapshotRequest().groupId("test").peerId(addr.toString()).serverId("localhost:8080").uri("remote://localhost:8080/99").term(0).meta(msgFactory.snapshotMeta().lastIncludedIndex(1).lastIncludedTerm(1).build()).build();
Mockito.lenient().when(raftClientService.connect(new Endpoint("localhost", 8080))).thenReturn(true);
final CompletableFuture<Message> future = new CompletableFuture<>();
final RpcRequests.GetFileRequest rb = msgFactory.getFileRequest().readerId(99).filename(Snapshot.JRAFT_SNAPSHOT_META_FILE).count(Integer.MAX_VALUE).offset(0).readPartly(true).build();
// Mock get metadata
final ArgumentCaptor<RpcResponseClosure> argument = ArgumentCaptor.forClass(RpcResponseClosure.class);
Mockito.lenient().when(raftClientService.getFile(eq(new Endpoint("localhost", 8080)), eq(rb), eq(copyOpts.getTimeoutMs()), argument.capture())).thenReturn(future);
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
executorService = singleThreadExecutor;
Utils.runInThread(singleThreadExecutor, () -> executor.installSnapshot(irb, msgFactory.installSnapshotResponse(), new RpcRequestClosure(asyncCtx, msgFactory)));
executor.interruptDownloadingSnapshots(1);
executor.join();
assertEquals(0, executor.getLastSnapshotTerm());
assertEquals(0, executor.getLastSnapshotIndex());
}
Aggregations