@Test public void getBackCachedResultIfTryingToPingTwice() { CumulativeLeaderPinger cumulativeLeaderPinger = new CumulativeLeaderPinger( pingerWithContext, Duration.ofSeconds(1), Duration.ofSeconds(1), HOST_UUID); Future<LeaderPingResult> clientWhoIsLed = cumulativeLeaderPinger.registerAndPing(HOST_UUID, CLIENT_WHO_IS_LED); when(batchPingableLeader.ping(ImmutableSet.of(CLIENT_WHO_IS_LED))) .thenReturn(ImmutableSet.of(CLIENT_WHO_IS_LED)) .thenReturn(ImmutableSet.of()); cumulativeLeaderPinger.runOneIteration(); assertThat(Futures.getUnchecked(clientWhoIsLed)) .isEqualTo(LeaderPingResults.pingReturnedTrue(HOST_UUID, HOST_AND_PORT)); Future<LeaderPingResult> clientWhoIsLedSecondRequest = cumulativeLeaderPinger.registerAndPing(HOST_UUID, CLIENT_WHO_IS_LED); assertThat(Futures.getUnchecked(clientWhoIsLedSecondRequest)) .isEqualTo(LeaderPingResults.pingReturnedTrue(HOST_UUID, HOST_AND_PORT)); verify(batchPingableLeader, only()).ping(ImmutableSet.of(CLIENT_WHO_IS_LED)); }
@Override public Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client) { Instant requestTime = Instant.now(); return FluentFuture.from(hasProcessedFirstRequest.computeIfAbsent(client, $ -> SettableFuture.create())) .transform( $ -> { checkNotShutdown(); return lastSuccessfulResult.get().result( client, requestTime.minus(leaderPingResponseWait), remoteClient.hostAndPort(), requestedUuid); }
CumulativeLeaderPinger extends AbstractScheduledService implements ClientAwareLeaderPinger { @Override public Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client) { Instant requestTime = Instant.now(); return FluentFuture.from(hasProcessedFirstRequest.computeIfAbsent(client, $ -> SettableFuture.create())) .transform( $ -> { checkNotShutdown(); return lastSuccessfulResult.get().result( client, requestTime.minus(leaderPingResponseWait), remoteClient.hostAndPort(), requestedUuid); } }
CumulativeLeaderPinger extends AbstractScheduledService implements ClientAwareLeaderPinger { @Override public Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client) { Instant requestTime = Instant.now(); return FluentFuture.from(hasProcessedFirstRequest.computeIfAbsent(client, $ -> SettableFuture.create())) .transform( $ -> { checkNotShutdown(); return lastSuccessfulResult.get().result( client, requestTime.minus(leaderPingResponseWait), remoteClient.hostAndPort(), requestedUuid); } CumulativeLeaderPinger(
            LeaderPingerContext<BatchPingableLeader> remoteClient,
            Duration leaderPingRate,
            Duration leaderPingResponseWait,
            UUID nodeUuid); }
CumulativeLeaderPinger extends AbstractScheduledService implements ClientAwareLeaderPinger { @Override public Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client) { Instant requestTime = Instant.now(); return FluentFuture.from(hasProcessedFirstRequest.computeIfAbsent(client, $ -> SettableFuture.create())) .transform( $ -> { checkNotShutdown(); return lastSuccessfulResult.get().result( client, requestTime.minus(leaderPingResponseWait), remoteClient.hostAndPort(), requestedUuid); } CumulativeLeaderPinger(
            LeaderPingerContext<BatchPingableLeader> remoteClient,
            Duration leaderPingRate,
            Duration leaderPingResponseWait,
            UUID nodeUuid); @Override Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client); }
CumulativeLeaderPinger extends AbstractScheduledService implements ClientAwareLeaderPinger { @Override public Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client) { Instant requestTime = Instant.now(); return FluentFuture.from(hasProcessedFirstRequest.computeIfAbsent(client, $ -> SettableFuture.create())) .transform( $ -> { checkNotShutdown(); return lastSuccessfulResult.get().result( client, requestTime.minus(leaderPingResponseWait), remoteClient.hostAndPort(), requestedUuid); } CumulativeLeaderPinger(
            LeaderPingerContext<BatchPingableLeader> remoteClient,
            Duration leaderPingRate,
            Duration leaderPingResponseWait,
            UUID nodeUuid); @Override Future<LeaderPingResult> registerAndPing(UUID requestedUuid, Client client);  }