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;
@Test()
public void 领取任务() throws InterruptedException {
for (int i = 0; i <= 20; i++) {
new Thread(new Runnable() {
@Override
public void run() {
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);
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();
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 {
}
}
}
}
}).start();
System.out.println("初始化:" + i + "循环");
}
Thread.sleep(1000 * 60 * 30);
}
}
|