<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qileilove

    blog已經轉移至github,大家請訪問 http://qaseven.github.io/

    多線程測試工具groboutils的使用

     一直使用junit做為服務測試框架,感覺不錯。最近有人反映在高并發的情況下,存在服務調不到。無奈再次打開單元測試模擬高并發的情況,卻發現junit不支持并發測試
      引入groboutils jar包,其實我主要使用MultiThreadedTestRunner類和TestRunnable類。
      原有的junit框架不做改變,導入GroboTestingJUnit-1.2.1-core.jar包
      代碼如下
    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);
    }
    }

     運行代碼,并發數開到100個后觀察運行時間發現運行運行時間到了12秒了,看來問題出在DAO。需要進行sql代碼優化了
      導入的測試包有:
    import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
    import net.sourceforge.groboutils.junit.v1.TestRunnable;
    import junit.framework.Test;
    import junit.framework.TestCase;
    import junit.framework.TestSuite;

    posted on 2013-11-13 10:19 順其自然EVO 閱讀(440) 評論(0)  編輯  收藏 所屬分類: jmeter and badboy

    <2013年11月>
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    1234567

    導航

    統計

    常用鏈接

    留言簿(55)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 无码免费一区二区三区免费播放| 亚洲免费无码在线| 亚洲中文字幕日本无线码| 亚洲国产无线乱码在线观看| 老司机精品视频免费| 久久久久成人精品免费播放动漫| 亚洲色欲色欲www在线丝| 亚洲人成免费电影| 色多多免费视频观看区一区| 国产成人精品免费视频软件| 亚洲国产一区国产亚洲| 国产大陆亚洲精品国产| 亚洲黄色免费在线观看| 亚洲欧洲自拍拍偷午夜色无码| 国产午夜无码片免费| 日本免费网站在线观看| 亚洲理论精品午夜电影| 国内精品免费久久影院| 免费中文字幕在线观看| 亚洲熟伦熟女专区hd高清| 日韩av无码久久精品免费| 亚洲色婷婷综合开心网| 亚洲欧美国产日韩av野草社区| 无码国产精品一区二区免费3p| 91情国产l精品国产亚洲区| 99在线热播精品免费99热| 亚洲美免无码中文字幕在线| 91精品成人免费国产片| 亚洲国产女人aaa毛片在线| 成年黄网站色大免费全看| 亚洲av日韩综合一区在线观看| 免费人成大片在线观看播放电影| 手机在线免费视频| 亚洲国产成人久久精品app| 国产精品成人无码免费| 暖暖在线视频免费视频| a级亚洲片精品久久久久久久| 男人扒开添女人下部免费视频| 亚洲gv白嫩小受在线观看| 97在线视频免费公开视频| 亚洲人成免费网站|