ConsolidationScoredPreferenceForSmallHosts extends ConsolidationAlgorithmBase { protected double getCloudExpetedMemoryUsagePercentageAfterHostShutdown(HostResources hostToPowerOff, CloudResources cloudResources) { double hostMemory = (hostToPowerOff.getTotalMemoryInBytes() / BYTES_TO_MEGA_BYTES) * hostToPowerOff.getMemoryOverprovisioning(); double expectedCloudMemoryAfterShutDown = (cloudResources.getMemoryInBytes() / BYTES_TO_MEGA_BYTES) - hostMemory; return (cloudResources.getUsedMemory() / BYTES_TO_MEGA_BYTES) / expectedCloudMemoryAfterShutDown; }  @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts);  }
@Test public void getCloudExpetedMemoryUsagePercentageAfterHostShutdownTest() { HostResources host = createHost(2, 1000l, 0l, 2000l, 0l); CloudResources cloud = new CloudResources(null, 4000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 0, 0, 0); Assert.assertEquals(0.5, spyAlgorithm.getCloudExpetedMemoryUsagePercentageAfterHostShutdown(host, cloud), 0.0); }