Skip to content

Commit 293e545

Browse files
committed
CLOUDSTACK-3467: Fixing the unit tests for implicit dedication planner. When fix for bug 2662
was made the unit tests were not updated correctly. The unit tests should have been changed to return the correct mock object (VMInstanceVO) when vmInstanceDao is queried for the vms running on host.
1 parent b1f7056 commit 293e545

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

‎plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,10 @@ public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientSer
202202
// Validations.
203203
// Check cluster 2 and 3 are not in the cluster list.
204204
// Host 6 and 7 should also be in avoid list.
205-
//System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Cluster list should not be empty but ::" + clusterList.toString());
206205
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
207206
boolean foundNeededCluster = false;
208207
for (Long cluster : clusterList) {
209-
if (cluster == 4) {
208+
if (cluster != 1) {
210209
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
211210
}else {
212211
foundNeededCluster = true;
@@ -219,8 +218,7 @@ public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientSer
219218
Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
220219
hostsThatShouldBeInAvoidList.add(6L);
221220
hostsThatShouldBeInAvoidList.add(7L);
222-
//System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Host in avoidlist :: " + hostsThatShouldBeInAvoidList.toString());
223-
assertFalse("Hosts 6 and 7 that should have been present were not found in avoid list" ,
221+
assertTrue("Hosts 6 and 7 that should have been present were not found in avoid list" ,
224222
hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
225223
}
226224

@@ -244,14 +242,11 @@ public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientSe
244242
// Host 5 and 7 should also be in avoid list.
245243
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
246244
boolean foundNeededCluster = false;
247-
//System.out.println("Cluster list 2 should not be present ::" + clusterList.toString());
248245
for (Long cluster : clusterList) {
249246
if (cluster != 2) {
250247
fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
251-
}else {
248+
} else {
252249
foundNeededCluster = true;
253-
//System.out.println("Cluster list 2 should not be present breaking now" + cluster);
254-
break;
255250
}
256251
}
257252
assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
@@ -261,7 +256,7 @@ public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientSe
261256
Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
262257
hostsThatShouldBeInAvoidList.add(5L);
263258
hostsThatShouldBeInAvoidList.add(7L);
264-
assertFalse("Hosts 5 and 7 that should have been present were not found in avoid list" ,
259+
assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list" ,
265260
hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
266261
}
267262

@@ -283,8 +278,7 @@ public void checkStrictModeNoHostsAvailable() throws InsufficientServerCapacityE
283278

284279
// Validations.
285280
// Check cluster list is empty.
286-
//System.out.println("Cluster list should not be empty but ::" + clusterList.toString());
287-
assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
281+
assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
288282
}
289283

290284
@Test
@@ -360,7 +354,7 @@ private void initializeForTest(VirtualMachineProfileImpl<VMInstanceVO> vmProfile
360354
when(vmProfile.getOwner()).thenReturn(account);
361355
when(vmProfile.getVirtualMachine()).thenReturn(vm);
362356
when(vmProfile.getId()).thenReturn(12L);
363-
when( vmDao.findById(12L)).thenReturn(userVm);
357+
when(vmDao.findById(12L)).thenReturn(userVm);
364358
when(userVm.getAccountId()).thenReturn(accountId);
365359

366360
when(vm.getDataCenterId()).thenReturn(dataCenterId);
@@ -440,20 +434,20 @@ private void initializeForImplicitPlannerTest(boolean preferred) {
440434
UserVmVO vm3 = mock(UserVmVO.class);
441435
when(vm3.getAccountId()).thenReturn(201L);
442436
when(vm3.getServiceOfferingId()).thenReturn(offeringIdForVmsOfOtherAccount);
443-
List<UserVmVO> userVmsForHost1 = new ArrayList<UserVmVO>();
444-
List<UserVmVO> userVmsForHost2 = new ArrayList<UserVmVO>();
445-
List<UserVmVO> userVmsForHost3 = new ArrayList<UserVmVO>();
446-
List<UserVmVO> stoppedVmsForHost = new ArrayList<UserVmVO>();
437+
List<VMInstanceVO> vmsForHost1 = new ArrayList<VMInstanceVO>();
438+
List<VMInstanceVO> vmsForHost2 = new ArrayList<VMInstanceVO>();
439+
List<VMInstanceVO> vmsForHost3 = new ArrayList<VMInstanceVO>();
440+
List<VMInstanceVO> stoppedVmsForHost = new ArrayList<VMInstanceVO>();
447441
// Host 2 is empty.
448-
userVmsForHost1.add(vm1);
449-
userVmsForHost1.add(vm2);
450-
userVmsForHost3.add(vm3);
451-
when(vmDao.listUpByHostId(5L)).thenReturn(userVmsForHost1);
452-
when(vmDao.listUpByHostId(6L)).thenReturn(userVmsForHost2);
453-
when(vmDao.listUpByHostId(7L)).thenReturn(userVmsForHost3);
454-
when(vmDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost);
455-
when(vmDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost);
456-
when(vmDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost);
442+
vmsForHost1.add(vm1);
443+
vmsForHost1.add(vm2);
444+
vmsForHost3.add(vm3);
445+
when(vmInstanceDao.listUpByHostId(5L)).thenReturn(vmsForHost1);
446+
when(vmInstanceDao.listUpByHostId(6L)).thenReturn(vmsForHost2);
447+
when(vmInstanceDao.listUpByHostId(7L)).thenReturn(vmsForHost3);
448+
when(vmInstanceDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost);
449+
when(vmInstanceDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost);
450+
when(vmInstanceDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost);
457451

458452
// Mock the offering with which the vm was created.
459453
ServiceOfferingVO offeringForVmOfThisAccount = mock(ServiceOfferingVO.class);
@@ -589,4 +583,4 @@ public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOEx
589583
}
590584
}
591585
}
592-
}
586+
}

0 commit comments

Comments
 (0)