ConsolidationScoredPreferenceForSmallHosts extends ConsolidationAlgorithmBase { @Override protected boolean internalCanPowerOffAnotherHostInCloud(CloudResources cloudResources) { double cpuUsagePercentage = cloudCpuUsagePercentage(cloudResources); if (cpuUsagePercentage > 0.7) { return false; } double memoryUsagePercentage = cloudMemoryUsagePercentage(cloudResources); return memoryUsagePercentage < 0.7; }  @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts);  }
@Test public void internalCanPowerOffAnotherHostInCloudTestFalseCausedByCpu() { CloudResources cloud = new CloudResources(null, 0l, 10000l * BYTES_TO_MEGA_BYTES, 7001l, 2000l, 5); Assert.assertFalse(spyAlgorithm.internalCanPowerOffAnotherHostInCloud(cloud)); verifyMethodsCalledFromInternalCanPowerOffAnotherHostInCloud(cloud, 1, 1, 0); }
@Test public void internalCanPowerOffAnotherHostInCloudTestFalseCausedByMemory() { CloudResources cloud = new CloudResources(null, 7000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 0, 2000l, 5); Assert.assertFalse(spyAlgorithm.internalCanPowerOffAnotherHostInCloud(cloud)); verifyMethodsCalledFromInternalCanPowerOffAnotherHostInCloud(cloud, 1, 1, 1); }
@Test public void internalCanPowerOffAnotherHostInCloudTestTrue() { CloudResources cloud = new CloudResources(null, 5000l * BYTES_TO_MEGA_BYTES, 10000l * BYTES_TO_MEGA_BYTES, 5000, 2000l, 5); Assert.assertTrue(spyAlgorithm.internalCanPowerOffAnotherHostInCloud(cloud)); verifyMethodsCalledFromInternalCanPowerOffAnotherHostInCloud(cloud, 1, 1, 1); }