You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/11 00:29:22 UTC
[1/7] more files changed
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 2897a63..95dc9a6 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -71,7 +71,6 @@ import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.alert.AlertManager;
import com.cloud.capacity.CapacityManager;
import com.cloud.cluster.ClusterManager;
-import com.cloud.cluster.StackMaid;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
@@ -238,7 +237,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
@Inject
protected ConfigurationDao _configDao;
-
+
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
@@ -288,7 +287,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating nics for " + vm);
}
-
+
try {
_networkMgr.allocate(vmProfile, networks);
} catch (ConcurrentOperationException e) {
@@ -673,7 +672,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
continue;
}
-
+
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
if (!pool.isInMaintenance()) {
if (s_logger.isDebugEnabled()) {
@@ -707,7 +706,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
}
}
-
+
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, account, params);
DeployDestination dest = null;
for (DeploymentPlanner planner : _planners) {
@@ -757,7 +756,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if(!reuseVolume){
reuseVolume = true;
}
-
+
Commands cmds = null;
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);
@@ -776,10 +775,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
_workDao.updateStep(work, Step.Starting);
_agentMgr.send(destHostId, cmds);
-
+
_workDao.updateStep(work, Step.Started);
-
-
+
+
StartAnswer startAnswer = cmds.getAnswer(StartAnswer.class);
if (startAnswer != null && startAnswer.getResult()) {
String host_guid = startAnswer.getHost_guid();
@@ -803,7 +802,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if (s_logger.isDebugEnabled()) {
s_logger.info("The guru did not like the answers so stopping " + vm);
}
-
+
StopCommand cmd = new StopCommand(vm.getInstanceName());
StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
if (answer == null || !answer.getResult()) {
@@ -815,7 +814,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
}
s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails()));
-
+
} catch (OperationTimedoutException e) {
s_logger.debug("Unable to send the start command to host " + dest.getHost());
if (e.isActive()) {
@@ -1071,7 +1070,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
vmGuru.prepareStop(profile);
-
+
StopCommand stop = new StopCommand(vm, vm.getInstanceName(), null);
boolean stopped = false;
StopAnswer answer = null;
@@ -1560,13 +1559,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
boolean isMachineUpgradable = true;
for(HostAllocator allocator : _hostAllocators) {
- isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
- if(isMachineUpgradable)
- continue;
- else
- break;
+ isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
+ if(isMachineUpgradable)
+ continue;
+ else
+ break;
}
-
+
return isMachineUpgradable;
}
@@ -1644,7 +1643,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
commands.addCommand(command);
}
}
-
+
for (final AgentVmInfo left : infos.values()) {
boolean found = false;
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
@@ -1740,7 +1739,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public void fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
- if (newStates==null)return;
+ if (newStates==null)return;
Map<Long, AgentVmInfo> infos = convertToInfos(newStates);
Set<VMInstanceVO> set_vms = Collections.synchronizedSet(new HashSet<VMInstanceVO>());
set_vms.addAll(_vmDao.listByClusterId(clusterId));
@@ -1750,11 +1749,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
AgentVmInfo info = infos.remove(vm.getId());
VMInstanceVO castedVm = null;
if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting))
- || (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
+ || (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
{
- s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
+ s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
-
+
// Bug 13850- grab outstanding work item if any for this VM state so that we mark it as DONE after we change VM state, else it will remain pending
ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState());
if (work != null) {
@@ -1763,8 +1762,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
}
vm.setState(State.Running); // set it as running and let HA take care of it
- _vmDao.persist(vm);
-
+ _vmDao.persist(vm);
+
if (work != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Updating outstanding work item to Done, id:" + work.getId());
@@ -1772,7 +1771,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
work.setStep(Step.Done);
_workDao.update(work.getId(), work);
}
-
+
castedVm = info.guru.findById(vm.getId());
try {
Host host = _hostDao.findByGuid(info.getHostUuid());
@@ -1812,20 +1811,20 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
}
else
- // host id can change
- if (info != null && vm.getState() == State.Running){
- // check for host id changes
- Host host = _hostDao.findByGuid(info.getHostUuid());
- if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
- s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
- try {
- stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
- } catch (NoTransitionException e) {
- s_logger.warn(e.getMessage());
- }
- }
- }
- /* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
+ // host id can change
+ if (info != null && vm.getState() == State.Running){
+ // check for host id changes
+ Host host = _hostDao.findByGuid(info.getHostUuid());
+ if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
+ s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
+ try {
+ stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
+ } catch (NoTransitionException e) {
+ s_logger.warn(e.getMessage());
+ }
+ }
+ }
+ /* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
s_logger.warn("Marking the VM as Stopped as it was still stopping on the CS" +vm.getName());
vm.setState(State.Stopped); // Setting the VM as stopped on the DB and clearing it from the host
vm.setLastHostId(vm.getHostId());
@@ -1863,7 +1862,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
boolean is_alien_vm = true;
long alien_vm_count = -1;
for (Map.Entry<String, Pair<String, State>> entry : newStates.entrySet()) {
- is_alien_vm = true;
+ is_alien_vm = true;
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : vmGurus) {
String name = entry.getKey();
VMInstanceVO vm = vmGuru.findByName(name);
@@ -1881,8 +1880,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
// alien VMs
if (is_alien_vm){
- map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
- s_logger.warn("Found an alien VM " + entry.getKey());
+ map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
+ s_logger.warn("Found an alien VM " + entry.getKey());
}
}
return map;
@@ -2267,13 +2266,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
Long clusterId = agent.getClusterId();
long agentId = agent.getId();
if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen
- StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
- HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
- if (allStates != null){
- this.fullSync(clusterId, allStates);
- }
-
- // initiate the cron job
+ StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
+ HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
+ if (allStates != null){
+ this.fullSync(clusterId, allStates);
+ }
+
+ // initiate the cron job
ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), clusterId);
try {
long seq_no = _agentMgr.send(agentId, new Commands(syncCmd), this);
@@ -2340,7 +2339,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
} catch (Exception e) {
s_logger.warn("Caught the following exception on transition checking", e);
} finally {
- StackMaid.current().exitCleanup();
lock.unlock();
}
}
@@ -2375,7 +2373,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public VMInstanceVO findById(long vmId) {
return _vmDao.findById(vmId);
}
-
+
@Override
public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId) {
ServiceOfferingVO newServiceOffering = _offeringDao.findById(newServiceOfferingId);
@@ -2387,7 +2385,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if (!vmInstance.getState().equals(State.Stopped)) {
s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState());
throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " +
- "in state " + vmInstance.getState()
+ "in state " + vmInstance.getState()
+ "; make sure the virtual machine is stopped and not in an error state before upgrading.");
}
@@ -2395,11 +2393,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if (vmInstance.getServiceOfferingId() == newServiceOffering.getId()) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " +
- "service offering (" + newServiceOffering.getName() + ")");
+ "service offering (" + newServiceOffering.getName() + ")");
}
throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " +
- "has the requested service offering (" + newServiceOffering.getName() + ")");
+ "has the requested service offering (" + newServiceOffering.getName() + ")");
}
ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
@@ -2421,7 +2419,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
"useLocalStorage=" + currentServiceOffering.getUseLocalStorage()
+ ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage());
}
-
+
// if vm is a system vm, check if it is a system service offering, if yes return with error as it cannot be used for user vms
if (currentServiceOffering.getSystemUse() != newServiceOffering.getSystemUse()) {
throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering");
@@ -2430,7 +2428,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
// Check that there are enough resources to upgrade the service offering
if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) {
throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " +
- "for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
+ "for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
+ newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory");
}
@@ -2439,12 +2437,12 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
if (!newTags.containsAll(currentTags)) {
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " +
- "does not have all the tags of the "
+ "does not have all the tags of the "
+ "current service offering. Current service offering tags: " + currentTags + "; " + "new service " +
- "offering tags: " + newTags);
+ "offering tags: " + newTags);
}
}
-
+
@Override
public boolean upgradeVmDb(long vmId, long serviceOfferingId) {
VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
@@ -2455,38 +2453,38 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
return _vmDao.update(vmId, vmForUpdate);
}
-
+
@Override
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
- ResourceUnavailableException, InsufficientCapacityException {
-
+ ResourceUnavailableException, InsufficientCapacityException {
+
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
-
+
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
null, null, null);
-
+
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
-
+
//check vm state
if (vm.getState() == State.Running) {
//1) allocate and prepare nic
NicProfile nic = _networkMgr.createNicForVm(network, requested, context, vmProfile, true);
-
+
//2) Convert vmProfile to vmTO
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
-
+
//3) Convert nicProfile to NicTO
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
-
+
//4) plug the nic to the vm
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
-
+
s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
@@ -2509,40 +2507,40 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
@Override
public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) {
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(hypervisorType);
-
+
NicTO nicTO = hvGuru.toNicTO(nic);
return nicTO;
}
-
+
@Override
public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
-
+
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
null, null, null);
-
+
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
-
+
Nic nic = null;
-
+
if (broadcastUri != null) {
nic = _nicsDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.toString());
} else {
nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
}
-
+
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
_networkMgr.getNetworkRate(network.getId(), vm.getId()),
_networkMgr.isSecurityGroupSupportedInNetwork(network),
_networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
-
+
//1) Unplug the nic
NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
@@ -2553,14 +2551,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
return false;
}
-
+
//2) Release the nic
_networkMgr.releaseNic(vmProfile, nic);
s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
-
+
//3) Remove the nic
_networkMgr.removeNic(vmProfile, nic);
return result;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/fac22702/server/test/com/cloud/async/TestAsync.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/async/TestAsync.java b/server/test/com/cloud/async/TestAsync.java
index 187f2e5..6f67fe2 100644
--- a/server/test/com/cloud/async/TestAsync.java
+++ b/server/test/com/cloud/async/TestAsync.java
@@ -19,18 +19,13 @@ package com.cloud.async;
import java.util.List;
-import org.apache.log4j.Logger;
-
import junit.framework.Assert;
-import com.cloud.async.AsyncJobVO;
-import com.cloud.cluster.StackMaid;
+import org.apache.log4j.Logger;
+
import com.cloud.cluster.CheckPointVO;
import com.cloud.cluster.dao.StackMaidDao;
import com.cloud.cluster.dao.StackMaidDaoImpl;
-import com.cloud.serializer.Param;
-import com.cloud.utils.ActionDelegate;
-import com.cloud.utils.Pair;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.testcase.Log4jEnabledTestCase;
@@ -42,15 +37,15 @@ public class TestAsync extends Log4jEnabledTestCase {
public static class SampleAsyncResult {
@Param(name="name", propName="name")
private final String _name;
-
+
@Param
private final int count;
-
+
public SampleAsyncResult(String name, int count) {
_name = name;
this.count = count;
}
-
+
public String getName() { return _name; }
public int getCount() { return count; }
}
@@ -60,31 +55,31 @@ public class TestAsync extends Log4jEnabledTestCase {
AsyncJobVO job = new AsyncJobVO(1, 1, "TestCmd", null);
job.setInstanceType("user_vm");
job.setInstanceId(1000L);
-
+
char[] buf = new char[1024];
for(int i = 0; i < 1024; i++)
buf[i] = 'a';
-
+
job.setResult(new String(buf));
dao.persist(job);
-
+
AsyncJobVO jobVerify = dao.findById(job.getId());
-
+
Assert.assertTrue(jobVerify.getCmd().equals(job.getCmd()));
Assert.assertTrue(jobVerify.getUserId() == 1);
Assert.assertTrue(jobVerify.getAccountId() == 1);
-
+
String result = jobVerify.getResult();
for(int i = 0; i < 1024; i++)
Assert.assertTrue(result.charAt(i) == 'a');
-
+
jobVerify = dao.findInstancePendingAsyncJob("user_vm", 1000L);
Assert.assertTrue(jobVerify != null);
Assert.assertTrue(jobVerify.getCmd().equals(job.getCmd()));
Assert.assertTrue(jobVerify.getUserId() == 1);
Assert.assertTrue(jobVerify.getAccountId() == 1);
}
-
+
public void testSerialization() {
List<Pair<String, Object>> l;
int value = 1;
@@ -93,23 +88,23 @@ public class TestAsync extends Log4jEnabledTestCase {
Assert.assertTrue(l.get(0).first().equals("result"));
Assert.assertTrue(l.get(0).second().equals("1"));
l.clear();
-
+
SampleAsyncResult result = new SampleAsyncResult("vmops", 1);
l = SerializerHelper.toPairList(result, "result");
-
+
Assert.assertTrue(l.size() == 2);
Assert.assertTrue(l.get(0).first().equals("name"));
Assert.assertTrue(l.get(0).second().equals("vmops"));
Assert.assertTrue(l.get(1).first().equals("count"));
Assert.assertTrue(l.get(1).second().equals("1"));
}
-
+
public void testAsyncResult() {
AsyncJobResult result = new AsyncJobResult(1);
-
+
result.setResultObject(100);
Assert.assertTrue(result.getResult().equals("java.lang.Integer/100"));
-
+
Object obj = result.getResultObject();
Assert.assertTrue(obj instanceof Integer);
Assert.assertTrue(((Integer)obj).intValue() == 100);
@@ -119,7 +114,7 @@ public class TestAsync extends Log4jEnabledTestCase {
Transaction txn = Transaction.open("testTransaction");
try {
txn.start();
-
+
AsyncJobDao dao = new AsyncJobDaoImpl();
AsyncJobVO job = new AsyncJobVO(1, 1, "TestCmd", null);
job.setInstanceType("user_vm");
@@ -131,11 +126,11 @@ public class TestAsync extends Log4jEnabledTestCase {
txn.close();
}
}
-
+
public void testMorevingian() {
int threadCount = 10;
final int testCount = 10;
-
+
Thread[] threads = new Thread[threadCount];
for(int i = 0; i < threadCount; i++) {
final int threadNum = i + 1;
@@ -145,35 +140,35 @@ public class TestAsync extends Log4jEnabledTestCase {
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
AsyncJobDao dao = new AsyncJobDaoImpl();
-
+
s_logger.info("Thread " + threadNum + " acquiring lock");
AsyncJobVO job = dao.acquire(1L, 30);
if(job != null) {
s_logger.info("Thread " + threadNum + " acquired lock");
-
+
try {
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 3000));
} catch (InterruptedException e) {
}
-
+
s_logger.info("Thread " + threadNum + " acquiring lock nestly");
AsyncJobVO job2 = dao.acquire(1L, 30);
if(job2 != null) {
s_logger.info("Thread " + threadNum + " acquired lock nestly");
-
+
try {
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 3000));
} catch (InterruptedException e) {
}
-
+
s_logger.info("Thread " + threadNum + " releasing lock (nestly acquired)");
dao.release(1L);
s_logger.info("Thread " + threadNum + " released lock (nestly acquired)");
-
+
} else {
s_logger.info("Thread " + threadNum + " was unable to acquire lock nestly");
}
-
+
s_logger.info("Thread " + threadNum + " releasing lock");
dao.release(1L);
s_logger.info("Thread " + threadNum + " released lock");
@@ -183,7 +178,7 @@ public class TestAsync extends Log4jEnabledTestCase {
} finally {
txn.close();
}
-
+
try {
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 10000));
} catch (InterruptedException e) {
@@ -192,11 +187,11 @@ public class TestAsync extends Log4jEnabledTestCase {
}
});
}
-
+
for(int i = 0; i < threadCount; i++) {
threads[i].start();
}
-
+
for(int i = 0; i < threadCount; i++) {
try {
threads[i].join();
@@ -204,88 +199,83 @@ public class TestAsync extends Log4jEnabledTestCase {
}
}
}
- */
-
- public void testMaid() {
- Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-
- StackMaidDao dao = new StackMaidDaoImpl();
- dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
- dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
- dao.pushCleanupDelegate(1L, 2, "delegate3", null);
-
- CheckPointVO item = dao.popCleanupDelegate(1L);
- Assert.assertTrue(item.getDelegate().equals("delegate3"));
- Assert.assertTrue(item.getContext() == null);
-
- item = dao.popCleanupDelegate(1L);
- Assert.assertTrue(item.getDelegate().equals("delegate2"));
- s_logger.info(item.getContext());
-
- item = dao.popCleanupDelegate(1L);
- Assert.assertTrue(item.getDelegate().equals("delegate1"));
- s_logger.info(item.getContext());
-
- txn.close();
- }
-
- public void testMaidClear() {
- Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-
- StackMaidDao dao = new StackMaidDaoImpl();
- dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
- dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
- dao.pushCleanupDelegate(1L, 2, "delegate3", null);
-
- dao.clearStack(1L);
- Assert.assertTrue(dao.popCleanupDelegate(1L) == null);
- txn.close();
- }
-
- public void testMaidExitCleanup() {
- StackMaid.current().push(1L, "com.cloud.async.CleanupDelegate", "Hello, world1");
- StackMaid.current().push(1L, "com.cloud.async.CleanupDelegate", "Hello, world2");
-
- StackMaid.current().exitCleanup(1L);
- }
-
- public void testMaidLeftovers() {
+ */
- Thread[] threads = new Thread[3];
- for(int i = 0; i < 3; i++) {
- final int threadNum = i+1;
- threads[i] = new Thread(new Runnable() {
- public void run() {
- Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-
- StackMaidDao dao = new StackMaidDaoImpl();
- dao.pushCleanupDelegate(1L, 0, "delegate-" + threadNum, "Hello, world");
- dao.pushCleanupDelegate(1L, 1, "delegate-" + threadNum, new Long(100));
- dao.pushCleanupDelegate(1L, 2, "delegate-" + threadNum, null);
-
- txn.close();
- }
- });
-
- threads[i].start();
- }
-
- for(int i = 0; i < 3; i++) {
- try {
- threads[i].join();
- } catch (InterruptedException e) {
- }
- }
+ public void testMaid() {
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-
- Transaction txn = Transaction.open(Transaction.CLOUD_DB);
-
- StackMaidDao dao = new StackMaidDaoImpl();
- List<CheckPointVO> l = dao.listLeftoversByMsid(1L);
- for(CheckPointVO maid : l) {
- s_logger.info("" + maid.getThreadId() + " " + maid.getDelegate() + " " + maid.getContext());
- }
-
- txn.close();
- }
+ StackMaidDao dao = new StackMaidDaoImpl();
+ dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
+ dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
+ dao.pushCleanupDelegate(1L, 2, "delegate3", null);
+
+ CheckPointVO item = dao.popCleanupDelegate(1L);
+ Assert.assertTrue(item.getDelegate().equals("delegate3"));
+ Assert.assertTrue(item.getContext() == null);
+
+ item = dao.popCleanupDelegate(1L);
+ Assert.assertTrue(item.getDelegate().equals("delegate2"));
+ s_logger.info(item.getContext());
+
+ item = dao.popCleanupDelegate(1L);
+ Assert.assertTrue(item.getDelegate().equals("delegate1"));
+ s_logger.info(item.getContext());
+
+ txn.close();
+ }
+
+ public void testMaidClear() {
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+
+ StackMaidDao dao = new StackMaidDaoImpl();
+ dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
+ dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
+ dao.pushCleanupDelegate(1L, 2, "delegate3", null);
+
+ dao.clearStack(1L);
+ Assert.assertTrue(dao.popCleanupDelegate(1L) == null);
+ txn.close();
+ }
+
+
+ public void testMaidLeftovers() {
+
+ Thread[] threads = new Thread[3];
+ for(int i = 0; i < 3; i++) {
+ final int threadNum = i+1;
+ threads[i] = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+
+ StackMaidDao dao = new StackMaidDaoImpl();
+ dao.pushCleanupDelegate(1L, 0, "delegate-" + threadNum, "Hello, world");
+ dao.pushCleanupDelegate(1L, 1, "delegate-" + threadNum, new Long(100));
+ dao.pushCleanupDelegate(1L, 2, "delegate-" + threadNum, null);
+
+ txn.close();
+ }
+ });
+
+ threads[i].start();
+ }
+
+ for(int i = 0; i < 3; i++) {
+ try {
+ threads[i].join();
+ } catch (InterruptedException e) {
+ }
+ }
+
+
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+
+ StackMaidDao dao = new StackMaidDaoImpl();
+ List<CheckPointVO> l = dao.listLeftoversByMsid(1L);
+ for(CheckPointVO maid : l) {
+ s_logger.info("" + maid.getThreadId() + " " + maid.getDelegate() + " " + maid.getContext());
+ }
+
+ txn.close();
+ }
}