Commit the current changes to unit tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/9759ad57 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/9759ad57 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/9759ad57 Branch: refs/heads/javelin Commit: 9759ad57f2dd0f2e0147568affe353a870b9b221 Parents: 727fab7 Author: Alex Huang <[email protected]> Authored: Thu Jan 17 06:50:11 2013 -0800 Committer: Alex Huang <[email protected]> Committed: Thu Jan 17 06:50:11 2013 -0800 ---------------------------------------------------------------------- .../rest/service/api/ClusterRestService.java | 3 +- .../engine/rest/service/api/PodRestService.java | 3 +- .../engine/rest/service/api/ZoneRestService.java | 3 +- .../service/api/ProvisioningServiceImpl.java | 77 ++++++------- .../ws/jackson/CSJacksonAnnotationTest.java | 39 ++++--- pom.xml | 2 +- .../security/SecurityGroupManagerImpl2Test.java | 89 ++++----------- server/test/com/cloud/utils/db/GlobalLockTest.java | 75 ------------ utils/pom.xml | 8 +- utils/src/com/cloud/utils/db/GenericDaoBase.java | 10 +- utils/test/com/cloud/utils/QualifierTest.java | 37 ------ utils/test/com/cloud/utils/db/GlobalLockTest.java | 83 ++++++++++++++ .../utils/log/CglibThrowableRendererTest.java | 12 ++- 13 files changed, 186 insertions(+), 255 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java index 7c45c45..216cfa8 100755 --- a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ClusterRestService.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.engine.rest.service.api; import java.util.List; -import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -38,7 +37,7 @@ import org.springframework.stereotype.Service; @Service("ClusterRestService") @Produces("application/json") public class ClusterRestService { - @Inject +// @Inject ProvisioningService _provisioningService; @GET @Path("/clusters") http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java index d235f97..0811f0b 100755 --- a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/PodRestService.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.engine.rest.service.api; -import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; @@ -36,7 +35,7 @@ import org.springframework.stereotype.Service; @Service("PodService") @Produces({"application/json"}) public class PodRestService { - @Inject +// @Inject ProvisioningService _provisioningService; @GET @Path("/pod/{pod-id}") http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java index 318b153..7170f00 100755 --- a/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java +++ b/engine/api/src/org/apache/cloudstack/engine/rest/service/api/ZoneRestService.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.engine.rest.service.api; import java.util.List; -import javax.inject.Inject; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -39,7 +38,7 @@ import org.springframework.stereotype.Service; @Service("zoneService") @Produces({"application/json"}) public class ZoneRestService { - @Inject +// @Inject ProvisioningService _provisioningService; @GET @Path("/zones") http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java index f503530..83e78b4 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/service/api/ProvisioningServiceImpl.java @@ -22,15 +22,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; - import javax.inject.Inject; -import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.Produces; import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntityImpl; -import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceManager; import org.apache.cloudstack.engine.datacenter.entity.api.HostEntity; import org.apache.cloudstack.engine.datacenter.entity.api.HostEntityImpl; @@ -42,21 +38,20 @@ import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntityImpl; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; -import com.cloud.dc.Pod; import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.storage.StoragePool; - +@Component @Service("provisioningService") @Path("/provisioning") public class ProvisioningServiceImpl implements ProvisioningService { - @Inject - DataCenterResourceManager manager; - - @Override + @Inject + DataCenterResourceManager manager; + + @Override public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) { // TODO Auto-generated method stub return null; @@ -64,41 +59,41 @@ public class ProvisioningServiceImpl implements ProvisioningService { @Override public ZoneEntity registerZone(String zoneUuid, String name, String owner, List<String> tags, Map<String, String> details) { - ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid, manager); - zoneEntity.setName(name); - zoneEntity.setOwner(owner); - zoneEntity.setDetails(details); - zoneEntity.persist(); - return zoneEntity; + ZoneEntityImpl zoneEntity = new ZoneEntityImpl(zoneUuid, manager); + zoneEntity.setName(name); + zoneEntity.setOwner(owner); + zoneEntity.setDetails(details); + zoneEntity.persist(); + return zoneEntity; } @Override public PodEntity registerPod(String podUuid, String name, String owner, String zoneUuid, List<String> tags, Map<String, String> details) { - PodEntityImpl podEntity = new PodEntityImpl(podUuid, manager); - podEntity.setOwner(owner); - podEntity.setName(name); - podEntity.persist(); - return podEntity; + PodEntityImpl podEntity = new PodEntityImpl(podUuid, manager); + podEntity.setOwner(owner); + podEntity.setName(name); + podEntity.persist(); + return podEntity; } @Override public ClusterEntity registerCluster(String clusterUuid, String name, String owner, List<String> tags, Map<String, String> details) { - ClusterEntityImpl clusterEntity = new ClusterEntityImpl(clusterUuid, manager); - clusterEntity.setOwner(owner); - clusterEntity.setName(name); - clusterEntity.persist(); - return clusterEntity; + ClusterEntityImpl clusterEntity = new ClusterEntityImpl(clusterUuid, manager); + clusterEntity.setOwner(owner); + clusterEntity.setName(name); + clusterEntity.persist(); + return clusterEntity; } @Override public HostEntity registerHost(String hostUuid, String name, String owner, List<String> tags, Map<String, String> details) { - HostEntityImpl hostEntity = new HostEntityImpl(hostUuid, manager); - hostEntity.setOwner(owner); - hostEntity.setName(name); - hostEntity.setDetails(details); - - hostEntity.persist(); - return hostEntity; + HostEntityImpl hostEntity = new HostEntityImpl(hostUuid, manager); + hostEntity.setOwner(owner); + hostEntity.setName(name); + hostEntity.setDetails(details); + + hostEntity.persist(); + return hostEntity; } @Override @@ -109,27 +104,27 @@ public class ProvisioningServiceImpl implements ProvisioningService { @Override public void deregisterZone(String uuid) { - ZoneEntityImpl zoneEntity = new ZoneEntityImpl(uuid, manager); - zoneEntity.disable(); + ZoneEntityImpl zoneEntity = new ZoneEntityImpl(uuid, manager); + zoneEntity.disable(); } @Override public void deregisterPod(String uuid) { - PodEntityImpl podEntity = new PodEntityImpl(uuid, manager); - podEntity.disable(); + PodEntityImpl podEntity = new PodEntityImpl(uuid, manager); + podEntity.disable(); } @Override public void deregisterCluster(String uuid) { - ClusterEntityImpl clusterEntity = new ClusterEntityImpl(uuid, manager); - clusterEntity.disable(); + ClusterEntityImpl clusterEntity = new ClusterEntityImpl(uuid, manager); + clusterEntity.disable(); } @Override public void deregisterHost(String uuid) { - HostEntityImpl hostEntity = new HostEntityImpl(uuid, manager); - hostEntity.disable(); + HostEntityImpl hostEntity = new HostEntityImpl(uuid, manager); + hostEntity.disable(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/framework/rest/test/org/apache/cloudstack/framework/ws/jackson/CSJacksonAnnotationTest.java ---------------------------------------------------------------------- diff --git a/framework/rest/test/org/apache/cloudstack/framework/ws/jackson/CSJacksonAnnotationTest.java b/framework/rest/test/org/apache/cloudstack/framework/ws/jackson/CSJacksonAnnotationTest.java index fef6ba2..8869b21 100644 --- a/framework/rest/test/org/apache/cloudstack/framework/ws/jackson/CSJacksonAnnotationTest.java +++ b/framework/rest/test/org/apache/cloudstack/framework/ws/jackson/CSJacksonAnnotationTest.java @@ -16,24 +16,25 @@ // under the License. package org.apache.cloudstack.framework.ws.jackson; -import java.io.IOException; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.Priority; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.Priority; public class CSJacksonAnnotationTest { @@ -41,7 +42,7 @@ public class CSJacksonAnnotationTest { public void setUp() throws Exception { } - @Test + @Test @Ignore public void test() { ObjectMapper mapper = new ObjectMapper(); JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4b5e3cf..ffb039b 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ </issueManagement> <properties> - <skipTests>true</skipTests> + <!-- <skipTests>true</skipTests--> <cs.jdk.version>1.6</cs.jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java b/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java index 723e4e6..f0576eb 100644 --- a/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java +++ b/server/test/com/cloud/network/security/SecurityGroupManagerImpl2Test.java @@ -25,97 +25,52 @@ import javax.naming.ConfigurationException; import junit.framework.TestCase; import org.junit.After; -import org.junit.Before; import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.cloud.agent.MockAgentManagerImpl; -import com.cloud.api.query.dao.SecurityGroupJoinDaoImpl; -import com.cloud.configuration.DefaultInterceptorLibrary; -import com.cloud.configuration.dao.ConfigurationDaoImpl; -import com.cloud.domain.dao.DomainDaoImpl; -import com.cloud.event.dao.UsageEventDaoImpl; -import com.cloud.network.MockNetworkManagerImpl; -import com.cloud.network.security.dao.SecurityGroupDaoImpl; -import com.cloud.network.security.dao.SecurityGroupRuleDaoImpl; -import com.cloud.network.security.dao.SecurityGroupRulesDaoImpl; -import com.cloud.network.security.dao.SecurityGroupVMMapDaoImpl; -import com.cloud.network.security.dao.SecurityGroupWorkDaoImpl; -import com.cloud.network.security.dao.VmRulesetLogDaoImpl; -import com.cloud.projects.MockProjectManagerImpl; -import com.cloud.tags.dao.ResourceTagsDaoImpl; -import com.cloud.user.MockAccountManagerImpl; -import com.cloud.user.MockDomainManagerImpl; -import com.cloud.user.dao.AccountDaoImpl; import com.cloud.utils.Profiler; - -import com.cloud.vm.MockUserVmManagerImpl; -import com.cloud.vm.MockVirtualMachineManagerImpl; import com.cloud.vm.dao.UserVmDaoImpl; -import com.cloud.vm.dao.VMInstanceDaoImpl; +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "classpath:/testContext.xml") public class SecurityGroupManagerImpl2Test extends TestCase { - //private final static Logger s_logger = Logger.getLogger(SecurityGroupManagerImpl2Test.class); - @Inject SecurityGroupManagerImpl2 _sgMgr = null; - @Inject UserVmDaoImpl _vmDao = null; - - @Before - @Override - public void setUp() { -/* - locator.addDao("ConfigurationDao", ConfigurationDaoImpl.class); - locator.addDao("SecurityGroupDao", SecurityGroupDaoImpl.class); - - locator.addDao("SecurityGroupRuleDao", SecurityGroupRuleDaoImpl.class); - locator.addDao("SecurityGroupJoinDao", SecurityGroupJoinDaoImpl.class); - locator.addDao("SecurityGroupVMMapDao", SecurityGroupVMMapDaoImpl.class); - locator.addDao("SecurityGroupRulesDao", SecurityGroupRulesDaoImpl.class); - locator.addDao("UserVmDao", UserVmDaoImpl.class); - locator.addDao("AccountDao", AccountDaoImpl.class); - locator.addDao("ConfigurationDao", ConfigurationDaoImpl.class); - locator.addDao("SecurityGroupWorkDao", SecurityGroupWorkDaoImpl.class); - locator.addDao("VmRulesetLogDao", VmRulesetLogDaoImpl.class); - locator.addDao("VMInstanceDao", VMInstanceDaoImpl.class); - locator.addDao("DomainDao", DomainDaoImpl.class); - locator.addDao("UsageEventDao", UsageEventDaoImpl.class); - locator.addDao("ResourceTagDao", ResourceTagsDaoImpl.class); - locator.addManager("AgentManager", MockAgentManagerImpl.class); - locator.addManager("VirtualMachineManager", MockVirtualMachineManagerImpl.class); - locator.addManager("UserVmManager", MockUserVmManagerImpl.class); - locator.addManager("NetworkManager", MockNetworkManagerImpl.class); - locator.addManager("AccountManager", MockAccountManagerImpl.class); - locator.addManager("DomainManager", MockDomainManagerImpl.class); - locator.addManager("ProjectManager", MockProjectManagerImpl.class); - locator.makeActive(new DefaultInterceptorLibrary()); -*/ - } - + @Inject + SecurityGroupManagerImpl2 _sgMgr = null; + @Inject + UserVmDaoImpl _vmDao = null; + @Override @After public void tearDown() throws Exception { } - + protected void _schedule(final int numVms) { System.out.println("Starting"); List<Long> work = new ArrayList<Long>(); - for (long i=100; i <= 100+numVms; i++) { + for (long i = 100; i <= 100 + numVms; i++) { work.add(i); } Profiler profiler = new Profiler(); profiler.start(); _sgMgr.scheduleRulesetUpdateToHosts(work, false, null); profiler.stop(); - - System.out.println("Done " + numVms + " in " + profiler.getDuration() + " ms"); + + System.out.println("Done " + numVms + " in " + profiler.getDuration() + + " ms"); } - + @Ignore public void testSchedule() throws ConfigurationException { _schedule(1000); } - + + @Test public void testWork() throws ConfigurationException { - _schedule(1000); - _sgMgr.work(); - + _schedule(1000); + _sgMgr.work(); + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/server/test/com/cloud/utils/db/GlobalLockTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/utils/db/GlobalLockTest.java b/server/test/com/cloud/utils/db/GlobalLockTest.java deleted file mode 100644 index e0e2b94..0000000 --- a/server/test/com/cloud/utils/db/GlobalLockTest.java +++ /dev/null @@ -1,75 +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.utils.db; - -import org.apache.log4j.Logger; - -import junit.framework.Assert; - -import com.cloud.utils.Profiler; -import com.cloud.utils.testcase.Log4jEnabledTestCase; - -public class GlobalLockTest extends Log4jEnabledTestCase{ - public static final Logger s_logger = Logger.getLogger(GlobalLockTest.class); - private final static GlobalLock _workLock = GlobalLock.getInternLock("SecurityGroupWork"); - public static class Worker implements Runnable { - int id = 0; - int timeoutSeconds = 10; - int jobDuration = 2; - public Worker(int id, int timeout, int duration) { - this.id = id; - timeoutSeconds = timeout; - jobDuration = duration; - } - public void run() { - boolean locked = false; - try { - Profiler p = new Profiler(); - p.start(); - locked = _workLock.lock(timeoutSeconds); - p.stop(); - System.out.println("Thread " + id + " waited " + p.getDuration() + " ms, locked=" + locked); - if (locked) { - Thread.sleep(jobDuration*1000); - } - } catch (InterruptedException e) { - } finally { - if (locked) { - boolean unlocked = _workLock.unlock(); - System.out.println("Thread " + id + " unlocked=" + unlocked); - } - } - } - } - - public void testTimeout() { - Thread [] pool = new Thread[50]; - for (int i=0; i < pool.length; i++) { - pool[i] = new Thread(new Worker(i, 5, 3)); - } - for (int i=0; i < pool.length; i++) { - pool[i].start(); - } - for (int i=0; i < pool.length; i++) { - try { - pool[i].join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/utils/pom.xml ---------------------------------------------------------------------- diff --git a/utils/pom.xml b/utils/pom.xml index 213ad38..c52f09a 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -159,12 +159,18 @@ <testSourceDirectory>test</testSourceDirectory> <testResources> <testResource> + <directory>${project.basedir}/test/resources</directory> + </testResource> + </testResources> + <!-- + <testResources> + <testResource> <directory>test/resources</directory> </testResource> <testResource> <directory>conf</directory> </testResource> - </testResources> + </testResources> --> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/utils/src/com/cloud/utils/db/GenericDaoBase.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index 880e9de..2ca1fe4 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -176,7 +176,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene return builder; } - public final Map<String, Attribute> getAllAttributes() { + public Map<String, Attribute> getAllAttributes() { return _allAttributes; } @@ -1222,7 +1222,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene public List<T> search(final SearchCriteria<T> sc, final Filter filter) { return search(sc, filter, null, false); } - + @Override @DB(txn=false) public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter) { List<T> objects = search(sc, filter, null, false); @@ -1832,14 +1832,14 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene if (joins != null) { i = addJoinAttributes(i, pstmt, joins); } - + /* if (groupByValues != null) { for (Object value : groupByValues) { pstmt.setObject(i++, value); } } - */ + */ final ResultSet rs = pstmt.executeQuery(); while (rs.next()) { @@ -1863,5 +1863,5 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene return sql; } - + } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/utils/test/com/cloud/utils/QualifierTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/QualifierTest.java b/utils/test/com/cloud/utils/QualifierTest.java deleted file mode 100644 index 8d758a5..0000000 --- a/utils/test/com/cloud/utils/QualifierTest.java +++ /dev/null @@ -1,37 +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 -// 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.utils; - -import javax.inject.Inject; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="classpath:/com/cloud/utils/QualifierTestContext.xml") -public class QualifierTest { - - @Inject - DummyInterface _dummy; - - @Test - public void test() { - _dummy.foo(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/utils/test/com/cloud/utils/db/GlobalLockTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/db/GlobalLockTest.java b/utils/test/com/cloud/utils/db/GlobalLockTest.java new file mode 100644 index 0000000..01e1e33 --- /dev/null +++ b/utils/test/com/cloud/utils/db/GlobalLockTest.java @@ -0,0 +1,83 @@ +// 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.utils.db; + +import org.apache.log4j.Logger; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import junit.framework.Assert; + +import com.cloud.utils.Profiler; +import com.cloud.utils.testcase.Log4jEnabledTestCase; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="classpath:/testContext.xml") +public class GlobalLockTest { + public static final Logger s_logger = Logger.getLogger(GlobalLockTest.class); + private final static GlobalLock _workLock = GlobalLock.getInternLock("SecurityGroupWork"); + public static class Worker implements Runnable { + int id = 0; + int timeoutSeconds = 10; + int jobDuration = 2; + public Worker(int id, int timeout, int duration) { + this.id = id; + timeoutSeconds = timeout; + jobDuration = duration; + } + public void run() { + boolean locked = false; + try { + Profiler p = new Profiler(); + p.start(); + locked = _workLock.lock(timeoutSeconds); + p.stop(); + System.out.println("Thread " + id + " waited " + p.getDuration() + " ms, locked=" + locked); + if (locked) { + Thread.sleep(jobDuration*1000); + } + } catch (InterruptedException e) { + } finally { + if (locked) { + boolean unlocked = _workLock.unlock(); + System.out.println("Thread " + id + " unlocked=" + unlocked); + } + } + } + } + + @Test + public void testTimeout() { + Thread [] pool = new Thread[50]; + for (int i=0; i < pool.length; i++) { + pool[i] = new Thread(new Worker(i, 5, 3)); + } + for (int i=0; i < pool.length; i++) { + pool[i].start(); + } + for (int i=0; i < pool.length; i++) { + try { + pool[i].join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/9759ad57/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java ---------------------------------------------------------------------- diff --git a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java index 59926f8..2a05a00 100644 --- a/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java +++ b/utils/test/com/cloud/utils/log/CglibThrowableRendererTest.java @@ -25,16 +25,21 @@ import com.cloud.utils.db.DB; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.log4j.spi.RootLogger; import org.apache.log4j.spi.ThrowableRenderer; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.CharArrayWriter; import java.io.Writer; - +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="classpath:/testContext.xml") public class CglibThrowableRendererTest extends TestCase { static Logger another = Logger.getLogger("TEST"); private final static Logger s_logger = Logger.getLogger(CglibThrowableRendererTest.class); - public static class Test { + public static class TestClass { @DB public void exception1() { throw new IllegalArgumentException("What a bad exception"); @@ -66,11 +71,12 @@ public class CglibThrowableRendererTest extends TestCase { return alternateRoot; } + @Test public void testException() { Writer w = new CharArrayWriter(); Logger alt = getAlternateLogger(w, null); - Test test = ComponentContext.inject(Test.class); + TestClass test = ComponentContext.inject(TestClass.class); try { test.exception(); } catch (Exception e) {
