OkayBase base = getBase(i)
UserCenter userCenter = new UserCenter(base)
userCenter.modifyPwd()
ThreadBase threadBase = new ThreadBase() {
@Override
protected void before() {
}
@Override
protected void doing() throws Exception {
userCenter.modifyPwd()
}
@Override
protected void after() {
}
}
threadBase.setTimes(times)
threads.add(threadBase)
}
new Concurrent(threads).start()
allOver()
}
}
main方法留了两个参数表示线程数和单线程请求数,下面是usercenter的主要代码。
public class UserCenter extends OkayBase {
private static Logger logger = LoggerFactory.getLogger(UserCenter.class);
public UserCenter(OkayBase okayBase) {
super(okayBase);
}
public JSONObject modifyPwd() {
String url = UserApi.MODIFY_PWD;
JSONObject params = getParams();
params.put("newpwd", getPassword(this.getUname()));
params.put("oldpwd", getPassword(this.getPwd()));
JSONObject response = getPostResponse(url, params);
output(response);
if (isRight(response)) {
String string = response.getJSONObject("data").getString("token");
this.setToken(string);
}
return response;
}
}
下面是okaybase的主要代码:
public class OkayBase extends SourceCode implements IBase {
private static Logger logger = LoggerFactory.getLogger(OkayBase.class);
int uid;
String token;
String uname;
String pwd;
public OkayBase(String uname, String pwd) {
this.uname = uname;
this.pwd = pwd;
login();
}
public String getPassword() {
String s = uname.substring(uname.length() - 6);
return getPassword(s);
}
public String getPassword(String pwd) {
return RSAUtils.getPassword(pwd);
}
public JSONObject getParams() {
JSONObject json = getJson("uid=" + uid, "token=" + token);
json.put("imei", "isFake");
json.put("serial", "W170500652");
json.put("ua", "f_an_4..0");
return json;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getUid() {
return uid;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getUname() {
return uname;
}
@Override
public boolean isRight(JSONObject jsonObject) {
int code = TEST_ERROR_CODE;
try {
code = jsonObject.getJSONObject("meta").getInt("ecode");
JSONObject data = jsonObject.getJSONObject("data");
return code == 0 && !data.isEmpty();
} catch (Exception e) {
return false;
}
}
/**
* 测试结束,资源释放
*/
public static void allOver() {
FanLibrary.testOver();
}
}