/** * Gets a {@link MockHelixPropertyStore} for the given {@link HelixPropertyStoreConfig}. * @param zkServers the ZooKeeper server address. * @param storeConfig A {@link HelixPropertyStoreConfig}. * @return A {@link MockHelixPropertyStore} defined by the {@link HelixPropertyStoreConfig}. */ MockHelixPropertyStore<ZNRecord> getHelixStore(String zkServers, HelixPropertyStoreConfig storeConfig) { return storeKeyToMockStoreMap.computeIfAbsent(zkServers + storeConfig.rootPath, path -> new MockHelixPropertyStore<>()); } }
/** * Tests the background updater for updating accounts from remote. During the initialization of * {@link HelixAccountService}, its internal {@link HelixPropertyStore} will be read to first time get account data. * Because of the background account updater, it should continuously make get calls to the {@link HelixPropertyStore}, * even no notification for account updates is received. Therefore, there will be more than 1 get calls to the * {@link HelixPropertyStore}. * @throws Exception */ @Test public void testBackgroundUpdater() throws Exception { helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATER_POLLING_INTERVAL_MS_KEY, "1"); vHelixConfigProps = new VerifiableProperties(helixConfigProps); storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps); String updaterThreadPrefix = UUID.randomUUID().toString(); MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix); accountService = mockHelixAccountServiceFactory.getAccountService(); CountDownLatch latch = new CountDownLatch(1); mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig).setReadLatch(latch); assertEquals("Wrong number of thread for account updater.", 1, numThreadsByThisName(updaterThreadPrefix)); awaitLatchOrTimeout(latch, 100); }