public class FaultServiceTest extends TestCase { /** * @param args * @throws FaultException * @throws ExpParamNotFoundException * @throws ParseException */ private IFaultService faultService; private static final int NUM_THREAD = 100; // 测试线程总数 public FaultServiceTest() { super(); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); } public FaultServiceTest(String name) { super(name); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); } // 高并发测试 public void testGetEquipEventAlertListByPage() throws Throwable { EquipmentQueryBean equipmentQueryBean = new EquipmentQueryBean(); // 生成所有测试线程 TestRunnable[] test = new TestRunnable[NUM_THREAD]; long start = System.currentTimeMillis(); for (int i = 0; i < test.length; i++) { test[i] = new FaultServiceThread(faultService, equipmentQueryBean); } // 生成测试线程运行器 MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(test); // 运行测试线程 mttr.runTestRunnables(); long used = System.currentTimeMillis() - start; System.out.printf("%s 调用花费 %s milli-seconds.\n", NUM_THREAD, used); } public static Test suite() { TestSuite test = new TestSuite("HealthService接口类测试"); test.addTest(new FaultServiceTest("testGetEquipEventAlertListByPage")); return test; } /* * 测试线程类定义 */ private static class FaultServiceThread extends TestRunnable { private IFaultService faultService; private EquipmentQueryBean equipmentQueryBean; public FaultServiceThread(IFaultService faultService, EquipmentQueryBean equipmentQueryBean) { super(); this.faultService = faultService; this.equipmentQueryBean = equipmentQueryBean; } @Override public void runTest() throws Throwable { faultService.getEquipEventAlertListByPage(equipmentQueryBean); } } } |