@Test public void throwsIfInstallConfigHasLeaderBlockButInitialRuntimeConfigContainsTimeLockBlock() throws IOException { setUpLeaderBlockInConfig(); setUpTimeLockBlockInRuntimeConfig(); assertGetLockAndTimestampServicesThrows(); }
@Test public void metricsAreReportedExactlyOnceWhenUsingRemoteService() throws IOException, InterruptedException { setUpForRemoteServices(); setUpLeaderBlockInConfig(); assertThatTimeAndLockMetricsAreRecorded(TIMESTAMP_SERVICE_FRESH_TIMESTAMP_METRIC, LOCK_SERVICE_CURRENT_TIME_METRIC); }
@Test public void metricsAreReportedExactlyOnceWhenUsingLocalService() throws IOException, InterruptedException { setUpForLocalServices(); setUpLeaderBlockInConfig(); assertThatTimeAndLockMetricsAreRecorded(TIMESTAMP_SERVICE_FRESH_TIMESTAMP_METRIC, LOCK_SERVICE_CURRENT_TIME_METRIC); }
@Test public void throwsIfInstallConfigHasRemoteBlockButInitialRuntimeConfigContainsTimeLockBlock() { setUpRemoteTimestampAndLockBlocksInConfig(); setUpTimeLockBlockInRuntimeConfig(); assertGetLockAndTimestampServicesThrows(); }
@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))); }
@Test public void userAgentsPresentOnRequestsWithLeaderBlockConfigured() throws IOException { setUpLeaderBlockInConfig(); verifyUserAgentOnRawTimestampAndLockRequests(); }
@Test public void userAgentsPresentOnRequestsToRemoteTimestampAndLockServices() { setUpRemoteTimestampAndLockBlocksInConfig(); verifyUserAgentOnRawTimestampAndLockRequests(); }
@Test public void metricsAreReportedExactlyOnceWhenUsingTimelockService() { setUpTimeLockBlockInInstallConfig(); assertThatTimeAndLockMetricsAreRecorded(TIMELOCK_SERVICE_FRESH_TIMESTAMP_METRIC, TIMELOCK_SERVICE_CURRENT_TIME_METRIC); }
mockClientConfig = getTimelockConfigForServers(ImmutableList.of(getUriForPort(availablePort))); rawRemoteServerConfig = ImmutableServerListConfig.builder() .addServers(getUriForPort(availablePort)) .build();
private void verifyUsingTimeLockByGettingAFreshTimestamp() { when(config.namespace()).thenReturn(Optional.of(CLIENT)); getLockAndTimestampServices().timelock().getFreshTimestamp(); availableServer.verify(1, postRequestedFor(urlMatching(TIMELOCK_TIMESTAMP_PATH))); }
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 asyncInitializationEventuallySucceeds() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAsyncAtlasDbConfig()) .initializeAsync(true) .build(); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .addSchemas(GenericTestSchema.getSchema()) .build() .serializable(); assertFalse(manager.isInitialized()); assertThatThrownBy(() -> manager.runTaskWithRetry(unused -> null)).isInstanceOf(NotInitializedException.class); Awaitility.await().atMost(12, TimeUnit.SECONDS).until(manager::isInitialized); performTransaction(manager); }
private void setUpLeaderBlockInConfig() throws IOException { when(config.leader()).thenReturn(Optional.of(ImmutableLeaderConfig.builder() .localServer(getUriForPort(availablePort)) .addLeaders(getUriForPort(availablePort)) .acceptorLogDir(temporaryFolder.newFolder()) .learnerLogDir(temporaryFolder.newFolder()) .quorumSize(1) .build())); }
private void assertThatTimeAndLockMetricsAreRecorded(String timestampMetric, String lockMetric) { assertThat(metricsManager.getRegistry().timer(timestampMetric).getCount(), is(equalTo(0L))); assertThat(metricsManager.getRegistry().timer(lockMetric).getCount(), is(equalTo(0L))); TransactionManagers.LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices(); lockAndTimestamp.timelock().getFreshTimestamp(); lockAndTimestamp.timelock().currentTimeMillis(); assertThat(metricsManager.getRegistry().timer(timestampMetric).getCount(), is(equalTo(1L))); assertThat(metricsManager.getRegistry().timer(lockMetric).getCount(), is(equalTo(1L))); }
private void setUpForRemoteServices() throws IOException { availableServer.stubFor(LEADER_UUID_MAPPING.willReturn(aResponse().withStatus(404))); setUpLeaderBlockInConfig(); }
@Test public void asyncInitializationIsSynchronousIfKvsIsReady() { AtlasDbConfig atlasDbConfig = ImmutableAtlasDbConfig.builder() .keyValueService(new InMemoryAtlasDbConfig()) .initializeAsync(true) .build(); TransactionManager manager = TransactionManagers.builder() .config(atlasDbConfig) .userAgent("test") .globalMetricsRegistry(new MetricRegistry()) .globalTaggedMetricRegistry(DefaultTaggedMetricRegistry.getDefault()) .registrar(environment) .addSchemas(GenericTestSchema.getSchema()) .build() .serializable(); assertTrue(manager.isInitialized()); performTransaction(manager); }