栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

idea多线程性能测试

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

idea多线程性能测试

package testcase.msm.Performance;

import com.jayway.jsonpath.JsonPath;
import io.restassured.http.ContentType;
import org.testng.Assert;
import org.testng.annotations.Test;

import static io.restassured.RestAssured.given;


public class 领取任务 {

    static int times = 0;
    static int times_Max = 50000;

    //invocationCount = 50, threadPoolSize = 2
    @Test()
    public void 领取任务() throws InterruptedException {

// for 循环 i为线程数
        for (int i = 0; i <= 20; i++) {
            //实例化线程运行run的内容
            new Thread(new Runnable() {
                @Override
                public void run() {
//从当前时间开始一直持续运行true的内容
                    while (times < times_Max) {
                        //调用接口
                        String url = "http://msm.dev.eainc.com:8082/modelServiceManager/rest/modelAutoTreatTasks";
                        String json = "{n" +
                                "t"action": "claim",n" +
                                "t"variables": [n" +
                                "tt{n" +
                                "ttt"key": "modelServiceIp",n" +
                                "ttt"value": "172.16.6.99"n" +
                                "tt},n" +
                                "tt{n" +
                                "ttt"key": "processorCount",n" +
                                "ttt"value": "4"n" +
                                "tt},n" +
                                "tt{n" +
                                "ttt"key": "memorySize",n" +
                                "ttt"value": "8191"n" +
                                "tt},n" +
                                "tt{n" +
                                "ttt"key": "tag",n" +
                                "ttt"value": "amfFirst"n" +
                                "tt}n" +
                                "t]n" +
                                "}";
                        String response =
                                given()
                                        .when()
                                        .contentType(ContentType.JSON)
                                        .body(json)
                                        .put(url)
                                        .then()
                                        .statusCode(200)
                                        .extract().asString();
                        System.out.println(response);

                        //领取了第几个任务
                        times = times + 1;
                        System.out.println("第" + times + "任务" + "," + "返回参数:" + response);

                        //打印线程id
                        long tid = Thread.currentThread().getId();
                        System.out.println("tid:" + tid);


                        if (response == null || response.length() == 0 || response.equals("[]")) {
                            Assert.assertFalse(true, "没有领取到任务");

                        } else {
                            String paras = JsonPath.read(response, "$.[0].para").toString();
                            //String paras = "[]";
                            System.out.println(paras);
                            if (paras == null || paras.equals("") || paras.equals("[]")) {
                                System.out.println("para为空..................");
                                String taskId = JsonPath.read(response, "$.[0].taskId").toString();
                                System.out.println("para为空的taskId为: " + taskId);
                                Assert.assertFalse(true, "para为空");
                            } else {
                                //System.out.println("para不为空");
                            }
                        }

                    }

                }
            }).start();
            // 进入多少线程
            System.out.println("初始化:" + i + "循环");
        }
//设置睡眠时间的原因:test标签 有诸线程和子线程,主线程跑完就关闭了,下面的子线程也就无法运行了,所在在主线程跑完等待一段时间不关闭,让子线程继续运行
        Thread.sleep(1000 * 60 * 30);
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/693011.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号