ConsolidationXenHaPreferenceForBigHostsHomogeneousEnvironment extends ConsolidationScoredPreferenceForBigHosts { @Override public Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts) { Map<Long, HostResources> vmsToHost = new HashMap<>(); if (rankedHosts.size() > 3) { for (int i = rankedHosts.size() - 1; i > 2; 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; } vmsDispersionHomogeneousHosts.rankHosts(rankedHosts); return vmsDispersionHomogeneousHosts.mapVMsToHost(rankedHosts); }  @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts);  }
@Test public void consolidateClusterWithTenHomogeneousHostsTest() { List<HostResources> hosts = createClusterHomogeneousHosts(10); Map<Long, HostResources> migrations = consolidationAlgorithm.mapVMsToHost(hosts); Assert.assertEquals(7, migrations.size()); }
@Test public void consolidateClusterWithTwoHomogeneousHostsTest() { List<HostResources> hosts = createClusterHomogeneousHosts(2); Map<Long, HostResources> migrations = consolidationAlgorithm.mapVMsToHost(hosts); Assert.assertEquals(0, migrations.size()); }
@Test public void consolidateClusterWithFourHomogeneousHostsTest() { List<HostResources> hosts = createClusterHomogeneousHosts(4); Map<Long, HostResources> migrations = consolidationAlgorithm.mapVMsToHost(hosts); Assert.assertEquals(1, migrations.size()); InOrder inOrder = Mockito.inOrder(consolidationAlgorithm); inOrder.verify(consolidationAlgorithm).canMigrateVmToHost(Mockito.any(VmResources.class), Mockito.any(HostResources.class)); inOrder.verify(consolidationAlgorithm).updateHostUsedResources(Mockito.any(VmResources.class), Mockito.any(HostResources.class)); }