From 7ad0722b86d1b5aff6763cfe1f1cc263292ac18d Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Fri, 26 Apr 2013 13:09:19 -0700 Subject: [PATCH] Unit test to added method to AsyncJobManager --- api/src/com/cloud/async/AsyncJob.java | 31 ------------------- .../cloud/vm/VirtualMachineManagerImpl.java | 2 +- .../com/cloud/async/TestAsyncJobManager.java | 12 ++++--- 3 files changed, 8 insertions(+), 37 deletions(-) diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java index 44d7339e2fb..c8dc6422146 100644 --- a/api/src/com/cloud/async/AsyncJob.java +++ b/api/src/com/cloud/async/AsyncJob.java @@ -22,37 +22,6 @@ import org.apache.cloudstack.api.InternalIdentity; import java.util.Date; public interface AsyncJob extends Identity, InternalIdentity { -/* - public enum Type { - None, - VirtualMachine, - DomainRouter, - Volume, - ConsoleProxy, - Snapshot, - Template, - Iso, - SystemVm, - Host, - StoragePool, - IpAddress, - SecurityGroup, - PhysicalNetwork, - TrafficType, - PhysicalNetworkServiceProvider, - FirewallRule, - Account, - User, - PrivateGateway, - StaticRoute, - Counter, - Condition, - AutoScalePolicy, - AutoScaleVmProfile, - AutoScaleVmGroup, - GlobalLoadBalancerRule - } - */ Long getParentId(); String getType(); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 353a0245e11..a34e02c7185 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1433,7 +1433,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac HypervisorGuru hvGuru = _hvGuruMgr.getGuru(profile.getVirtualMachine().getHypervisorType()); VirtualMachineTO to = hvGuru.implement(profile); return to; - } + } protected void cancelWorkItems(long nodeId) { GlobalLock scanLock = GlobalLock.getInternLock("vmmgr.cancel.workitem"); diff --git a/server/test/com/cloud/async/TestAsyncJobManager.java b/server/test/com/cloud/async/TestAsyncJobManager.java index 1b23937a0d4..7a0840aa247 100644 --- a/server/test/com/cloud/async/TestAsyncJobManager.java +++ b/server/test/com/cloud/async/TestAsyncJobManager.java @@ -19,7 +19,8 @@ package com.cloud.async; import javax.inject.Inject; import junit.framework.TestCase; -import org.apache.log4j.Logger; +import org.apache.cloudstack.framework.messagebus.MessageBus; +import org.apache.cloudstack.framework.messagebus.PublishScope; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,20 +31,20 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.cloud.async.AsyncJobManager; import com.cloud.cluster.ClusterManager; +import com.cloud.utils.Predicate; import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.Transaction; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:/AsyncJobTestContext.xml") public class TestAsyncJobManager extends TestCase { - public static final Logger s_logger = Logger.getLogger(TestAsyncJobManager.class.getName()); @Inject AsyncJobManager asyncMgr; @Inject ClusterManager clusterMgr; @Inject MessageBus messageBus; @Before - public void setUp() { + public void setUp() { ComponentContext.initComponentsLifeCycle(); Mockito.when(clusterMgr.getManagementNodeId()).thenReturn(1L); @@ -65,15 +66,16 @@ public class TestAsyncJobManager extends TestCase { Thread.sleep(1000); } catch (InterruptedException e) { } + System.out.println("Publish wakeup message"); messageBus.publish(null, "VM", PublishScope.GLOBAL, null); } } }); thread.start(); - asyncMgr.waitAndCheck("VM", 5000, 10000, new Predicate() { + asyncMgr.waitAndCheck(new String[] {"VM"}, 5000L, 10000L, new Predicate() { public boolean checkCondition() { - s_logger.info("Check condition to exit"); + System.out.println("Check condition to exit"); return false; } });