ConsolidationScoredPreferenceForSmallHosts extends ConsolidationAlgorithmBase { @Override protected boolean internalCanPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources) { double expectedCpuUsagePercentage = getCloudExpetedCpuUsageAfterHostShutdown(hostToPowerOff, cloudResources); if (expectedCpuUsagePercentage > 0.7) { return false; } double expectedMemoryUsagePercentage = getCloudExpetedMemoryUsagePercentageAfterHostShutdown(hostToPowerOff, cloudResources); return expectedMemoryUsagePercentage < 0.7; }  @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts);  }
@Test public void internalCanPowerOffHostTestFalseCausedByCpu() { HostResources host = createHost(3, 2000l, 0l, 2000l, 0l); CloudResources cloud = new CloudResources(null, 5000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 5000, 2000l, 5); Assert.assertFalse(spyAlgorithm.internalCanPowerOffHost(host, cloud)); verifyInternalCannPowerOffCalledMethods(1, 0); }
@Test public void internalCanPowerOffHostTestFalseCausedByMemory() { HostResources host = createHost(2, 1000l, 0l, 3000l, 0l); CloudResources cloud = new CloudResources(null, 5000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 5000, 2000l, 5); Assert.assertFalse(spyAlgorithm.internalCanPowerOffHost(host, cloud)); verifyInternalCannPowerOffCalledMethods(1, 1); }
@Test public void internalCanPowerOffHostTestTrue() { HostResources host = createHost(2, 1000l, 0l, 2000l, 0l); CloudResources cloud = new CloudResources(null, 5000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 5000, 2000l, 5); Assert.assertTrue(spyAlgorithm.internalCanPowerOffHost(host, cloud)); verifyInternalCannPowerOffCalledMethods(1, 1); }