http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aff0220d/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java deleted file mode 100644 index 659adb7..0000000 --- a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java +++ /dev/null @@ -1,433 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package com.cloud.vm; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -import org.apache.cloudstack.api.command.user.vm.RestoreVMCmd; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; - -import com.cloud.agent.AgentManager; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.CheckVirtualMachineAnswer; -import com.cloud.agent.api.CheckVirtualMachineCommand; -import com.cloud.agent.api.MigrateWithStorageAnswer; -import com.cloud.agent.api.MigrateWithStorageCommand; -import com.cloud.agent.api.MigrateWithStorageCompleteAnswer; -import com.cloud.agent.api.MigrateWithStorageCompleteCommand; -import com.cloud.agent.api.MigrateWithStorageReceiveAnswer; -import com.cloud.agent.api.MigrateWithStorageReceiveCommand; -import com.cloud.agent.api.MigrateWithStorageSendAnswer; -import com.cloud.agent.api.MigrateWithStorageSendCommand; -import com.cloud.agent.api.PrepareForMigrationAnswer; -import com.cloud.agent.api.PrepareForMigrationCommand; -import com.cloud.agent.api.ScaleVmAnswer; -import com.cloud.agent.api.ScaleVmCommand; -import com.cloud.capacity.CapacityManager; -import com.cloud.configuration.ConfigurationManager; -import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.dao.EntityManager; -import com.cloud.dc.dao.ClusterDao; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.HostPodDao; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.ManagementServerException; -import com.cloud.exception.OperationTimedoutException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.exception.VirtualMachineMigrationException; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.hypervisor.HypervisorGuru; -import com.cloud.hypervisor.HypervisorGuruManager; -import com.cloud.network.NetworkManager; -import com.cloud.service.ServiceOfferingVO; -import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.StoragePool; -import com.cloud.storage.StoragePoolHostVO; -import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.Volume; -import com.cloud.storage.VolumeManager; -import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.DiskOfferingDao; -import com.cloud.storage.dao.StoragePoolHostDao; -import com.cloud.storage.dao.VMTemplateDao; -import com.cloud.storage.dao.VolumeDao; -import com.cloud.user.Account; -import com.cloud.user.AccountManager; -import com.cloud.user.AccountVO; -import com.cloud.user.UserVO; -import com.cloud.user.dao.AccountDao; -import com.cloud.user.dao.UserDao; -import com.cloud.utils.Pair; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.vm.VirtualMachine.Event; -import com.cloud.vm.VirtualMachine.PowerState; -import com.cloud.vm.VirtualMachine.State; -import com.cloud.vm.dao.UserVmDao; -import com.cloud.vm.dao.VMInstanceDao; -import com.cloud.vm.snapshot.VMSnapshotManager; - -public class VirtualMachineManagerImplTest { - - @Spy VirtualMachineManagerImpl _vmMgr = new VirtualMachineManagerImpl(); - @Mock - VolumeManager _storageMgr; - @Mock - Account _account; - @Mock - AccountManager _accountMgr; - @Mock - ConfigurationManager _configMgr; - @Mock - CapacityManager _capacityMgr; - @Mock - AgentManager _agentMgr; - @Mock - AccountDao _accountDao; - @Mock - ConfigurationDao _configDao; - @Mock - HostDao _hostDao; - @Mock - UserDao _userDao; - @Mock - UserVmDao _vmDao; - @Mock - ItWorkDao _workDao; - @Mock - VMInstanceDao _vmInstanceDao; - @Mock - VMTemplateDao _templateDao; - @Mock - VolumeDao _volsDao; - @Mock - RestoreVMCmd _restoreVMCmd; - @Mock - AccountVO _accountMock; - @Mock - UserVO _userMock; - @Mock - UserVmVO _vmMock; - @Mock - VMInstanceVO _vmInstance; - @Mock - HostVO _host; - @Mock - VMTemplateVO _templateMock; - @Mock - VolumeVO _volumeMock; - @Mock - List<VolumeVO> _rootVols; - @Mock - ItWorkVO _work; - - @Mock - EntityManager _entityMgr; - - @Mock ClusterDao _clusterDao; - @Mock HostPodDao _podDao; - @Mock DataCenterDao _dcDao; - @Mock DiskOfferingDao _diskOfferingDao; - @Mock PrimaryDataStoreDao _storagePoolDao; - @Mock StoragePoolHostDao _poolHostDao; - @Mock NetworkManager _networkMgr; - @Mock HypervisorGuruManager _hvGuruMgr; - @Mock VMSnapshotManager _vmSnapshotMgr; - - // Mock objects for vm migration with storage test. - @Mock DiskOfferingVO _diskOfferingMock; - @Mock StoragePoolVO _srcStoragePoolMock; - @Mock StoragePoolVO _destStoragePoolMock; - @Mock HostVO _srcHostMock; - @Mock HostVO _destHostMock; - @Mock - Map<Volume, StoragePool> _volumeToPoolMock; - - @Before - public void setup(){ - MockitoAnnotations.initMocks(this); - - _vmMgr._entityMgr = _entityMgr; - _vmMgr._volsDao = _volsDao; - _vmMgr._volumeMgr = _storageMgr; - _vmMgr._accountMgr = _accountMgr; - _vmMgr._configMgr = _configMgr; - _vmMgr._hostDao = _hostDao; - _vmMgr._nodeId = 1L; -/* - _vmMgr._workDao = _workDao; -*/ - _vmMgr._agentMgr = _agentMgr; - _vmMgr._poolHostDao= _poolHostDao; - _vmMgr._networkMgr = _networkMgr; - _vmMgr._hvGuruMgr = _hvGuruMgr; - _vmMgr._vmSnapshotMgr = _vmSnapshotMgr; - _vmMgr._vmDao = _vmInstanceDao; - - when(_vmMock.getId()).thenReturn(314l); - when(_vmInstance.getId()).thenReturn(1L); - when(_vmInstance.getServiceOfferingId()).thenReturn(2L); - when(_vmInstance.getInstanceName()).thenReturn("myVm"); - when(_vmInstance.getHostId()).thenReturn(2L); - when(_vmInstance.getType()).thenReturn(VirtualMachine.Type.User); - when(_host.getId()).thenReturn(1L); - when(_hostDao.findById(anyLong())).thenReturn(null); - when(_configMgr.getServiceOffering(anyLong())).thenReturn(getSvcoffering(512)); - when(_workDao.persist(_work)).thenReturn(_work); - when(_workDao.update("1", _work)).thenReturn(true); - when(_work.getId()).thenReturn("1"); - doNothing().when(_work).setStep(ItWorkVO.Step.Done); - //doNothing().when(_volsDao).detachVolume(anyLong()); - //when(_work.setStep(ItWorkVO.Step.Done)).thenReturn("1"); - - } - - - @Test(expected=CloudRuntimeException.class) - public void testScaleVM1() throws Exception { - - - DeployDestination dest = new DeployDestination(null, null, null, _host); - long l = 1L; - - when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance); - _vmMgr.migrateForScale(_vmInstance.getUuid(), l, dest, l); - - } - - @Test (expected=CloudRuntimeException.class) - public void testScaleVM2() throws Exception { - - DeployDestination dest = new DeployDestination(null, null, null, _host); - long l = 1L; - - when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance); - ServiceOfferingVO newServiceOffering = getSvcoffering(512); - ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), - newServiceOffering.getSpeed(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse()); - Answer answer = new ScaleVmAnswer(reconfigureCmd, true, "details"); - when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null); - _vmMgr.reConfigureVm(_vmInstance, getSvcoffering(256), false); - - } - - @Test (expected=CloudRuntimeException.class) - public void testScaleVM3() throws Exception { - - /*VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm); - - Long srcHostId = vm.getHostId(); - Long oldSvcOfferingId = vm.getServiceOfferingId(); - if (srcHostId == null) { - throw new CloudRuntimeException("Unable to scale the vm because it doesn't have a host id"); - }*/ - - when(_vmInstance.getHostId()).thenReturn(null); - when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance); - _vmMgr.findHostAndMigrate(_vmInstance.getUuid(), 2l); - - } - - - private ServiceOfferingVO getSvcoffering(int ramSize){ - - long id = 4L; - String name = "name"; - String displayText = "displayText"; - int cpu = 1; - //int ramSize = 256; - int speed = 128; - - boolean ha = false; - boolean useLocalStorage = false; - - ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, useLocalStorage, false, null, false, null, false); - return serviceOffering; - } - - private void initializeMockConfigForMigratingVmWithVolumes() throws OperationTimedoutException, - ResourceUnavailableException { - - // Mock the source and destination hosts. - when(_srcHostMock.getId()).thenReturn(5L); - when(_destHostMock.getId()).thenReturn(6L); - when(_hostDao.findById(5L)).thenReturn(_srcHostMock); - when(_hostDao.findById(6L)).thenReturn(_destHostMock); - - // Mock the vm being migrated. - when(_vmMock.getId()).thenReturn(1L); - when(_vmMock.getHypervisorType()).thenReturn(HypervisorType.XenServer); - when(_vmMock.getState()).thenReturn(State.Running).thenReturn(State.Running).thenReturn(State.Migrating) - .thenReturn(State.Migrating); - when(_vmMock.getHostId()).thenReturn(5L); - when(_vmInstance.getId()).thenReturn(1L); - when(_vmInstance.getServiceOfferingId()).thenReturn(2L); - when(_vmInstance.getInstanceName()).thenReturn("myVm"); - when(_vmInstance.getHostId()).thenReturn(5L); - when(_vmInstance.getType()).thenReturn(VirtualMachine.Type.User); - when(_vmInstance.getState()).thenReturn(State.Running).thenReturn(State.Running).thenReturn(State.Migrating) - .thenReturn(State.Migrating); - - // Mock the work item. - when(_workDao.persist(any(ItWorkVO.class))).thenReturn(_work); - when(_workDao.update("1", _work)).thenReturn(true); - when(_work.getId()).thenReturn("1"); - doNothing().when(_work).setStep(ItWorkVO.Step.Done); - - // Mock the vm guru and the user vm object that gets returned. - _vmMgr._vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru>(); - UserVmManagerImpl userVmManager = mock(UserVmManagerImpl.class); - _vmMgr.registerGuru(VirtualMachine.Type.User, userVmManager); -// when(userVmManager.findById(anyLong())).thenReturn(_vmMock); - - // Mock the iteration over all the volumes of an instance. - Iterator<VolumeVO> volumeIterator = mock(Iterator.class); - when(_volsDao.findUsableVolumesForInstance(anyLong())).thenReturn(_rootVols); - when(_rootVols.iterator()).thenReturn(volumeIterator); - when(volumeIterator.hasNext()).thenReturn(true, false); - when(volumeIterator.next()).thenReturn(_volumeMock); - - // Mock the disk offering and pool objects for a volume. - when(_volumeMock.getDiskOfferingId()).thenReturn(5L); - when(_volumeMock.getPoolId()).thenReturn(200L); - when(_diskOfferingDao.findById(anyLong())).thenReturn(_diskOfferingMock); - when(_storagePoolDao.findById(anyLong())).thenReturn(_srcStoragePoolMock); - - // Mock the volume to pool mapping. - when(_volumeToPoolMock.get(_volumeMock)).thenReturn(_destStoragePoolMock); - when(_destStoragePoolMock.getId()).thenReturn(201L); - when(_srcStoragePoolMock.getId()).thenReturn(200L); - when(_destStoragePoolMock.isLocal()).thenReturn(false); - when(_diskOfferingMock.getUseLocalStorage()).thenReturn(false); - when(_poolHostDao.findByPoolHost(anyLong(), anyLong())).thenReturn(mock(StoragePoolHostVO.class)); - - // Mock hypervisor guru. - HypervisorGuru guruMock = mock(HypervisorGuru.class); - when(_hvGuruMgr.getGuru(HypervisorType.XenServer)).thenReturn(guruMock); - - when(_srcHostMock.getClusterId()).thenReturn(3L); - when(_destHostMock.getClusterId()).thenReturn(3L); - - // Mock the commands and answers to the agent. - PrepareForMigrationAnswer prepAnswerMock = mock(PrepareForMigrationAnswer.class); - when(prepAnswerMock.getResult()).thenReturn(true); - when(_agentMgr.send(anyLong(), isA(PrepareForMigrationCommand.class))).thenReturn(prepAnswerMock); - - MigrateWithStorageAnswer migAnswerMock = mock(MigrateWithStorageAnswer.class); - when(migAnswerMock.getResult()).thenReturn(true); - when(_agentMgr.send(anyLong(), isA(MigrateWithStorageCommand.class))).thenReturn(migAnswerMock); - - MigrateWithStorageReceiveAnswer migRecAnswerMock = mock(MigrateWithStorageReceiveAnswer.class); - when(migRecAnswerMock.getResult()).thenReturn(true); - when(_agentMgr.send(anyLong(), isA(MigrateWithStorageReceiveCommand.class))).thenReturn(migRecAnswerMock); - - MigrateWithStorageSendAnswer migSendAnswerMock = mock(MigrateWithStorageSendAnswer.class); - when(migSendAnswerMock.getResult()).thenReturn(true); - when(_agentMgr.send(anyLong(), isA(MigrateWithStorageSendCommand.class))).thenReturn(migSendAnswerMock); - - MigrateWithStorageCompleteAnswer migCompleteAnswerMock = mock(MigrateWithStorageCompleteAnswer.class); - when(migCompleteAnswerMock.getResult()).thenReturn(true); - when(_agentMgr.send(anyLong(), isA(MigrateWithStorageCompleteCommand.class))).thenReturn(migCompleteAnswerMock); - - CheckVirtualMachineAnswer checkVmAnswerMock = mock(CheckVirtualMachineAnswer.class); - when(checkVmAnswerMock.getResult()).thenReturn(true); - when(checkVmAnswerMock.getState()).thenReturn(PowerState.PowerOn); - when(_agentMgr.send(anyLong(), isA(CheckVirtualMachineCommand.class))).thenReturn(checkVmAnswerMock); - - // Mock the state transitions of vm. - Pair<Long, Long> opaqueMock = new Pair<Long, Long> (_vmMock.getHostId(), _destHostMock.getId()); - when(_vmSnapshotMgr.hasActiveVMSnapshotTasks(anyLong())).thenReturn(false); - when(_vmInstanceDao.updateState(State.Running, Event.MigrationRequested, State.Migrating, _vmMock, opaqueMock)) - .thenReturn(true); - when(_vmInstanceDao.updateState(State.Migrating, Event.OperationSucceeded, State.Running, _vmMock, opaqueMock)) - .thenReturn(true); - } - - // Check migration of a vm with its volumes within a cluster. - @Test - public void testMigrateWithVolumeWithinCluster() throws ResourceUnavailableException, ConcurrentOperationException, - ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException { - - initializeMockConfigForMigratingVmWithVolumes(); - when(_srcHostMock.getClusterId()).thenReturn(3L); - when(_destHostMock.getClusterId()).thenReturn(3L); - - _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock); - } - - // Check migration of a vm with its volumes across a cluster. - @Test - public void testMigrateWithVolumeAcrossCluster() throws ResourceUnavailableException, ConcurrentOperationException, - ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException { - - initializeMockConfigForMigratingVmWithVolumes(); - when(_srcHostMock.getClusterId()).thenReturn(3L); - when(_destHostMock.getClusterId()).thenReturn(4L); - - _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock); - } - - // Check migration of a vm fails when src and destination pool are not of same type; that is, one is shared and - // other is local. - @Test(expected=CloudRuntimeException.class) - public void testMigrateWithVolumeFail1() throws ResourceUnavailableException, ConcurrentOperationException, - ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException { - - initializeMockConfigForMigratingVmWithVolumes(); - when(_srcHostMock.getClusterId()).thenReturn(3L); - when(_destHostMock.getClusterId()).thenReturn(3L); - - when(_destStoragePoolMock.isLocal()).thenReturn(true); - when(_diskOfferingMock.getUseLocalStorage()).thenReturn(false); - - _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock); - } - - // Check migration of a vm fails when vm is not in Running state. - @Test(expected=ConcurrentOperationException.class) - public void testMigrateWithVolumeFail2() throws ResourceUnavailableException, ConcurrentOperationException, - ManagementServerException, VirtualMachineMigrationException, OperationTimedoutException { - - initializeMockConfigForMigratingVmWithVolumes(); - when(_srcHostMock.getClusterId()).thenReturn(3L); - when(_destHostMock.getClusterId()).thenReturn(3L); - - when(_vmMock.getState()).thenReturn(State.Stopped); - - _vmMgr.migrateWithStorage(_vmInstance.getUuid(), _srcHostMock.getId(), _destHostMock.getId(), _volumeToPoolMock); - } -}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aff0220d/server/test/com/cloud/vm/VmWorkTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/VmWorkTest.java b/server/test/com/cloud/vm/VmWorkTest.java deleted file mode 100644 index 4a6ccb8..0000000 --- a/server/test/com/cloud/vm/VmWorkTest.java +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.vm; - -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.inject.Inject; - -import junit.framework.TestCase; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.google.gson.Gson; - -import org.apache.cloudstack.framework.jobs.AsyncJobManager; -import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; -import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; -import org.apache.cloudstack.vm.jobs.VmWorkJobDao; -import org.apache.cloudstack.vm.jobs.VmWorkJobVO; -import org.apache.cloudstack.vm.jobs.VmWorkJobVO.Step; - -import com.cloud.api.ApiSerializerHelper; -import com.cloud.cluster.ClusterManager; -import com.cloud.deploy.DataCenterDeployment; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.deploy.DeploymentPlanner.ExcludeList; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientStorageCapacityException; -import com.cloud.utils.LogUtils; -import com.cloud.utils.Predicate; -import com.cloud.utils.component.ComponentContext; -import com.cloud.utils.db.Transaction; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="classpath:/VmWorkTestContext.xml") -public class VmWorkTest extends TestCase { - @Inject AsyncJobManager _jobMgr; - @Inject VirtualMachineManager _vmMgr; - @Inject ClusterManager _clusterMgr; - @Inject VmWorkJobDao _vmworkJobDao; - - Gson _gson = new Gson(); - - @Before - public void setup() { - LogUtils.initLog4j("log4j-vmops.xml"); - - ComponentContext.initComponentsLifeCycle(); - _vmMgr = Mockito.spy(_vmMgr); - Mockito.when(_clusterMgr.getManagementNodeId()).thenReturn(1L); - - Transaction.open("dummy"); - - // drop constraint check in order to do single table test - Statement stat = null; - try { - stat = Transaction.currentTxn().getConnection().createStatement(); - stat.execute("SET foreign_key_checks = 0;"); - } catch (SQLException e) { - } finally { - if(stat != null) { - try { - stat.close(); - } catch (SQLException e) { - } - } - } - } - - @Override - @After - public void tearDown() { - Transaction.currentTxn().close(); - } - - @Test - public void testDeployPlanSerialization() { - DeploymentPlan plan = new DataCenterDeployment(1L); - ExcludeList excludeList = new ExcludeList(); - - excludeList.addCluster(1); - plan.setAvoids(excludeList); - - String json = _gson.toJson(plan); - DeploymentPlan planClone = _gson.fromJson(json, DataCenterDeployment.class); - Assert.assertTrue(planClone.getDataCenterId() == plan.getDataCenterId()); - } - - @Test - public void testVmWorkStart() { - VmWorkStart work = new VmWorkStart(); - Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(); - params.put(VirtualMachineProfile.Param.HaTag, "HA"); - params.put(VirtualMachineProfile.Param.ControlNic, new Long(100)); - work.setParams(params); - - VmWorkStart workClone = _gson.fromJson(_gson.toJson(work), VmWorkStart.class); - Assert.assertTrue(work.getParams().size() == workClone.getParams().size()); - Assert.assertTrue(work.getParams().get(VirtualMachineProfile.Param.HaTag).equals(workClone.getParams().get(VirtualMachineProfile.Param.HaTag))); - } - - public void testVmWorkDispatcher() { - VmWorkJobVO workJob = new VmWorkJobVO(UUID.randomUUID().toString()); - workJob.setDispatcher("VmWorkJobDispatcher"); - workJob.setCmd("doVmWorkStart"); - workJob.setAccountId(1L); - workJob.setUserId(2L); - workJob.setStep(Step.Starting); - workJob.setVmType(VirtualMachine.Type.ConsoleProxy); - workJob.setVmInstanceId(1L); - - VmWorkStart workInfo = new VmWorkStart(); - workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo)); - - _jobMgr.submitAsyncJob(workJob, "VM", 1); - - _jobMgr.waitAndCheck(new String[] {"Done"}, 120000, 120000, new Predicate() { - - @Override - public boolean checkCondition() { - return true; - } - }); - } - - @Test - public void testVmWorkWakeup() { - AsyncJobVO mainJob = new AsyncJobVO(); - - mainJob.setDispatcher("TestApiJobDispatcher"); - mainJob.setAccountId(1L); - mainJob.setUserId(1L); - mainJob.setCmd("Dummy"); - mainJob.setCmdInfo("Dummy"); - - _jobMgr.submitAsyncJob(mainJob); - - try { - Thread.sleep(120000); - } catch (InterruptedException e) { - } - } - - @Test - public void testExceptionSerialization() { - InsufficientCapacityException exception = new InsufficientStorageCapacityException("foo", VmWorkJobVO.class, 1L); - - String encodedString = JobSerializerHelper.toObjectSerializedString(exception); - System.out.println(encodedString); - - exception = (InsufficientCapacityException)JobSerializerHelper.fromObjectSerializedString(encodedString); - Assert.assertTrue(exception.getScope() == VmWorkJobVO.class); - Assert.assertTrue(exception.getMessage().equals("foo")); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aff0220d/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java b/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java deleted file mode 100644 index 4e7d90c..0000000 --- a/server/test/com/cloud/vm/VmWorkTestApiJobDispatcher.java +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package com.cloud.vm; - -import java.sql.SQLException; -import java.sql.Statement; - -import javax.inject.Inject; - -import org.apache.cloudstack.framework.jobs.AsyncJob; -import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher; -import org.apache.cloudstack.framework.jobs.AsyncJobManager; -import org.apache.cloudstack.vm.jobs.VmWorkJobVO; - -import com.cloud.api.ApiSerializerHelper; -import com.cloud.async.AsyncJobExecutionContext; -import com.cloud.utils.component.AdapterBase; -import com.cloud.utils.db.Transaction; - -public class VmWorkTestApiJobDispatcher extends AdapterBase implements AsyncJobDispatcher { - - @Inject AsyncJobManager _jobMgr; - - @Override - public void runJob(AsyncJob job) { - - // drop constraint check in order to do single table test - Statement stat = null; - try { - stat = Transaction.currentTxn().getConnection().createStatement(); - stat.execute("SET foreign_key_checks = 0;"); - } catch (SQLException e) { - } finally { - if(stat != null) { - try { - stat.close(); - } catch (SQLException e) { - } - } - } - - VmWorkJobVO workJob = new VmWorkJobVO(job.getRelated()); - - workJob.setDispatcher("TestWorkJobDispatcher"); - workJob.setCmd(VmWorkJobDispatcher.Start); - - workJob.setAccountId(1L); - workJob.setUserId(1L); - workJob.setStep(VmWorkJobVO.Step.Starting); - workJob.setVmType(VirtualMachine.Type.ConsoleProxy); - workJob.setVmInstanceId(1L); - - // save work context info (there are some duplications) - VmWorkStart workInfo = new VmWorkStart(); - workInfo.setAccountId(1L); - workInfo.setUserId(1L); - workInfo.setVmId(1L); - workInfo.setPlan(null); - workInfo.setParams(null); - workJob.setCmdInfo(ApiSerializerHelper.toSerializedString(workInfo)); - - _jobMgr.submitAsyncJob(workJob, VmWorkJobDispatcher.VM_WORK_QUEUE, 1L); - - _jobMgr.joinJob(job.getId(), workJob.getId(), "processVmStartWakeup", - VmWorkJobDispatcher.VM_WORK_JOB_WAKEUP_DISPATCHER, - new String[] {}, - 3000, 120000); - AsyncJobExecutionContext.getCurrentExecutionContext().resetSyncSource(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aff0220d/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java index c766fa4..734d274 100755 --- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java +++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java @@ -480,24 +480,6 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu } /* (non-Javadoc) - * @see com.cloud.configuration.ConfigurationManager#csvTagsToList(java.lang.String) - */ - @Override - public List<String> csvTagsToList(String tags) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.configuration.ConfigurationManager#listToCsvTags(java.util.List) - */ - @Override - public String listToCsvTags(List<String> tags) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) * @see com.cloud.configuration.ConfigurationManager#checkZoneAccess(com.cloud.user.Account, com.cloud.dc.DataCenter) */ @Override
