### Question:
Replicator implements ThreadId.OnError { public static void sendHeartbeat(final ThreadId id, final RpcResponseClosure<AppendEntriesResponse> closure) { final Replicator r = (Replicator) id.lock(); if (r == null) { RpcUtils.runClosureInThread(closure, new Status(RaftError.EHOSTDOWN, "Peer %s is not connected", id)); return; } r.sendEmptyEntries(true, closure); } Replicator(final ReplicatorOptions replicatorOptions, final RaftOptions raftOptions); @OnlyForTest PriorityQueue<RpcResponse> getPendingResponses(); static ThreadId start(final ReplicatorOptions opts, final RaftOptions raftOptions); static void waitForCaughtUp(final ThreadId id, final long maxMargin, final long dueTime,
                                       final CatchUpClosure done); @Override String toString(); @Override void onError(final ThreadId id, final Object data, final int errorCode); static void sendHeartbeat(final ThreadId id, final RpcResponseClosure<AppendEntriesResponse> closure); static boolean stop(final ThreadId id); static boolean join(final ThreadId id); static long getLastRpcSendTimestamp(final ThreadId id); static boolean transferLeadership(final ThreadId id, final long logIndex); static boolean stopTransferLeadership(final ThreadId id); static boolean sendTimeoutNowAndStop(final ThreadId id, final int timeoutMs); static long getNextIndex(final ThreadId id);  }### Answer:
@Test public void testSendHeartbeat() { final Replicator r = getReplicator(); this.id.unlock(); assertNull(r.getHeartbeatInFly()); final RpcRequests.AppendEntriesRequest request = createEmptyEntriesRequest(true); Mockito.when( this.rpcService.appendEntries(eq(this.peerId.getEndpoint()), eq(request), eq(this.opts.getElectionTimeoutMs() / 2), Mockito.any())).thenReturn(new FutureImpl<>()); Replicator.sendHeartbeat(this.id, new RpcResponseClosureAdapter<RpcRequests.AppendEntriesResponse>() { @Override public void run(final Status status) { assertTrue(status.isOk()); } }); assertNotNull(r.getHeartbeatInFly()); assertSame(r, this.id.lock()); this.id.unlock(); }