@Test
  public void testBackgroundUpdater() throws InterruptedException, SQLException, IOException {

    mySqlConfigProps.setProperty(UPDATER_POLLING_INTERVAL_SECONDS, "1");
    Account testAccount = new AccountBuilder((short) 1, "testAccount1", Account.AccountStatus.ACTIVE).build();
    when(mockMySqlAccountStore.getNewAccounts(anyLong())).thenReturn(new ArrayList<>())
        .thenReturn(new ArrayList<>(Collections.singletonList(testAccount)));
    mySqlAccountService = getAccountService();

    assertEquals("Background account updater thread should have been started", 1,
        numThreadsByThisName(MySqlAccountService.MYSQL_ACCOUNT_UPDATER_PREFIX));

    // Verify cache is empty.
    assertNull("Cache should be empty", mySqlAccountService.getAccountById(testAccount.getId()));
    // sleep for polling interval time
    Thread.sleep(Long.parseLong(mySqlConfigProps.getProperty(UPDATER_POLLING_INTERVAL_SECONDS)) * 1000 + 100);
    // Verify account is added to cache by background updater.
    assertEquals("Mismatch in account retrieved by ID", testAccount,
        mySqlAccountService.getAccountById(testAccount.getId()));

    // verify that close() stops the background updater thread
    mySqlAccountService.close();

    // force shutdown background updater thread. As the default timeout value is 1 minute, it is possible that thread is
    // present after close() due to actively executing task.
    mySqlAccountService.getScheduler().shutdownNow();

    assertTrue("Background account updater thread should be stopped",
        TestUtils.checkAndSleep(0, () -> numThreadsByThisName(MySqlAccountService.MYSQL_ACCOUNT_UPDATER_PREFIX), 1000));
  }
Tests background updater for updating cache from mysql store periodically.
ambry-account/src/test/java/com/github/ambry/account/MySqlAccountServiceTest.java