@Test public void userAgentsPresentOnRequestsWithLeaderBlockConfigured() throws IOException { setUpLeaderBlockInConfig(); verifyUserAgentOnRawTimestampAndLockRequests(); }
private void setUpForLocalServices() throws IOException { doAnswer(invocation -> { // Configure our server to reply with the same server ID as the registered PingableLeader. PingableLeader localPingableLeader = invocation.getArgument(0); availableServer.stubFor(LEADER_UUID_MAPPING.willReturn(aResponse() .withStatus(200) .withBody(("\"" + localPingableLeader.getUUID() + "\"").getBytes()))); return null; }).when(environment).accept(isA(PingableLeader.class)); setUpLeaderBlockInConfig(); }
@Test public void metricsAreReportedExactlyOnceWhenUsingLocalService() throws IOException, InterruptedException { setUpForLocalServices(); setUpLeaderBlockInConfig(); assertThatTimeAndLockMetricsAreRecorded(TIMESTAMP_SERVICE_FRESH_TIMESTAMP_METRIC, LOCK_SERVICE_CURRENT_TIME_METRIC); }
@Test public void metricsAreReportedExactlyOnceWhenUsingRemoteService() throws IOException, InterruptedException { setUpForRemoteServices(); setUpLeaderBlockInConfig(); assertThatTimeAndLockMetricsAreRecorded(TIMESTAMP_SERVICE_FRESH_TIMESTAMP_METRIC, LOCK_SERVICE_CURRENT_TIME_METRIC); }
@Test public void throwsIfInstallConfigHasLeaderBlockButInitialRuntimeConfigContainsTimeLockBlock() throws IOException { setUpLeaderBlockInConfig(); setUpTimeLockBlockInRuntimeConfig(); assertGetLockAndTimestampServicesThrows(); }
private void setUpForRemoteServices() throws IOException { availableServer.stubFor(LEADER_UUID_MAPPING.willReturn(aResponse().withStatus(404))); setUpLeaderBlockInConfig(); }
@Test public void remoteCallsStillMadeIfPingableLeader404s() throws IOException, InterruptedException { setUpForRemoteServices(); setUpLeaderBlockInConfig(); TransactionManagers.LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices(); availableServer.verify(getRequestedFor(urlMatching(LEADER_UUID_PATH))); lockAndTimestamp.timelock().getFreshTimestamp(); lockAndTimestamp.lock().currentTimeMillis(); availableServer.verify(postRequestedFor(urlMatching(TIMESTAMP_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); availableServer.verify(postRequestedFor(urlMatching(LOCK_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); }
@Test public void remoteCallsElidedIfTalkingToLocalServer() throws IOException, InterruptedException { setUpForLocalServices(); setUpLeaderBlockInConfig(); TransactionManagers.LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices(); availableServer.verify(getRequestedFor(urlMatching(LEADER_UUID_PATH))); lockAndTimestamp.timelock().getFreshTimestamp(); lockAndTimestamp.lock().currentTimeMillis(); availableServer.verify(0, postRequestedFor(urlMatching(TIMESTAMP_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); availableServer.verify(0, postRequestedFor(urlMatching(LOCK_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); }