use of com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK in project photon-model by vmware.
the class TestAWSCostAdapterService method verifyCollectedStats.
private void verifyCollectedStats(List<ComputeStats> statsList) {
Map<String, ComputeStats> computeStatsByLink = statsList.stream().collect(Collectors.toMap(e -> e.computeLink, Function.identity(), (allStats, stats) -> {
allStats.statValues.putAll(stats.statValues);
return allStats;
}));
ComputeStats account1Stats = computeStatsByLink.get(account1SelfLink);
ComputeStats account2Stats = computeStatsByLink.get(account2SelfLink);
String normalizedStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST);
// verify account costs
assertTrue(account1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account1TotalCost);
assertTrue(account2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue == account2TotalCost);
// check that service level stats exist
String serviceCode = AwsServices.EC2_Instance_Usage.getName().replaceAll(" ", "");
String serviceResourceCostMetric = String.format(AWSConstants.SERVICE_RESOURCE_COST, serviceCode);
assertTrue(!account1Stats.statValues.get(serviceResourceCostMetric).isEmpty());
String serviceCode2 = AwsServices.EC2_Others.getName().replaceAll(" ", "");
String serviceOtherCostMetric = String.format(AWSConstants.SERVICE_OTHER_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceOtherCostMetric).isEmpty());
String serviceMonthlyOtherCostMetric = String.format(AWSConstants.SERVICE_MONTHLY_OTHER_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceMonthlyOtherCostMetric).isEmpty());
String serviceReservedRecurringCostMetric = String.format(AWSConstants.SERVICE_RESERVED_RECURRING_COST, serviceCode2);
assertTrue(!account1Stats.statValues.get(serviceReservedRecurringCostMetric).isEmpty());
ComputeStats instance1Stats = computeStatsByLink.get(INSTANCE_1_SELF_LINK);
ComputeStats instance2Stats = computeStatsByLink.get(INSTANCE_2_SELF_LINK);
assertEquals(instance1TotalCost, instance1Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
assertEquals(instance2TotalCost, instance2Stats.statValues.get(normalizedStatKeyValue).get(0).latestValue, 0);
String normalizedReservedInstanceStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.RESERVED_INSTANCE_DURATION);
assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
assertEquals(1.0, instance1Stats.statValues.get(normalizedReservedInstanceStatKeyValue).get(0).latestValue, 0);
// Check that stat values are accompanied with Units.
for (String key : account1Stats.statValues.keySet()) {
List<ServiceStat> stats = account1Stats.statValues.get(key);
for (ServiceStat stat : stats) {
assertTrue("Unit is empty", !stat.unit.isEmpty());
}
}
}
Aggregations