当前位置: 首页 > 工具软件 > groovy-http > 使用案例 >

压测脚本---groovy---随机取值

云景焕
2023-12-01

import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.plugin.http.HTTPRequest
import net.grinder.plugin.http.HTTPPluginControl
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.AfterThread
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import HTTPClient.CookieModule
import HTTPClient.HTTPResponse
import org.slf4j.LoggerFactory

import ch.qos.logback.classic.Level
import com.alibaba.fastjson.JSONObject;
//import com.suning.sacs.service.api.Response
import java.util.HashMap;
import java.util.Map;
import HTTPClient.HTTPResponse
import com.suning.rsf.RSFException;
import com.suning.rsf.ServiceException;
import com.suning.rsf.consumer.Callback;

import java.io.File;
import com.suning.framework.scm.client.SCMClientImpl;

import com.alibaba.fastjson.JSON;
import **.consumer.ServiceAgent;
import *****.consumer.ServiceLocator;
//import ****.main.PassWordAuthReqInfo;
//import ****.main.RSAEncrypt;
//import ****.service.announcersf.RSFAnnouncementService
//import *****.service.ApiRemoteMapService;

import ********.service.ApiRemoteService;
import *******.consumer.ServiceLocator;
//import org.apache.commons.collections.MapUtils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.HashMap;
import java.util.Map;

@RunWith(GrinderRunner)
class TestRunner {
public static GTest action1
//public static HTTPRequest request
public ApiRemoteService service
public static int rowNumber
// public static int rowNumber2
public static ListlineList = new File("./resources/size.txt").readLines()
// public static ListlineList2
String picData=null;
public String testdata=null;

@BeforeProcess
public static void beforeProcess() {
	action1 = new GTest(1, "action1")
	grinder.logger.info("before process.");
}

@BeforeThread 
public void beforeThread() {
	action1.record(this, "action1")
	grinder.statistics.delayReports=true;
	grinder.logger.info("before thread.");
	service = ServiceLocator.getService("***.***.api.rsf.service.ApiRemoteService","***",false)
	LoggerFactory.getLogger("worker").setLevel(Level.INFO);
	System.setProperty("ldc", "NJXG_PST")
	
}

@Before
public void before() {
  Random r = new Random();
  int word = r.nextInt(lineList.size());
    picData = lineList.get(word)
	 testdata="{\"appId\":\"*****\",\"accessKey\":\"faf47c6f****7b998eb99\",\"recogReq\":{\"picType\":\"base64\",\"picData\":\"${picData}\"}}";

// sleep(3000)
}

@Test
public void action1() {
	 String json = service.execute(testdata) ;

// grinder.logger.info("=随机数是="+json);
if(json.contains("“msg”:“ok”")){
assertTrue(true)
System.out.println(“调用成功”);
grinder.logger.info(""+json);
}else{
grinder.logger.info("
"+json);
assertTrue(false);
}
}

@AfterThread
public void afterThread() {
}

}

 类似资料: