Search in sources :

Example 1 with AccountStatsMySqlConfig

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

the class AccountStatsMySqlStoreTest method testLocalBackupFile.

@Test
public void testLocalBackupFile() throws IOException {
    // First, make sure there is no local backup file.
    Path tempDir = Files.createTempDirectory("AccountStatsMySqlStoreTest");
    Path localBackupFilePath = tempDir.resolve("localbackup");
    Properties prop = new Properties();
    prop.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, localBackupFilePath.toString());
    AccountStatsMySqlConfig accountStatsMySqlConfig = new AccountStatsMySqlConfig(new VerifiableProperties(prop));
    AccountStatsMySqlStore store = new AccountStatsMySqlStore(accountStatsMySqlConfig, mockDataSource, clusterName, hostname, null, new MetricRegistry());
    assertNull(store.getPreviousHostAccountStorageStatsWrapper());
    // Second, save a backup file.
    HostAccountStorageStats hostAccountStorageStats = new HostAccountStorageStats(StorageStatsUtilTest.generateRandomHostAccountStorageStats(10, 10, 10, 10000L, 2, 10));
    StatsHeader header = new StatsHeader(StatsHeader.StatsDescription.STORED_DATA_SIZE, System.currentTimeMillis(), 10, 10, null);
    HostAccountStorageStatsWrapper statsWrapper = new HostAccountStorageStatsWrapper(header, hostAccountStorageStats);
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writeValue(localBackupFilePath.toFile(), statsWrapper);
    store = new AccountStatsMySqlStore(accountStatsMySqlConfig, mockDataSource, clusterName, hostname, null, new MetricRegistry());
    HostAccountStorageStatsWrapper backupWrapper = store.getPreviousHostAccountStorageStatsWrapper();
    assertNotNull(backupWrapper);
    assertStatsHeader(backupWrapper.getHeader(), 10, 10);
    Assert.assertEquals(hostAccountStorageStats.getStorageStats(), backupWrapper.getStats().getStorageStats());
}
Also used : Path(java.nio.file.Path) HostAccountStorageStats(com.github.ambry.server.storagestats.HostAccountStorageStats) HostAccountStorageStatsWrapper(com.github.ambry.server.HostAccountStorageStatsWrapper) VerifiableProperties(com.github.ambry.config.VerifiableProperties) StatsHeader(com.github.ambry.server.StatsHeader) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

Example 2 with AccountStatsMySqlConfig

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

the class HostnameHelperTest method testHostnameHelperBasic.

@Test
public void testHostnameHelperBasic() throws Exception {
    String[] domains = { ".github.com", ".travis.com", "noleadingdot.com", "  needtrim.com  ", "    " };
    AccountStatsMySqlConfig config = createAccountStatsMySqlConfig(String.join(",", domains));
    int port = 1000;
    HostnameHelper helper = new HostnameHelper(config, port);
    Assert.assertEquals("ambry-test1_1000", helper.simplifyHostname("ambry-test1.github.com"));
    Assert.assertEquals("ambry-test1_1000", helper.simplifyHostname("ambry-test1.travis.com"));
    Assert.assertEquals("ambry-test1_1000", helper.simplifyHostname("ambry-test1.noleadingdot.com"));
    Assert.assertEquals("ambry-test1_1000", helper.simplifyHostname("ambry-test1.needtrim.com"));
    Assert.assertEquals("ambry-test1.example.com_1000", helper.simplifyHostname("ambry-test1.example.com"));
}
Also used : AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig) Test(org.junit.Test)

Example 3 with AccountStatsMySqlConfig

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

the class HostnameHelperTest method createAccountStatsMySqlConfig.

private AccountStatsMySqlConfig createAccountStatsMySqlConfig(String domainNamesToRemove) {
    Properties properties = new Properties();
    properties.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, domainNamesToRemove);
    return new AccountStatsMySqlConfig(new VerifiableProperties(properties));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig)

Aggregations

AccountStatsMySqlConfig (com.github.ambry.config.AccountStatsMySqlConfig)3 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HostAccountStorageStatsWrapper (com.github.ambry.server.HostAccountStorageStatsWrapper)1 StatsHeader (com.github.ambry.server.StatsHeader)1 StorageStatsUtilTest (com.github.ambry.server.StorageStatsUtilTest)1 HostAccountStorageStats (com.github.ambry.server.storagestats.HostAccountStorageStats)1 Path (java.nio.file.Path)1