ConsolidationAlgorithmBase extends ClusterManagementDummyAlgorithm { @Override public Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts) { Map<Long, HostResources> vmsToHost = new HashMap<>(); for (int i = rankedHosts.size() - 1; i > 0; i--) { for (VmResources vmResources : rankedHosts.get(i).getVmsResources()) { for (HostResources hostCandidateToStayRunning : rankedHosts) { if (canMigrateVmToHost(vmResources, hostCandidateToStayRunning)) { vmsToHost.put(vmResources.getVmId(), hostCandidateToStayRunning); updateHostUsedResources(vmResources, hostCandidateToStayRunning); break; } } } } return vmsToHost; }  @Override int getClusterIntervalBetweenConsolidation(); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts); boolean canMigrateVmToHost(VmResources vm, HostResources host); void updateHostUsedResources(VmResources vm, HostResources host); @Override final boolean canPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources); @Override final boolean canPowerOffAnotherHostInCloud(CloudResources cloudResources); @Override boolean canHeuristicShutdownHosts();  }
@Test public void mapVMsToHost() { List<HostResources> hosts = createHosts(); Map<Long, HostResources> migrations = spyAlgorithm.mapVMsToHost(hosts); long id = hosts.get(1).getVmsResources().get(0).getVmId(); Assert.assertEquals(1, migrations.size()); Assert.assertEquals(3000l, hosts.get(0).getUsedCpu()); Assert.assertEquals(1500l, hosts.get(0).getUsedMemoryInMegaBytes()); Assert.assertEquals(hosts.get(0).getHostId(), migrations.get(id).getHostId()); InOrder inOrder = Mockito.inOrder(spyAlgorithm); inOrder.verify(spyAlgorithm).canMigrateVmToHost(hosts.get(1).getVmsResources().get(0), hosts.get(0)); inOrder.verify(spyAlgorithm).updateHostUsedResources(hosts.get(1).getVmsResources().get(0), hosts.get(0)); }