Search in sources :

Example 16 with StatsWrapper

use of com.github.ambry.server.StatsWrapper in project ambry by linkedin.

the class AccountStatsMySqlStoreIntegrationTest method testMultiStoreStats.

/**
 * Tests to store multiple stats for multiple hosts and recover stats from database.
 * @throws Exception
 */
@Test
public void testMultiStoreStats() throws Exception {
    AccountStatsMySqlStore mySqlStore1 = createAccountStatsMySqlStore(clusterName1, hostname1, port1);
    AccountStatsMySqlStore mySqlStore2 = createAccountStatsMySqlStore(clusterName1, hostname2, port2);
    AccountStatsMySqlStore mySqlStore3 = createAccountStatsMySqlStore(clusterName2, hostname3, port3);
    // Generating StatsWrappers, store StatsWrappers and retrieve StatsWrappers
    StatsWrapper stats1 = generateStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    StatsWrapper stats2 = generateStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    StatsWrapper stats3 = generateStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    mySqlStore1.storeAccountStats(stats1);
    mySqlStore2.storeAccountStats(stats2);
    mySqlStore3.storeAccountStats(stats3);
    assertTableSize(mySqlStore1, 3 * 10 * 10);
    StatsWrapper obtainedStats1 = mySqlStore1.queryAccountStatsByHost(hostname1, port1);
    StatsWrapper obtainedStats2 = mySqlStore2.queryAccountStatsByHost(hostname2, port2);
    StatsWrapper obtainedStats3 = mySqlStore3.queryAccountStatsByHost(hostname3, port3);
    assertTwoStatsSnapshots(obtainedStats1.getSnapshot(), stats1.getSnapshot());
    assertTwoStatsSnapshots(obtainedStats2.getSnapshot(), stats2.getSnapshot());
    assertTwoStatsSnapshots(obtainedStats3.getSnapshot(), stats3.getSnapshot());
    // Generating HostAccountStorageStatsWrappers, store and retrieve them
    HostAccountStorageStatsWrapper hostStats1 = generateHostAccountStorageStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    HostAccountStorageStatsWrapper hostStats2 = generateHostAccountStorageStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    HostAccountStorageStatsWrapper hostStats3 = generateHostAccountStorageStatsWrapper(10, 10, 1, StatsReportType.ACCOUNT_REPORT);
    mySqlStore1.storeHostAccountStorageStats(hostStats1);
    mySqlStore2.storeHostAccountStorageStats(hostStats2);
    mySqlStore3.storeHostAccountStorageStats(hostStats3);
    HostAccountStorageStatsWrapper obtainedHostStats1 = mySqlStore1.queryHostAccountStorageStatsByHost(hostname1, port1);
    HostAccountStorageStatsWrapper obtainedHostStats2 = mySqlStore2.queryHostAccountStorageStatsByHost(hostname2, port2);
    HostAccountStorageStatsWrapper obtainedHostStats3 = mySqlStore3.queryHostAccountStorageStatsByHost(hostname3, port3);
    assertEquals(hostStats1.getStats().getStorageStats(), obtainedHostStats1.getStats().getStorageStats());
    assertEquals(hostStats2.getStats().getStorageStats(), obtainedHostStats2.getStats().getStorageStats());
    assertEquals(hostStats3.getStats().getStorageStats(), obtainedHostStats3.getStats().getStorageStats());
    // Retrieve StatWrappers
    obtainedStats1 = mySqlStore1.queryAccountStatsByHost(hostname1, port1);
    StatsSnapshot converted = StorageStatsUtil.convertHostAccountStorageStatsToStatsSnapshot(hostStats1.getStats(), false);
    assertTwoStatsSnapshots(converted, obtainedStats1.getSnapshot());
    mySqlStore1.shutdown();
    mySqlStore2.shutdown();
    mySqlStore3.shutdown();
}
Also used : HostAccountStorageStatsWrapper(com.github.ambry.server.HostAccountStorageStatsWrapper) HostAccountStorageStatsWrapper(com.github.ambry.server.HostAccountStorageStatsWrapper) StatsWrapper(com.github.ambry.server.StatsWrapper) HostPartitionClassStorageStatsWrapper(com.github.ambry.server.HostPartitionClassStorageStatsWrapper) StatsSnapshot(com.github.ambry.server.StatsSnapshot) Test(org.junit.Test) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

Aggregations

StatsWrapper (com.github.ambry.server.StatsWrapper)16 StatsSnapshot (com.github.ambry.server.StatsSnapshot)15 HashMap (java.util.HashMap)11 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Random (java.util.Random)8 StatsReportType (com.github.ambry.server.StatsReportType)7 StatsHeader (com.github.ambry.server.StatsHeader)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 HostAccountStorageStatsWrapper (com.github.ambry.server.HostAccountStorageStatsWrapper)4 HostPartitionClassStorageStatsWrapper (com.github.ambry.server.HostPartitionClassStorageStatsWrapper)4 Pair (com.github.ambry.utils.Pair)4 IOException (java.io.IOException)4 StorageStatsUtilTest (com.github.ambry.server.StorageStatsUtilTest)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 AccountStatsMySqlConfig (com.github.ambry.config.AccountStatsMySqlConfig)2 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 StorageStatsUtil (com.github.ambry.server.StorageStatsUtil)2