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

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() {
}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值