Source:
public void testPositiveAffinityWithPinnedOrHE() { List<VDS> hosts = Arrays.asList(host1, host2, host3); VM vm1 = createVmRunning(host2); VM vm2 = createVmRunning(host3); vm1.setMigrationSupport(MigrationSupport.PINNED_TO_HOST); affinityGroups.add(createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, true, vm1, vm2, newVm)); Map<Guid, Integer> scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertEquals((Integer)1000, scores.get(host1.getId())); assertEquals((Integer)1, scores.get(host2.getId())); assertEquals((Integer)2, scores.get(host3.getId())); vm1.setMigrationSupport(MigrationSupport.MIGRATABLE); vm1.setOrigin(OriginType.HOSTED_ENGINE); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertEquals((Integer)1000, scores.get(host1.getId())); assertEquals((Integer)1, scores.get(host2.getId())); assertEquals((Integer)2, scores.get(host3.getId())); vm1.setMigrationSupport(MigrationSupport.PINNED_TO_HOST); vm1.setOrigin(OriginType.RHEV); affinityGroups.clear(); affinityGroups.add(createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, false, vm1, vm2, newVm)); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertEquals((Integer)1000, scores.get(host1.getId())); assertEquals((Integer)1, scores.get(host2.getId())); assertEquals((Integer)2, scores.get(host3.getId())); vm1.setMigrationSupport(MigrationSupport.MIGRATABLE); vm1.setOrigin(OriginType.HOSTED_ENGINE); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertEquals((Integer)1000, scores.get(host1.getId())); assertEquals((Integer)1, scores.get(host2.getId())); assertEquals((Integer)2, scores.get(host3.getId())); }

Target:
public void testPositiveAffinityWithPinnedOrHE() { List<VDS> hosts = Arrays.asList(host1, host2, host3); VM vm1 = createVmRunning(host2); VM vm2 = createVmRunning(host3); vm1.setMigrationSupport(MigrationSupport.PINNED_TO_HOST); affinityGroups.add(createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, true, vm1, vm2, newVm)); Map<Guid, Integer> scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertThat(scores.get(host2.getId())).isLessThan(scores.get(host3.getId())); assertThat(scores.get(host3.getId())).isLessThan(scores.get(host1.getId())); vm1.setMigrationSupport(MigrationSupport.MIGRATABLE); vm1.setOrigin(OriginType.HOSTED_ENGINE); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertThat(scores.get(host2.getId())).isLessThan(scores.get(host3.getId())); assertThat(scores.get(host3.getId())).isLessThan(scores.get(host1.getId())); vm1.setMigrationSupport(MigrationSupport.PINNED_TO_HOST); vm1.setOrigin(OriginType.RHEV); affinityGroups.clear(); affinityGroups.add(createAffinityGroup(cluster, EntityAffinityRule.POSITIVE, false, vm1, vm2, newVm)); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertThat(scores.get(host2.getId())).isLessThan(scores.get(host3.getId())); assertThat(scores.get(host3.getId())).isLessThan(scores.get(host1.getId())); vm1.setMigrationSupport(MigrationSupport.MIGRATABLE); vm1.setOrigin(OriginType.HOSTED_ENGINE); scores = collectScores(policyUnit.score(cluster, hosts, newVm, null)); assertThat(scores.get(host2.getId())).isLessThan(scores.get(host3.getId())); assertThat(scores.get(host3.getId())).isLessThan(scores.get(host1.getId())); }