@Override @SuppressWarnings({"CheckReturnValue", "ResultOfMethodCallIgnored"}) // errorprone doesn't pick up "when=NEVER" protected synchronized void tryInitialize() { try { destination.ping(); } catch (Exception e) { throw new AtlasDbDependencyException("Could not contact the Timelock Server.", e); } long currentTimestamp = source.backupAndInvalidate(); destination.fastForwardTimestamp(currentTimestamp); }
@Test public void migrationDoesNotProceedIfInvalidationFails() { when(invalidator.backupAndInvalidate()).thenThrow(new IllegalStateException()); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT); assertThatThrownBy(migrator::migrate).isInstanceOf(IllegalStateException.class); wireMockRule.verify(0, postRequestedFor(urlEqualTo(TEST_ENDPOINT))); }
@Test public void invalidationDoesNotProceedIfTimelockPingUnsuccessful() { wireMockRule.stubFor(PING_MAPPING.willReturn(aResponse().withStatus(500))); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT); assertThatThrownBy(migrator::migrate).isInstanceOf(AtlasDbDependencyException.class); verify(invalidator, never()).backupAndInvalidate(); }
private void verifyUserAgentOnTimelockTimestampAndLockRequests() { verifyUserAgentOnTimestampAndLockRequests(TIMELOCK_TIMESTAMP_PATH, TIMELOCK_LOCK_PATH); verify(invalidator, times(1)).backupAndInvalidate(); availableServer.verify(getRequestedFor(urlEqualTo(TIMELOCK_PING_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); availableServer.verify(postRequestedFor(urlEqualTo(TIMELOCK_FF_PATH)) .withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT))); }
@Test public void asyncMigrationProceedsIfInvalidatorInitiallyUnavailable() throws InterruptedException { when(invalidator.backupAndInvalidate()) .thenAnswer(new Answer<Long>() { private AtomicBoolean shouldFail = new AtomicBoolean(true); verify(invalidator, times(2)).backupAndInvalidate(); wireMockRule.verify(postRequestedFor(urlEqualTo(TEST_ENDPOINT)));
when(invalidator.backupAndInvalidate()).thenReturn(EMBEDDED_BOUND);
@Test public void propagatesBackupTimestampToFastForwardOnRemoteService() { wireMockRule.stubFor(TEST_MAPPING.willReturn(aResponse().withStatus(204))); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT); migrator.migrate(); wireMockRule.verify(getRequestedFor(urlEqualTo(PING_ENDPOINT))); verify(invalidator, times(1)).backupAndInvalidate(); wireMockRule.verify(postRequestedFor(urlEqualTo(TEST_ENDPOINT))); }
@Before public void setUp() { when(invalidator.backupAndInvalidate()).thenReturn(BACKUP_TIMESTAMP); wireMockRule.stubFor(PING_MAPPING.willReturn(aResponse() .withStatus(200) .withBody(TimestampManagementService.PING_RESPONSE) .withHeader("Content-Type", "text/plain")) .inScenario(SCENARIO) .whenScenarioStateIs(Scenario.STARTED) .willSetStateTo(Scenario.STARTED)); String serverUri = String.format("http://%s:%s", WireMockConfiguration.DEFAULT_BIND_ADDRESS, wireMockRule.port()); ServerListConfig defaultServerListConfig = ImmutableServerListConfig.builder().addServers(serverUri).build(); timelockConfig = ImmutableTimeLockClientConfig.builder() .client("testClient") .serversList(defaultServerListConfig) .build(); }
@Override @SuppressWarnings({"CheckReturnValue", "ResultOfMethodCallIgnored"}) // errorprone doesn't pick up "when=NEVER" protected synchronized void tryInitialize() { try { destination.ping(); } catch (Exception e) { throw new AtlasDbDependencyException("Could not contact the Timelock Server.", e); } long currentTimestamp = source.backupAndInvalidate(); destination.fastForwardTimestamp(currentTimestamp); }
@Test public void asyncMigrationProceedsIfTimeLockInitiallyUnavailable() throws InterruptedException { String nowSucceeding = "nowSucceeding"; wireMockRule.stubFor(PING_MAPPING.inScenario(SCENARIO) .whenScenarioStateIs(Scenario.STARTED) .willReturn(aResponse().withStatus(500)) .willSetStateTo(nowSucceeding)); wireMockRule.stubFor(PING_MAPPING.inScenario(SCENARIO) .whenScenarioStateIs(nowSucceeding) .willReturn(aResponse().withStatus(204))); wireMockRule.stubFor(TEST_MAPPING.willReturn(aResponse().withStatus(204))); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), () -> timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT, true); migrator.migrate(); Awaitility.await() .atMost(30, TimeUnit.SECONDS) .pollInterval(1, TimeUnit.SECONDS) .until(migrator::isInitialized); wireMockRule.verify(getRequestedFor(urlEqualTo(PING_ENDPOINT))); verify(invalidator, times(1)).backupAndInvalidate(); wireMockRule.verify(postRequestedFor(urlEqualTo(TEST_ENDPOINT))); }