Search in sources :

Example 6 with HelixPropertyStoreConfig

use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.

the class HelixAccountServiceTest method setup.

@Before
public void setup() {
    helixConfigProps.clear();
    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);
    helixConfigProps.setProperty(HelixAccountServiceConfig.BACKUP_DIRECTORY_KEY, accountBackupDir.toString());
    helixConfigProps.setProperty(HelixAccountServiceConfig.USE_NEW_ZNODE_PATH, String.valueOf(useNewZNodePath));
    vHelixConfigProps = new VerifiableProperties(helixConfigProps);
    storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
    mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, null, mockRouter);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) Before(org.junit.Before)

Example 7 with HelixPropertyStoreConfig

use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.

the class HelixAccountServiceTest method testDisabledBackups.

/**
 * 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, mockRouter);
    accountService = mockHelixAccountServiceFactory.getAccountService();
    updateAccountsAndAssertAccountExistence(Collections.singleton(refAccount), 1, true);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 8 with HelixPropertyStoreConfig

use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.

the class HelixAccountServiceTest method testDisableBackgroundUpdater.

/**
 * 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, mockRouter);
    accountService = mockHelixAccountServiceFactory.getAccountService();
    assertEquals("Wrong number of thread for account updater.", 0, numThreadsByThisName(updaterThreadPrefix));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 9 with HelixPropertyStoreConfig

use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.

the class HelixAccountServiceTest method testStartWithBackupFiles.

/**
 * Tests starting up a {@link HelixAccountService}, when the corresponding {@code ZooKeeper} does not have any
 * {@link ZNRecord} on it but local backup files exists.
 * @throws Exception Any unexpected exception
 */
@Test
public void testStartWithBackupFiles() throws Exception {
    // use testUpdateAccount function to create backups and then delete helixStore data.
    testUpdateAccount();
    if (accountService != null) {
        accountService.close();
    }
    deleteStoreIfExists();
    // should have some backup files.
    if (helixConfigProps.containsKey(HelixAccountServiceConfig.BACKUP_DIRECTORY_KEY)) {
        File[] files = accountBackupDir.toFile().listFiles(path -> BackupFileManager.versionFilenamePattern.matcher(path.getName()).find());
        assertTrue("UpdateAccount should create backup files", files.length > 0);
        helixConfigProps.put(HelixAccountServiceConfig.ENABLE_SERVE_FROM_BACKUP, "true");
        vHelixConfigProps = new VerifiableProperties(helixConfigProps);
        storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
        String updaterThreadPrefix = UUID.randomUUID().toString();
        MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix, mockRouter);
        accountService = mockHelixAccountServiceFactory.getAccountService();
        assertNotNull("Backup files should have data", accountService.getAllAccounts());
        assertEquals("Number of accounts from backup mismatch", accountService.getAllAccounts().size(), 1 + NUM_REF_ACCOUNT);
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) File(java.io.File) Test(org.junit.Test)

Example 10 with HelixPropertyStoreConfig

use of com.github.ambry.config.HelixPropertyStoreConfig in project ambry by linkedin.

the class HelixNotifierTest method getHelixStoreConfig.

/**
 * A util method that generates {@link HelixPropertyStoreConfig}.
 * @param zkClientConnectString The connect string to connect to a {@code ZooKeeper}.
 * @param zkClientSessionTimeoutMs Timeout for a zk session.
 * @param zkClientConnectionTimeoutMs Timeout for a zk connection.
 * @param storeRootPath The root path of a store in {@code ZooKeeper}.
 * @return {@link HelixPropertyStoreConfig} defined by the arguments.
 */
public static HelixPropertyStoreConfig getHelixStoreConfig(String zkClientConnectString, int zkClientSessionTimeoutMs, int zkClientConnectionTimeoutMs, String storeRootPath) {
    Properties helixConfigProps = new Properties();
    helixConfigProps.setProperty(HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "zk.client.connection.timeout.ms", String.valueOf(zkClientConnectionTimeoutMs));
    helixConfigProps.setProperty(HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "zk.client.session.timeout.ms", String.valueOf(zkClientSessionTimeoutMs));
    helixConfigProps.setProperty(HelixAccountServiceConfig.ZK_CLIENT_CONNECT_STRING_KEY, zkClientConnectString);
    helixConfigProps.setProperty(HelixPropertyStoreConfig.HELIX_PROPERTY_STORE_PREFIX + "root.path", storeRootPath);
    VerifiableProperties vHelixConfigProps = new VerifiableProperties(helixConfigProps);
    return new HelixPropertyStoreConfig(vHelixConfigProps);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Aggregations

HelixPropertyStoreConfig (com.github.ambry.config.HelixPropertyStoreConfig)12 VerifiableProperties (com.github.ambry.config.VerifiableProperties)12 MetricRegistry (com.codahale.metrics.MetricRegistry)7 Test (org.junit.Test)7 Properties (java.util.Properties)6 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Account (com.github.ambry.account.Account)1 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HelixException (org.apache.helix.HelixException)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 IdealState (org.apache.helix.model.IdealState)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1 JSONException (org.json.JSONException)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1