You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2013/07/12 09:51:25 UTC

[30/50] git commit: updated refs/heads/sdnextensions to bcfb4e6

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.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/51b02702
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/51b02702
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/51b02702

Branch: refs/heads/sdnextensions
Commit: 51b02702f91bb084dd20540190f02232b82617f5
Parents: 1e2f99b
Author: Devdeep Singh <de...@gmail.com>
Authored: Thu Jul 11 16:01:13 2013 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Thu Jul 11 16:05:51 2013 +0530

----------------------------------------------------------------------
 .../implicitplanner/ImplicitPlannerTest.java    | 46 +++++++++-----------
 1 file changed, 20 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/51b02702/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
----------------------------------------------------------------------
diff --git a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
index efbb5c2..e519668 100644
--- a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
+++ b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
@@ -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 {
             }
         }
     }
-}
+}
\ No newline at end of file