@Override public AccountService getAccountService() { try { long startTimeMs = System.currentTimeMillis(); logger.info("Starting a HelixAccountService"); HelixPropertyStore<ZNRecord> helixStore = CommonUtils.createHelixPropertyStore(accountServiceConfig.zkClientConnectString, storeConfig, null); logger.info("HelixPropertyStore started with zkClientConnectString={}, zkClientSessionTimeoutMs={}, " + "zkClientConnectionTimeoutMs={}, rootPath={}", accountServiceConfig.zkClientConnectString, storeConfig.zkClientSessionTimeoutMs, storeConfig.zkClientConnectionTimeoutMs, storeConfig.rootPath); ScheduledExecutorService scheduler = accountServiceConfig.updaterPollingIntervalMs > 0 ? Utils.newScheduler(1, HELIX_ACCOUNT_UPDATER_PREFIX, false) : null; HelixAccountService helixAccountService = new HelixAccountService(helixStore, accountServiceMetrics, notifier, scheduler, accountServiceConfig); long spentTimeMs = System.currentTimeMillis() - startTimeMs; logger.info("HelixAccountService started, took {} ms", spentTimeMs); accountServiceMetrics.startupTimeInMs.update(spentTimeMs); return helixAccountService; } catch (Exception e) { throw new IllegalStateException("Could not instantiate HelixAccountService", e); } } }
@Override public void close() { if (open.compareAndSet(true, false)) { if (notifier != null) { notifier.unsubscribe(ACCOUNT_METADATA_CHANGE_TOPIC, changeTopicListener); } if (scheduler != null) { shutDownExecutorService(scheduler, config.updaterShutDownTimeoutMs, TimeUnit.MILLISECONDS); } helixStore.stop(); } }
refAccountId = Utils.getRandomShort(random); accountIdSet.add(refAccountId); refAccountName = UUID.randomUUID().toString(); refAccountStatus = random.nextBoolean() ? AccountStatus.ACTIVE : AccountStatus.INACTIVE; refContainerId = Utils.getRandomShort(random); refContainerName = UUID.randomUUID().toString(); refContainerStatus = random.nextBoolean() ? ContainerStatus.ACTIVE : ContainerStatus.INACTIVE;
idToRefContainerMap.clear(); for (int i = 0; i < accountCount; i++) { short accountId = Utils.getRandomShort(random); if (!accountIdSet.add(accountId)) { i--; Set<Short> containerIdSet = new HashSet<>(); for (int j = 0; j < containerCountPerAccount; j++) { short containerId = Utils.getRandomShort(random); if (!containerIdSet.add(containerId)) { j--;
@Test public void testAllMethods() throws Exception { assertEquals("Wrong account", null, accountService.getAccountById(Utils.getRandomShort(random))); assertEquals("Wrong account", InMemoryUnknownAccountService.UNKNOWN_ACCOUNT, accountService.getAccountById((short) -1)); assertEquals("Wrong account", InMemoryUnknownAccountService.UNKNOWN_ACCOUNT, accountService.getAccountByName(UtilsTest.getRandomString(10))); assertEquals("Wrong size of account collection", 1, accountService.getAllAccounts().size()); // updating the InMemoryUnknownAccountService should fail. Account account = new AccountBuilder((short) 1, "a", Account.AccountStatus.INACTIVE).build(); assertFalse("Wrong return value from an unsuccessful update operation", accountService.updateAccounts(Collections.singletonList(account))); assertEquals("Wrong size of account collection", 1, accountService.getAllAccounts().size()); try { accountService.getAllAccounts().add(account); fail("Should have thrown."); } catch (UnsupportedOperationException e) { // expected } accountService.close(); }
@Override public AccountService getAccountService() { try { ScheduledExecutorService scheduler = accountServiceConfig.updaterPollingIntervalMs > 0 ? Utils.newScheduler(1, updaterThreadPrefix, false) : null; return new HelixAccountService(getHelixStore(accountServiceConfig.zkClientConnectString, storeConfig), accountServiceMetrics, notifier, scheduler, accountServiceConfig); } catch (Exception e) { throw new IllegalStateException("Could not instantiate HelixAccountService", e); } }