StoragePolicySummary { void add(StorageType[] storageTypes, BlockStoragePolicy policy) { StorageTypeAllocation storageCombo = new StorageTypeAllocation(storageTypes, policy); Long count = storageComboCounts.get(storageCombo); if (count == null) { storageComboCounts.put(storageCombo, 1l); storageCombo.setActualStoragePolicy( getStoragePolicy(storageCombo.getStorageTypes())); } else { storageComboCounts.put(storageCombo, count.longValue()+1); } totalBlocks++; } StoragePolicySummary(BlockStoragePolicy[] storagePolicies); String toString();  }
@Test public void testMultipleHots() { BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite(); StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies()); BlockStoragePolicy hot = bsps.getPolicy("HOT"); sts.add(new StorageType[]{StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.DISK,StorageType.DISK},hot); Map<String, Long> actualOutput = convertToStringMap(sts); Assert.assertEquals(4,actualOutput.size()); Map<String, Long> expectedOutput = new HashMap<>(); expectedOutput.put("HOT|DISK:1(HOT)", 1l); expectedOutput.put("HOT|DISK:2(HOT)", 1l); expectedOutput.put("HOT|DISK:3(HOT)", 1l); expectedOutput.put("HOT|DISK:4(HOT)", 1l); Assert.assertEquals(expectedOutput,actualOutput); }
@Test public void testMultipleHotsWithDifferentCounts() { BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite(); StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies()); BlockStoragePolicy hot = bsps.getPolicy("HOT"); sts.add(new StorageType[]{StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.DISK,StorageType.DISK},hot); Map<String, Long> actualOutput = convertToStringMap(sts); Assert.assertEquals(4,actualOutput.size()); Map<String, Long> expectedOutput = new HashMap<>(); expectedOutput.put("HOT|DISK:1(HOT)", 1l); expectedOutput.put("HOT|DISK:2(HOT)", 2l); expectedOutput.put("HOT|DISK:3(HOT)", 2l); expectedOutput.put("HOT|DISK:4(HOT)", 1l); Assert.assertEquals(expectedOutput,actualOutput); }
@Test public void testMultipleWarmsInDifferentOrder() { BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite(); StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies()); BlockStoragePolicy warm = bsps.getPolicy("WARM"); sts.add(new StorageType[]{StorageType.DISK,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.ARCHIVE,StorageType.DISK},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.DISK,StorageType.DISK},warm); sts.add(new StorageType[]{StorageType.DISK, StorageType.ARCHIVE,StorageType.DISK},warm); sts.add(new StorageType[]{StorageType.DISK, StorageType.DISK,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.DISK, StorageType.ARCHIVE,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.DISK,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.DISK},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.DISK,StorageType.DISK},warm); Map<String, Long> actualOutput = convertToStringMap(sts); Assert.assertEquals(4,actualOutput.size()); Map<String, Long> expectedOutput = new HashMap<>(); expectedOutput.put("WARM|DISK:1,ARCHIVE:1(WARM)", 2l); expectedOutput.put("WARM|DISK:2,ARCHIVE:1", 3l); expectedOutput.put("WARM|DISK:1,ARCHIVE:2(WARM)", 3l); expectedOutput.put("WARM|DISK:2,ARCHIVE:2", 1l); Assert.assertEquals(expectedOutput,actualOutput); }
@Test public void testDifferentSpecifiedPolicies() { BlockStoragePolicySuite bsps = BlockStoragePolicySuite.createDefaultSuite(); StoragePolicySummary sts = new StoragePolicySummary(bsps.getAllPolicies()); BlockStoragePolicy hot = bsps.getPolicy("HOT"); BlockStoragePolicy warm = bsps.getPolicy("WARM"); BlockStoragePolicy cold = bsps.getPolicy("COLD"); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK,StorageType.DISK},hot); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK,StorageType.DISK},warm); sts.add(new StorageType[]{StorageType.DISK,StorageType.DISK,StorageType.DISK},cold); sts.add(new StorageType[]{StorageType.DISK, StorageType.ARCHIVE,StorageType.ARCHIVE},hot); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.DISK,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.DISK},cold); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.DISK},cold); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.ARCHIVE},hot); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.ARCHIVE},hot); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.ARCHIVE},warm); sts.add(new StorageType[]{StorageType.ARCHIVE, StorageType.ARCHIVE,StorageType.ARCHIVE},cold); Map<String, Long> actualOutput = convertToStringMap(sts); Assert.assertEquals(9,actualOutput.size()); Map<String, Long> expectedOutput = new HashMap<>(); expectedOutput.put("HOT|DISK:3(HOT)", 2l); expectedOutput.put("COLD|DISK:1,ARCHIVE:2(WARM)", 2l); expectedOutput.put("HOT|ARCHIVE:3(COLD)", 2l); expectedOutput.put("WARM|DISK:3(HOT)", 1l); expectedOutput.put("COLD|DISK:3(HOT)", 1l); expectedOutput.put("WARM|ARCHIVE:3(COLD)", 1l); expectedOutput.put("WARM|DISK:1,ARCHIVE:2(WARM)", 1l); expectedOutput.put("COLD|ARCHIVE:3(COLD)", 1l); expectedOutput.put("HOT|DISK:1,ARCHIVE:2(WARM)", 1l); Assert.assertEquals(expectedOutput,actualOutput); }