VmsDispersionAlgorithmForHomogeneousEnvironment extends ConsolidationScoredPreferenceForSmallHosts { @Override public List<HostResources> rankHosts(List<HostResources> hostsList) { clusterMemoryUsagePercentage(hostsList); List<HostResources> sortedHosts = cloneListOfHosts(hostsList); setEachHostScore(sortedHosts); sortHosts(sortedHosts); return sortedHosts; } VmsDispersionAlgorithmForHomogeneousEnvironment(); @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts); @Override boolean internalCanPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts);  }
@Test public void rankHostHomogeneousMemoryConfigurationTest() { List<HostResources> hostsList = new ArrayList<HostResources>(); HostResources h0 = createHostConfiguringUsedMemory(1024); hostsList.add(h0); HostResources h1 = createHostConfiguringUsedMemory(512); hostsList.add(h1); HostResources h2 = createHostConfiguringUsedMemory(2048); hostsList.add(h2); List<HostResources> rankedHostsList = vmsDistributionAlgorithm.rankHosts(hostsList); Assert.assertEquals(hostsList.get(1).getUsedMemoryInMegaBytes(), rankedHostsList.get(0).getUsedMemoryInMegaBytes()); Assert.assertEquals(hostsList.get(0).getUsedMemoryInMegaBytes(), rankedHostsList.get(1).getUsedMemoryInMegaBytes()); Assert.assertEquals(hostsList.get(2).getUsedMemoryInMegaBytes(), rankedHostsList.get(2).getUsedMemoryInMegaBytes()); verifyRankHostCalledMethods(hostsList, rankedHostsList); }
@Test public void rankHostWithOneHostOfZeroMemoryUsageTest() { List<HostResources> hostsList = new ArrayList<HostResources>(); HostResources h0 = createHostConfiguringUsedMemory(1024); hostsList.add(h0); HostResources h1 = createEmptyHost(); hostsList.add(h1); List<HostResources> rankedHostsList = vmsDistributionAlgorithm.rankHosts(hostsList); Assert.assertEquals(hostsList.get(1).getUsedMemoryInMegaBytes(), rankedHostsList.get(0).getUsedMemoryInMegaBytes()); Assert.assertEquals(hostsList.get(0).getUsedMemoryInMegaBytes(), rankedHostsList.get(1).getUsedMemoryInMegaBytes()); verifyRankHostCalledMethods(hostsList, rankedHostsList); }