/** * Tests disabling the background thread. By setting the polling interval to 0ms, the accounts should not be fetched. * Therefore, after the {@link HelixAccountService} starts, there should be a single get call to the * {@link HelixPropertyStore}. * @throws Exception */ @Test public void testDisabledBackups() throws Exception { helixConfigProps.remove(HelixAccountServiceConfig.BACKUP_DIRECTORY_KEY); 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(); updateAccountsAndAssertAccountExistence(Collections.singleton(refAccount), 1, true); }
/** * Resets variables and settings, and cleans up if the store already exists. * @throws Exception Any unexpected exception. */ public HelixAccountServiceTest() throws Exception { helixConfigProps.setProperty( HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "zk.client.connection.timeout.ms", String.valueOf(ZK_CLIENT_CONNECTION_TIMEOUT_MS)); helixConfigProps.setProperty(HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "zk.client.session.timeout.ms", String.valueOf(ZK_CLIENT_SESSION_TIMEOUT_MS)); helixConfigProps.setProperty(HelixAccountServiceConfig.ZK_CLIENT_CONNECT_STRING_KEY, ZK_CONNECT_STRING); helixConfigProps.setProperty(HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "root.path", STORE_ROOT_PATH); accountBackupDir = Paths.get(TestUtils.getTempDir("account-backup")).toAbsolutePath(); helixConfigProps.setProperty(HelixAccountServiceConfig.BACKUP_DIRECTORY_KEY, accountBackupDir.toString()); vHelixConfigProps = new VerifiableProperties(helixConfigProps); storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps); notifier = new MockNotifier<>(); mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, null); deleteStoreIfExists(); generateReferenceAccountsAndContainers(); }
/** * Tests disabling the background thread. By setting the polling interval to 0ms, the accounts should not be fetched. * Therefore, after the {@link HelixAccountService} starts, there should be a single get call to the * {@link HelixPropertyStore}. */ @Test public void testDisableBackgroundUpdater() { helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATER_POLLING_INTERVAL_MS_KEY, "0"); 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(); assertEquals("Wrong number of thread for account updater.", 0, numThreadsByThisName(updaterThreadPrefix)); }
/** * 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); }