@Test public void testNonExistingAccountsAfterMultipleChanges() throws Exception { for (short x = 0; x < 10; x++) { Collection<Account> generatedAccounts = generateAccountJsonFile((short) 100, (short) (x + 5), DEFAULT_SEED_1); accountService.processAccountJsonFile(); verifyNonExistingAccounts(generatedAccounts); } }
public void processAccountJsonFile() { processAccountJsonLock.lock(); try { accountJsonProcessingStartTimeMs = System.currentTimeMillis(); logger.trace("Checking if JSON account file has changed."); if (!Files.exists(accountFile)) { logger.warn("Unable to open JSON account file '{}'", accountFile.toString()); return; } FileTime accountFileLastModified = Files.getLastModifiedTime(accountFile); if (accountFilePreviousModified == null || accountFilePreviousModified.compareTo(accountFileLastModified) < 0) { logger.debug("JSON Account file has changed or has never been loaded before. " + "Previous last know modified time: {}, new last known modified time: {}", accountFilePreviousModified, accountFileLastModified); String accountsJsonString = new String(Files.readAllBytes(accountFile), StandardCharsets.UTF_8); updateAccountsMap(accountsJsonString); accountFilePreviousModified = accountFileLastModified; } long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.trace("Completed updating accounts, took {} ms", timeForUpdate); accountServiceMetrics.updateAccountTimeInMs.update(timeForUpdate); } catch (Exception e) { long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.error("Failed updating accounts, took {} ms\"", timeForUpdate, e); accountServiceMetrics.updateAccountErrorCount.inc(); } finally { processAccountJsonLock.unlock(); } }
JsonAccountService extends AbstractAccountService { public void processAccountJsonFile() { processAccountJsonLock.lock(); try { accountJsonProcessingStartTimeMs = System.currentTimeMillis(); logger.trace("Checking if JSON account file has changed."); if (!Files.exists(accountFile)) { logger.warn("Unable to open JSON account file '{}'", accountFile.toString()); return; } FileTime accountFileLastModified = Files.getLastModifiedTime(accountFile); if (accountFilePreviousModified == null || accountFilePreviousModified.compareTo(accountFileLastModified) < 0) { logger.debug("JSON Account file has changed or has never been loaded before. " + "Previous last know modified time: {}, new last known modified time: {}", accountFilePreviousModified, accountFileLastModified); String accountsJsonString = new String(Files.readAllBytes(accountFile), StandardCharsets.UTF_8); updateAccountsMap(accountsJsonString); accountFilePreviousModified = accountFileLastModified; } long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.trace("Completed updating accounts, took {} ms", timeForUpdate); accountServiceMetrics.updateAccountTimeInMs.update(timeForUpdate); } catch (Exception e) { long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.error("Failed updating accounts, took {} ms\"", timeForUpdate, e); accountServiceMetrics.updateAccountErrorCount.inc(); } finally { processAccountJsonLock.unlock(); } } }
JsonAccountService extends AbstractAccountService { public void processAccountJsonFile() { processAccountJsonLock.lock(); try { accountJsonProcessingStartTimeMs = System.currentTimeMillis(); logger.trace("Checking if JSON account file has changed."); if (!Files.exists(accountFile)) { logger.warn("Unable to open JSON account file '{}'", accountFile.toString()); return; } FileTime accountFileLastModified = Files.getLastModifiedTime(accountFile); if (accountFilePreviousModified == null || accountFilePreviousModified.compareTo(accountFileLastModified) < 0) { logger.debug("JSON Account file has changed or has never been loaded before. " + "Previous last know modified time: {}, new last known modified time: {}", accountFilePreviousModified, accountFileLastModified); String accountsJsonString = new String(Files.readAllBytes(accountFile), StandardCharsets.UTF_8); updateAccountsMap(accountsJsonString); accountFilePreviousModified = accountFileLastModified; } long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.trace("Completed updating accounts, took {} ms", timeForUpdate); accountServiceMetrics.updateAccountTimeInMs.update(timeForUpdate); } catch (Exception e) { long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.error("Failed updating accounts, took {} ms\"", timeForUpdate, e); accountServiceMetrics.updateAccountErrorCount.inc(); } finally { processAccountJsonLock.unlock(); } } JsonAccountService(Path accountFile, AccountServiceMetrics accountServiceMetrics, ScheduledExecutorService scheduler,
      JsonAccountConfig accountConfig); }
JsonAccountService extends AbstractAccountService { public void processAccountJsonFile() { processAccountJsonLock.lock(); try { accountJsonProcessingStartTimeMs = System.currentTimeMillis(); logger.trace("Checking if JSON account file has changed."); if (!Files.exists(accountFile)) { logger.warn("Unable to open JSON account file '{}'", accountFile.toString()); return; } FileTime accountFileLastModified = Files.getLastModifiedTime(accountFile); if (accountFilePreviousModified == null || accountFilePreviousModified.compareTo(accountFileLastModified) < 0) { logger.debug("JSON Account file has changed or has never been loaded before. " + "Previous last know modified time: {}, new last known modified time: {}", accountFilePreviousModified, accountFileLastModified); String accountsJsonString = new String(Files.readAllBytes(accountFile), StandardCharsets.UTF_8); updateAccountsMap(accountsJsonString); accountFilePreviousModified = accountFileLastModified; } long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.trace("Completed updating accounts, took {} ms", timeForUpdate); accountServiceMetrics.updateAccountTimeInMs.update(timeForUpdate); } catch (Exception e) { long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.error("Failed updating accounts, took {} ms\"", timeForUpdate, e); accountServiceMetrics.updateAccountErrorCount.inc(); } finally { processAccountJsonLock.unlock(); } } JsonAccountService(Path accountFile, AccountServiceMetrics accountServiceMetrics, ScheduledExecutorService scheduler,
      JsonAccountConfig accountConfig); @Override boolean updateAccounts(Collection<Account> accounts); @Override void close(); void processAccountJsonFile(); }
JsonAccountService extends AbstractAccountService { public void processAccountJsonFile() { processAccountJsonLock.lock(); try { accountJsonProcessingStartTimeMs = System.currentTimeMillis(); logger.trace("Checking if JSON account file has changed."); if (!Files.exists(accountFile)) { logger.warn("Unable to open JSON account file '{}'", accountFile.toString()); return; } FileTime accountFileLastModified = Files.getLastModifiedTime(accountFile); if (accountFilePreviousModified == null || accountFilePreviousModified.compareTo(accountFileLastModified) < 0) { logger.debug("JSON Account file has changed or has never been loaded before. " + "Previous last know modified time: {}, new last known modified time: {}", accountFilePreviousModified, accountFileLastModified); String accountsJsonString = new String(Files.readAllBytes(accountFile), StandardCharsets.UTF_8); updateAccountsMap(accountsJsonString); accountFilePreviousModified = accountFileLastModified; } long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.trace("Completed updating accounts, took {} ms", timeForUpdate); accountServiceMetrics.updateAccountTimeInMs.update(timeForUpdate); } catch (Exception e) { long timeForUpdate = System.currentTimeMillis() - accountJsonProcessingStartTimeMs; logger.error("Failed updating accounts, took {} ms\"", timeForUpdate, e); accountServiceMetrics.updateAccountErrorCount.inc(); } finally { processAccountJsonLock.unlock(); } } JsonAccountService(Path accountFile, AccountServiceMetrics accountServiceMetrics, ScheduledExecutorService scheduler,
      JsonAccountConfig accountConfig); @Override boolean updateAccounts(Collection<Account> accounts); @Override void close(); void processAccountJsonFile();  }