mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
unit test for SG mgr v2
This commit is contained in:
parent
b52d1157e9
commit
7e2c2c627f
@ -8,11 +8,19 @@ import junit.framework.TestCase;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.agent.MockAgentManagerImpl;
|
import com.cloud.agent.MockAgentManagerImpl;
|
||||||
import com.cloud.configuration.DefaultInterceptorLibrary;
|
import com.cloud.configuration.DefaultInterceptorLibrary;
|
||||||
import com.cloud.configuration.dao.ConfigurationDaoImpl;
|
import com.cloud.configuration.dao.ConfigurationDaoImpl;
|
||||||
import com.cloud.domain.dao.DomainDaoImpl;
|
import com.cloud.domain.dao.DomainDaoImpl;
|
||||||
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.network.MockNetworkManagerImpl;
|
import com.cloud.network.MockNetworkManagerImpl;
|
||||||
import com.cloud.network.security.dao.IngressRuleDaoImpl;
|
import com.cloud.network.security.dao.IngressRuleDaoImpl;
|
||||||
import com.cloud.network.security.dao.SecurityGroupDaoImpl;
|
import com.cloud.network.security.dao.SecurityGroupDaoImpl;
|
||||||
@ -27,15 +35,20 @@ import com.cloud.utils.component.ComponentLocator;
|
|||||||
import com.cloud.utils.component.MockComponentLocator;
|
import com.cloud.utils.component.MockComponentLocator;
|
||||||
import com.cloud.vm.MockUserVmManagerImpl;
|
import com.cloud.vm.MockUserVmManagerImpl;
|
||||||
import com.cloud.vm.MockVirtualMachineManagerImpl;
|
import com.cloud.vm.MockVirtualMachineManagerImpl;
|
||||||
|
import com.cloud.vm.UserVmVO;
|
||||||
|
import com.cloud.vm.VirtualMachineName;
|
||||||
|
import com.cloud.vm.dao.UserVmDao;
|
||||||
import com.cloud.vm.dao.UserVmDaoImpl;
|
import com.cloud.vm.dao.UserVmDaoImpl;
|
||||||
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
import com.cloud.vm.dao.VMInstanceDaoImpl;
|
||||||
|
|
||||||
public class SecurityGroupManagerImpl2Test extends TestCase {
|
public class SecurityGroupManagerImpl2Test extends TestCase {
|
||||||
//private final static Logger s_logger = Logger.getLogger(SecurityGroupManagerImpl2Test.class);
|
//private final static Logger s_logger = Logger.getLogger(SecurityGroupManagerImpl2Test.class);
|
||||||
|
SecurityGroupManagerImpl2 _sgMgr = null;
|
||||||
|
UserVmDaoImpl _vmDao = null;
|
||||||
|
|
||||||
@Override
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
@Override
|
||||||
|
public void setUp() {
|
||||||
MockComponentLocator locator = new MockComponentLocator("management-server");
|
MockComponentLocator locator = new MockComponentLocator("management-server");
|
||||||
|
|
||||||
locator.addDao("ConfigurationDao", ConfigurationDaoImpl.class);
|
locator.addDao("ConfigurationDao", ConfigurationDaoImpl.class);
|
||||||
@ -57,6 +70,23 @@ public class SecurityGroupManagerImpl2Test extends TestCase {
|
|||||||
locator.addManager("NetworkManager", MockNetworkManagerImpl.class);
|
locator.addManager("NetworkManager", MockNetworkManagerImpl.class);
|
||||||
locator.addManager("AccountManager", MockAccountManagerImpl.class);
|
locator.addManager("AccountManager", MockAccountManagerImpl.class);
|
||||||
locator.makeActive(new DefaultInterceptorLibrary());
|
locator.makeActive(new DefaultInterceptorLibrary());
|
||||||
|
_sgMgr = ComponentLocator.inject(SecurityGroupManagerImpl2.class);
|
||||||
|
|
||||||
|
_vmDao = spy((UserVmDaoImpl)locator.getDao(UserVmDao.class));
|
||||||
|
when(_vmDao.findById(anyLong())).thenAnswer(new Answer<UserVmVO>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserVmVO answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Object[] args = invocation.getArguments();
|
||||||
|
Long vmId = (Long) args[0];
|
||||||
|
String vmName = VirtualMachineName.getVmName(vmId,3, "VM");
|
||||||
|
UserVmVO result = new UserVmVO(vmId, vmName, vmName, 1, HypervisorType.XenServer, 5, false, false, 1, 3, 1, null, vmName);
|
||||||
|
result.setHostId(vmId);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
AgentManager agentMgr = spy(locator.getManager(AgentManager.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,20 +94,28 @@ public class SecurityGroupManagerImpl2Test extends TestCase {
|
|||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSchedule() {
|
protected void _schedule(final int numVms) {
|
||||||
final int numVms = 10000;
|
|
||||||
System.out.println("Starting");
|
System.out.println("Starting");
|
||||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
|
||||||
SecurityGroupManagerImpl2 sgMgr = ComponentLocator.inject(SecurityGroupManagerImpl2.class);
|
|
||||||
List<Long> work = new ArrayList<Long>();
|
List<Long> work = new ArrayList<Long>();
|
||||||
for (long i=100; i <= numVms; i++) {
|
for (long i=100; i <= 100+numVms; i++) {
|
||||||
work.add(i);
|
work.add(i);
|
||||||
}
|
}
|
||||||
Profiler profiler = new Profiler();
|
Profiler profiler = new Profiler();
|
||||||
profiler.start();
|
profiler.start();
|
||||||
sgMgr.scheduleRulesetUpdateToHosts(work, false, null);
|
_sgMgr.scheduleRulesetUpdateToHosts(work, false, null);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
|
|
||||||
System.out.println("Done " + numVms + " in " + profiler.getDuration() + " ms");
|
System.out.println("Done " + numVms + " in " + profiler.getDuration() + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public void testSchedule() {
|
||||||
|
_schedule(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWork() {
|
||||||
|
_schedule(100);
|
||||||
|
_sgMgr.work();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user