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;

/**
 * @author xinhuo
 * @date 2021/12/24 9:13
 * @Description ${创建任务后,领取任务,领取任务的时候只领取到taskId,没有领取到para内容失败}
 */
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" +
                                "\t\t{\n" +
                                "\t\t\t\"key\": \"modelServiceIp\",\n" +
                                "\t\t\t\"value\": \"172.16.6.99\"\n" +
                                "\t\t},\n" +
                                "\t\t{\n" +
                                "\t\t\t\"key\": \"processorCount\",\n" +
                                "\t\t\t\"value\": \"4\"\n" +
                                "\t\t},\n" +
                                "\t\t{\n" +
                                "\t\t\t\"key\": \"memorySize\",\n" +
                                "\t\t\t\"value\": \"8191\"\n" +
                                "\t\t},\n" +
                                "\t\t{\n" +
                                "\t\t\t\"key\": \"tag\",\n" +
                                "\t\t\t\"value\": \"amfFirst\"\n" +
                                "\t\t}\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);
    }
}

更多内容请关注微信公众号:耿门文楼
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值