### Question:
MySqlAccountService extends AbstractAccountService { @Override public Collection<Account> getAllAccounts() { infoMapLock.readLock().lock(); try { return accountInfoMapRef.get().getAccounts(); } finally { infoMapLock.readLock().unlock(); } } MySqlAccountService(AccountServiceMetrics accountServiceMetrics, MySqlAccountServiceConfig config,
      MySqlAccountStore mySqlAccountStore); @Override Account getAccountById(short accountId); @Override Account getAccountByName(String accountName); @Override boolean updateAccounts(Collection<Account> accounts); @Override Collection<Account> getAllAccounts(); @Override boolean addAccountUpdateConsumer(Consumer<Collection<Account>> accountUpdateConsumer); @Override boolean removeAccountUpdateConsumer(Consumer<Collection<Account>> accountUpdateConsumer); @Override void selectInactiveContainersAndMarkInZK(StatsSnapshot statsSnapshot); @Override void close();  }### Answer:
@Test public void testInitCacheFromDisk() throws IOException, SQLException { Path accountBackupDir = Paths.get(TestUtils.getTempDir("account-backup")).toAbsolutePath(); mySqlConfigProps.setProperty(MySqlAccountServiceConfig.BACKUP_DIRECTORY_KEY, accountBackupDir.toString()); long lastModifiedTime = 100; Account testAccount = new AccountBuilder((short) 1, "testAccount", Account.AccountStatus.ACTIVE).lastModifiedTime(lastModifiedTime) .build(); Map<String, String> accountMap = new HashMap<>(); accountMap.put(Short.toString(testAccount.getId()), testAccount.toJson(false).toString()); String filename = BackupFileManager.getBackupFilename(1, SystemTime.getInstance().seconds()); Path filePath = accountBackupDir.resolve(filename); BackupFileManager.writeAccountMapToFile(filePath, accountMap); MySqlAccountStore mockMySqlAccountStore = mock(MySqlAccountStore.class); mySqlAccountService = new MySqlAccountService(new AccountServiceMetrics(new MetricRegistry()), new MySqlAccountServiceConfig(new VerifiableProperties(mySqlConfigProps)), mockMySqlAccountStore); assertEquals("Mismatch in number of accounts in cache", 1, mySqlAccountService.getAllAccounts().size()); assertEquals("Mismatch in account info in cache", testAccount, mySqlAccountService.getAllAccounts().iterator().next()); verify(mockMySqlAccountStore, atLeastOnce()).getNewAccounts(lastModifiedTime); verify(mockMySqlAccountStore, atLeastOnce()).getNewContainers(lastModifiedTime); }
@Test public void testInitCacheOnStartUp() throws SQLException, IOException { Container testContainer = new ContainerBuilder((short) 1, "testContainer", Container.ContainerStatus.ACTIVE, "testContainer", (short) 1).build(); Account testAccount = new AccountBuilder((short) 1, "testAccount", Account.AccountStatus.ACTIVE).containers( Collections.singleton(testContainer)).build(); MySqlAccountStore mockMySqlAccountStore = mock(MySqlAccountStore.class); when(mockMySqlAccountStore.getNewAccounts(0)).thenReturn(new ArrayList<>(Collections.singletonList(testAccount))); mySqlAccountService = new MySqlAccountService(new AccountServiceMetrics(new MetricRegistry()), new MySqlAccountServiceConfig(new VerifiableProperties(mySqlConfigProps)), mockMySqlAccountStore); List<Account> accounts = new ArrayList<>(mySqlAccountService.getAllAccounts()); assertEquals("Mismatch in number of accounts", 1, accounts.size()); assertEquals("Mismatch in account information", testAccount, accounts.get(0)); }