mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									1e2f99be68
								
							
						
					
					
						commit
						51b02702f9
					
				@ -202,11 +202,10 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        // Validations.
 | 
			
		||||
        // Check cluster 2 and 3 are not in the cluster list.
 | 
			
		||||
        // Host 6 and 7 should also be in avoid list.
 | 
			
		||||
        //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Cluster list should not be empty but ::" + clusterList.toString());
 | 
			
		||||
        assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
 | 
			
		||||
        boolean foundNeededCluster = false;
 | 
			
		||||
        for (Long cluster : clusterList) {
 | 
			
		||||
            if (cluster == 4) {
 | 
			
		||||
            if (cluster != 1) {
 | 
			
		||||
                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
 | 
			
		||||
            }else {
 | 
			
		||||
                foundNeededCluster = true;
 | 
			
		||||
@ -219,8 +218,7 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
 | 
			
		||||
        hostsThatShouldBeInAvoidList.add(6L);
 | 
			
		||||
        hostsThatShouldBeInAvoidList.add(7L);
 | 
			
		||||
        //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Host in avoidlist :: " +  hostsThatShouldBeInAvoidList.toString()); 
 | 
			
		||||
        assertFalse("Hosts 6 and 7 that should have been present were not found in avoid list" ,
 | 
			
		||||
        assertTrue("Hosts 6 and 7 that should have been present were not found in avoid list" ,
 | 
			
		||||
                hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -244,14 +242,11 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        // Host 5 and 7 should also be in avoid list.
 | 
			
		||||
        assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
 | 
			
		||||
        boolean foundNeededCluster = false;
 | 
			
		||||
        //System.out.println("Cluster list 2 should not be present ::" + clusterList.toString());
 | 
			
		||||
        for (Long cluster : clusterList) {
 | 
			
		||||
            if (cluster != 2) {
 | 
			
		||||
                fail("Found a cluster that shouldn't have been present, cluster id : " + cluster);
 | 
			
		||||
            }else {
 | 
			
		||||
            } else {
 | 
			
		||||
                foundNeededCluster = true;
 | 
			
		||||
                //System.out.println("Cluster list 2 should not be present breaking now" + cluster);
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
 | 
			
		||||
@ -261,7 +256,7 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
 | 
			
		||||
        hostsThatShouldBeInAvoidList.add(5L);
 | 
			
		||||
        hostsThatShouldBeInAvoidList.add(7L);
 | 
			
		||||
        assertFalse("Hosts 5 and 7 that should have been present were not found in avoid list" ,
 | 
			
		||||
        assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list" ,
 | 
			
		||||
                hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -283,8 +278,7 @@ public class ImplicitPlannerTest {
 | 
			
		||||
 | 
			
		||||
        // Validations.
 | 
			
		||||
        // Check cluster list is empty.
 | 
			
		||||
        //System.out.println("Cluster list should not be empty but  ::" + clusterList.toString());
 | 
			
		||||
        assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
 | 
			
		||||
        assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
@ -360,7 +354,7 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        when(vmProfile.getOwner()).thenReturn(account);
 | 
			
		||||
        when(vmProfile.getVirtualMachine()).thenReturn(vm);
 | 
			
		||||
        when(vmProfile.getId()).thenReturn(12L);
 | 
			
		||||
        when( vmDao.findById(12L)).thenReturn(userVm);
 | 
			
		||||
        when(vmDao.findById(12L)).thenReturn(userVm);
 | 
			
		||||
        when(userVm.getAccountId()).thenReturn(accountId);
 | 
			
		||||
 | 
			
		||||
        when(vm.getDataCenterId()).thenReturn(dataCenterId);
 | 
			
		||||
@ -440,20 +434,20 @@ public class ImplicitPlannerTest {
 | 
			
		||||
        UserVmVO vm3 = mock(UserVmVO.class);
 | 
			
		||||
        when(vm3.getAccountId()).thenReturn(201L);
 | 
			
		||||
        when(vm3.getServiceOfferingId()).thenReturn(offeringIdForVmsOfOtherAccount);
 | 
			
		||||
        List<UserVmVO> userVmsForHost1 = new ArrayList<UserVmVO>();
 | 
			
		||||
        List<UserVmVO> userVmsForHost2 = new ArrayList<UserVmVO>();
 | 
			
		||||
        List<UserVmVO> userVmsForHost3 = new ArrayList<UserVmVO>();
 | 
			
		||||
        List<UserVmVO> stoppedVmsForHost = new ArrayList<UserVmVO>();
 | 
			
		||||
        List<VMInstanceVO> vmsForHost1 = new ArrayList<VMInstanceVO>();
 | 
			
		||||
        List<VMInstanceVO> vmsForHost2 = new ArrayList<VMInstanceVO>();
 | 
			
		||||
        List<VMInstanceVO> vmsForHost3 = new ArrayList<VMInstanceVO>();
 | 
			
		||||
        List<VMInstanceVO> stoppedVmsForHost = new ArrayList<VMInstanceVO>();
 | 
			
		||||
        // Host 2 is empty.
 | 
			
		||||
        userVmsForHost1.add(vm1);
 | 
			
		||||
        userVmsForHost1.add(vm2);
 | 
			
		||||
        userVmsForHost3.add(vm3);
 | 
			
		||||
        when(vmDao.listUpByHostId(5L)).thenReturn(userVmsForHost1);
 | 
			
		||||
        when(vmDao.listUpByHostId(6L)).thenReturn(userVmsForHost2);
 | 
			
		||||
        when(vmDao.listUpByHostId(7L)).thenReturn(userVmsForHost3);
 | 
			
		||||
        when(vmDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
        when(vmDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
        when(vmDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
        vmsForHost1.add(vm1);
 | 
			
		||||
        vmsForHost1.add(vm2);
 | 
			
		||||
        vmsForHost3.add(vm3);
 | 
			
		||||
        when(vmInstanceDao.listUpByHostId(5L)).thenReturn(vmsForHost1);
 | 
			
		||||
        when(vmInstanceDao.listUpByHostId(6L)).thenReturn(vmsForHost2);
 | 
			
		||||
        when(vmInstanceDao.listUpByHostId(7L)).thenReturn(vmsForHost3);
 | 
			
		||||
        when(vmInstanceDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
        when(vmInstanceDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
        when(vmInstanceDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost);
 | 
			
		||||
 | 
			
		||||
        // Mock the offering with which the vm was created.
 | 
			
		||||
        ServiceOfferingVO offeringForVmOfThisAccount = mock(ServiceOfferingVO.class);
 | 
			
		||||
@ -589,4 +583,4 @@ public class ImplicitPlannerTest {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user