@Test public void testOnReceiveInstallSnapshotRpc() { NodeImpl node = (NodeImpl) newNodeBuilder( NodeId.of("A"), new NodeEndpoint("A", "localhost", 2333), new NodeEndpoint("B", "localhost", 2334), new NodeEndpoint("C", "localhost", 2335)) .setStore(new MemoryNodeStore(1, null)) .build(); node.start(); InstallSnapshotRpc rpc = new InstallSnapshotRpc(); rpc.setTerm(1); rpc.setLastTerm(1); rpc.setLastIndex(2); rpc.setLastConfig(ImmutableSet.of( new NodeEndpoint("A", "localhost", 2333), new NodeEndpoint("B", "localhost", 2334), new NodeEndpoint("C", "localhost", 2335) )); rpc.setData(new byte[0]); rpc.setDone(true); node.onReceiveInstallSnapshotRpc(new InstallSnapshotRpcMessage(rpc, NodeId.of("B"), null)); MockConnector mockConnector = (MockConnector) node.getContext().connector(); InstallSnapshotResult result = (InstallSnapshotResult) mockConnector.getResult(); Assert.assertEquals(1, result.getTerm()); }
@Subscribe public void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage) { context.taskExecutor().submit( () -> context.connector().replyInstallSnapshot(doProcessInstallSnapshotRpc(rpcMessage), rpcMessage), LOGGING_FUTURE_CALLBACK ); }
NodeImpl implements Node { @Subscribe public void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage) { context.taskExecutor().submit( () -> context.connector().replyInstallSnapshot(doProcessInstallSnapshotRpc(rpcMessage), rpcMessage), LOGGING_FUTURE_CALLBACK ); } }
NodeImpl implements Node { @Subscribe public void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage) { context.taskExecutor().submit( () -> context.connector().replyInstallSnapshot(doProcessInstallSnapshotRpc(rpcMessage), rpcMessage), LOGGING_FUTURE_CALLBACK ); } NodeImpl(NodeContext context); }
NodeImpl implements Node { @Subscribe public void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage) { context.taskExecutor().submit( () -> context.connector().replyInstallSnapshot(doProcessInstallSnapshotRpc(rpcMessage), rpcMessage), LOGGING_FUTURE_CALLBACK ); } NodeImpl(NodeContext context); @Override synchronized void registerStateMachine(@Nonnull StateMachine stateMachine); @Override @Nonnull RoleNameAndLeaderId getRoleNameAndLeaderId(); @Override void addNodeRoleListener(@Nonnull NodeRoleListener listener); @Override synchronized void start(); @Override void appendLog(@Nonnull byte[] commandBytes); @Override @Nonnull GroupConfigChangeTaskReference addNode(@Nonnull NodeEndpoint endpoint); @Override @Nonnull GroupConfigChangeTaskReference removeNode(@Nonnull NodeId id); @Subscribe void onReceiveRequestVoteRpc(RequestVoteRpcMessage rpcMessage); @Subscribe void onReceiveRequestVoteResult(RequestVoteResult result); @Subscribe void onReceiveAppendEntriesRpc(AppendEntriesRpcMessage rpcMessage); @Subscribe void onReceiveAppendEntriesResult(AppendEntriesResultMessage resultMessage); @Subscribe void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage); @Subscribe void onReceiveInstallSnapshotResult(InstallSnapshotResultMessage resultMessage); @Subscribe void onGroupConfigEntryFromLeaderAppend(GroupConfigEntryFromLeaderAppendEvent event); @Subscribe void onGroupConfigEntryCommitted(GroupConfigEntryCommittedEvent event); @Subscribe void onGroupConfigEntryBatchRemoved(GroupConfigEntryBatchRemovedEvent event); @Subscribe void onGenerateSnapshot(SnapshotGenerateEvent event); @Subscribe void onReceiveDeadEvent(DeadEvent deadEvent); @Override synchronized void stop(); }
NodeImpl implements Node { @Subscribe public void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage) { context.taskExecutor().submit( () -> context.connector().replyInstallSnapshot(doProcessInstallSnapshotRpc(rpcMessage), rpcMessage), LOGGING_FUTURE_CALLBACK ); } NodeImpl(NodeContext context); @Override synchronized void registerStateMachine(@Nonnull StateMachine stateMachine); @Override @Nonnull RoleNameAndLeaderId getRoleNameAndLeaderId(); @Override void addNodeRoleListener(@Nonnull NodeRoleListener listener); @Override synchronized void start(); @Override void appendLog(@Nonnull byte[] commandBytes); @Override @Nonnull GroupConfigChangeTaskReference addNode(@Nonnull NodeEndpoint endpoint); @Override @Nonnull GroupConfigChangeTaskReference removeNode(@Nonnull NodeId id); @Subscribe void onReceiveRequestVoteRpc(RequestVoteRpcMessage rpcMessage); @Subscribe void onReceiveRequestVoteResult(RequestVoteResult result); @Subscribe void onReceiveAppendEntriesRpc(AppendEntriesRpcMessage rpcMessage); @Subscribe void onReceiveAppendEntriesResult(AppendEntriesResultMessage resultMessage); @Subscribe void onReceiveInstallSnapshotRpc(InstallSnapshotRpcMessage rpcMessage); @Subscribe void onReceiveInstallSnapshotResult(InstallSnapshotResultMessage resultMessage); @Subscribe void onGroupConfigEntryFromLeaderAppend(GroupConfigEntryFromLeaderAppendEvent event); @Subscribe void onGroupConfigEntryCommitted(GroupConfigEntryCommittedEvent event); @Subscribe void onGroupConfigEntryBatchRemoved(GroupConfigEntryBatchRemovedEvent event); @Subscribe void onGenerateSnapshot(SnapshotGenerateEvent event); @Subscribe void onReceiveDeadEvent(DeadEvent deadEvent); @Override synchronized void stop();  }