스 크 립 트 를 녹음 할 수 없 는 업무 압축 테스트

스트레스 테스트 를 할 때 스 크 립 트 를 녹음 할 수 없 는 경우 가 많 습 니 다. 예 를 들 어 인증 코드 를 입력 해 야 하 는 로그 인 기능 은 무 작위 로 생 성 된 인증 코드 를 녹음 할 수 없습니다. 서버 업무 예 코드 는 다음 과 같 습 니 다.
public class UserController extends Controller{
	/**
	 *     ,    http://localhost:8000/user/login
	 */
	public void login() {
		Map map = new HashMap();
		String name = this.getPara("name");//    
		String password = this.getPara("password");//  
		String code = this.getPara("code");  //    
		if(this.getSessionAttr("code").equals(code)){
			if(User.login(name, password) == true){
				map.put("msg", "    ");
			}
			else{
				map.put("msg", "        ");
			}
		}
		else{
			map.put("msg", "       ");
		}
		this.renderJson(JSONValue.toJSONString(map));
	}
}

테스트 인원 이 강하 지 않 은 경우 (녹화 할 수 없고 강력 한 식별 인증 코드 스 크 립 트 를 손 으로 작성 할 능력 도 없 음) 서버 측 에 압력 측정 방법 을 추가 하여 jmeter 를 사용 하여 압력 테스트 를 편리 하 게 할 수 있 습 니 다.
/**
	 *    :           ,
	 *   jmeter    http://localhost:8000/user/testLogin1
	 */
	public void testLogin1(){
		Random rand = new Random();
		String[][] user = {{"user1", "psw1"}, {"user2", "psw2"}};
		String[] u = user[rand.nextInt(10) / user.length];
		
		Map map = new HashMap();
		String name = u[0];//    
		String password = u[1];//  
		String code = this.getSessionAttr("code");  //    
		if(this.getSessionAttr("code").equals(code)){
			if(User.login(name, password) == true){
				map.put("msg", "    ");
			}
			else{
				map.put("msg", "        ");
			}
		}
		else{
			map.put("msg", "       ");
		}
		this.renderJson(JSONValue.toJSONString(map));
	}
/**
	 *      :             HTTP  
	 *   jmeter    http://localhost:8000/user/testLogin2
	 */
	public void testLogin2(){
		Random rand = new Random();
		String[][] user = {{"user1", "psw1"}, {"user2", "psw2"}};
		String[] u = user[rand.nextInt(10) / user.length];
		String code = "test";
		String body = "";
		try{
			Document doc = Jsoup.connect("http://localhost:8000/user/login")
			.data("name", u[0]).data("password", u[1]).data("code", code)
			.ignoreContentType(true).post();
			body = doc.body().text();
			System.out.println(body);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		this.renderText(body);
	}

복잡 한 업무, jmeter 나 loadrunner 도 스 크 립 트 를 녹음 하거나 복잡 한 스 크 립 트 를 작성 하지 않 아 도 스트레스 테스트 를 할 수 있 습 니 다. 다만 서버 개발 자 는 테스트 코드 를 하나 더 써 야 합 니 다.

좋은 웹페이지 즐겨찾기