@Test public void testReplicateLog() { NodeImpl node = (NodeImpl) newNodeBuilder( NodeId.of("A"), new NodeEndpoint("A", "localhost", 2333), new NodeEndpoint("B", "localhost", 2334), new NodeEndpoint("C", "localhost", 2335) ).build(); node.start(); node.electionTimeout(); node.onReceiveRequestVoteResult(new RequestVoteResult(1, true)); node.replicateLog(); MockConnector mockConnector = (MockConnector) node.getContext().connector(); Assert.assertEquals(3, mockConnector.getMessageCount()); List<MockConnector.Message> messages = mockConnector.getMessages(); Set<NodeId> destinationNodeIds = messages.subList(1, 3).stream() .map(MockConnector.Message::getDestinationNodeId) .collect(Collectors.toSet()); Assert.assertEquals(2, destinationNodeIds.size()); Assert.assertTrue(destinationNodeIds.contains(NodeId.of("B"))); Assert.assertTrue(destinationNodeIds.contains(NodeId.of("C"))); AppendEntriesRpc rpc = (AppendEntriesRpc) messages.get(2).getRpc(); Assert.assertEquals(1, rpc.getTerm()); }
void replicateLog() { context.taskExecutor().submit(this::doReplicateLog, LOGGING_FUTURE_CALLBACK); }
NodeImpl implements Node { void replicateLog() { context.taskExecutor().submit(this::doReplicateLog, LOGGING_FUTURE_CALLBACK); } }
NodeImpl implements Node { void replicateLog() { context.taskExecutor().submit(this::doReplicateLog, LOGGING_FUTURE_CALLBACK); } NodeImpl(NodeContext context); }
NodeImpl implements Node { void replicateLog() { context.taskExecutor().submit(this::doReplicateLog, 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 { void replicateLog() { context.taskExecutor().submit(this::doReplicateLog, 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();  }