Updated Branches: refs/heads/vmsync ca3d6306f -> e31e33ccd
unit-test to track reset of hypervisor state sync Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e31e33cc Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e31e33cc Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e31e33cc Branch: refs/heads/vmsync Commit: e31e33ccd32d665421d2c13df81c67e740290745 Parents: ca3d630 Author: Kelven Yang <[email protected]> Authored: Wed Apr 24 11:38:32 2013 -0700 Committer: Kelven Yang <[email protected]> Committed: Wed Apr 24 11:38:32 2013 -0700 ---------------------------------------------------------------------- server/test/com/cloud/vm/dao/VmDaoTest.java | 31 ++++++++++++++++++++++ setup/db/db/schema-410to420.sql | 2 +- 2 files changed, 32 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e31e33cc/server/test/com/cloud/vm/dao/VmDaoTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/dao/VmDaoTest.java b/server/test/com/cloud/vm/dao/VmDaoTest.java index f5694a4..83f39f8 100644 --- a/server/test/com/cloud/vm/dao/VmDaoTest.java +++ b/server/test/com/cloud/vm/dao/VmDaoTest.java @@ -73,7 +73,10 @@ public class VmDaoTest extends TestCase { public void testPowerStateUpdate() { UserVmVO userVmInstance = new UserVmVO(1L, "Dummy", "DummyInstance", 1L, HypervisorType.Any, 1L, true, false, 1L, 1L, 1L, null, null, null); + userVmDao.persist(userVmInstance); + userVmInstance = new UserVmVO(2L, "Dummy2", "DummyInstance2", + 1L, HypervisorType.Any, 1L, true, false, 1L, 1L, 1L, null, null, null); userVmDao.persist(userVmInstance); VMInstanceVO instance = instanceDao.findById(1L); @@ -105,7 +108,35 @@ public class VmDaoTest extends TestCase { instance = instanceDao.findById(1L); Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOff); Assert.assertTrue(instance.getPowerStateUpdateCount() == 1); + + // reset state tracking + instanceDao.resetVmPowerStateTracking(1L); + instance = instanceDao.findById(1L); + Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOff); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 0); + + // update state tracking status twice (vm id: 1) + instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff); + instance = instanceDao.findById(1L); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 1); + + instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff); + instance = instanceDao.findById(1L); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 2); + + // update state tracking (vm id: 2) + instanceDao.updatePowerState(2L, 1L, VirtualMachine.PowerState.PowerOn); + instanceDao.updatePowerState(2L, 1L, VirtualMachine.PowerState.PowerOn); + instance = instanceDao.findById(2L); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 2); + + instanceDao.resetHostPowerStateTracking(1L); + instance = instanceDao.findById(1L); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 0); + instance = instanceDao.findById(2L); + Assert.assertTrue(instance.getPowerStateUpdateCount() == 0); userVmDao.expunge(1L); + userVmDao.expunge(2L); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e31e33cc/setup/db/db/schema-410to420.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 5b03148..a6f2c2b 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -419,5 +419,5 @@ ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_executing_msid` bigint; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state` VARCHAR(74) DEFAULT 'PowerUnknown'; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_count` INT DEFAULT 0; -ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_host` BIGINT; +ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_host` bigint unsigned; ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__power_host` FOREIGN KEY (`power_host`) REFERENCES `cloud`.`host`(`id`);
