Search in sources :

Example 6 with RpcRequestClosure

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());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Endpoint(org.apache.ignite.raft.jraft.util.Endpoint) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcResponseClosure(org.apache.ignite.raft.jraft.rpc.RpcResponseClosure) ExecutorService(java.util.concurrent.ExecutorService) RaftMessagesFactory(org.apache.ignite.raft.jraft.RaftMessagesFactory) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) Test(org.junit.jupiter.api.Test)

Aggregations

Message (org.apache.ignite.raft.jraft.rpc.Message)6 RpcRequestClosure (org.apache.ignite.raft.jraft.rpc.RpcRequestClosure)6 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)6 Test (org.junit.jupiter.api.Test)6 RpcContext (org.apache.ignite.raft.jraft.rpc.RpcContext)4 CompletableFuture (java.util.concurrent.CompletableFuture)2 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)2 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)2 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)2 ByteBuffer (java.nio.ByteBuffer)1 ExecutorService (java.util.concurrent.ExecutorService)1 LoadSnapshotClosure (org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure)1 GetFileRequestBuilder (org.apache.ignite.raft.jraft.rpc.GetFileRequestBuilder)1 SnapshotReader (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)1 LocalSnapshotReader (org.apache.ignite.raft.jraft.storage.snapshot.local.LocalSnapshotReader)1 ByteString (org.apache.ignite.raft.jraft.util.ByteString)1