@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); }
@Override public Collection<Account> getAllAccounts() { infoMapLock.readLock().lock(); try { return accountInfoMapRef.get().getAccounts(); } finally { infoMapLock.readLock().unlock(); } }
MySqlAccountService extends AbstractAccountService { @Override public Collection<Account> getAllAccounts() { infoMapLock.readLock().lock(); try { return accountInfoMapRef.get().getAccounts(); } finally { infoMapLock.readLock().unlock(); } } }
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); }
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(); }
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();  }