티스토리 뷰
postId에 따른 comments 조회
아래 스크립트는 groovy로 작성되었습니다.
스크립트 설명
- GTest 타입 변수 4개 선언 -> test1, test2, test3, test4
- test(1~4) 각각에 매칭시킬 HttpRequest 타입 변수도 4개 선언 -> request1, request2, request3, request4
- BeforeProcess 프로세스가 실행되기 전 변수별 객체 생성
- 예시)
- test1 = new GTest(1, “127.0.0.1/post/1/comments”)
- request1 = new HTTPRequest()
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.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Date
import java.util.List
import java.util.ArrayList
import HTTPClient.Cookie
import HTTPClient.CookieModule
import HTTPClient.HTTPResponse
import HTTPClient.NVPair
/**
* A simple example using the HTTP plugin that shows the retrieval of a
* single page via HTTP.
*
* This script is automatically generated by ngrinder.
*
* @author admin
*/
@RunWith(GrinderRunner)
class TestRunner {
public static GTest test1
public static GTest test2
public static GTest test3
public static GTest test4
public static HTTPRequest request1
public static HTTPRequest request2
public static HTTPRequest request3
public static HTTPRequest request4
public static NVPair[] headers = []
public static NVPair[] params = []
public static Cookie[] cookies = []
@BeforeProcess
public static void beforeProcess() {
HTTPPluginControl.getConnectionDefaults().timeout = 6000
test1 = new GTest(1, "127.0.0.1/post/1/comments")
test2 = new GTest(2, "127.0.0.1/post/2/comments")
test3 = new GTest(3, "127.0.0.1/post/3/comments")
test4 = new GTest(4, "127.0.0.1/post/4/comments")
request1 = new HTTPRequest()
request2 = new HTTPRequest()
request3 = new HTTPRequest()
request4 = new HTTPRequest()
test1.record(request1)
test2.record(request2)
test3.record(request3)
test4.record(request4)
// grinder.logger.info("before process.");
}
@BeforeThread
public void beforeThread() {
test1.record(this, "test1")
test2.record(this, "test2")
test3.record(this, "test3")
test4.record(this, "test4")
grinder.statistics.delayReports=true;
grinder.logger.info("before thread.");
}
@Before
public void before() {
request1.setHeaders(headers)
request2.setHeaders(headers)
request3.setHeaders(headers)
request4.setHeaders(headers)
cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
grinder.logger.info("before thread. init headers and cookies");
}
@Test
public void test1(){
HTTPResponse result1 = request1.GET("http://127.0.0.1:8080/post/1/comments", params)
if (result1.statusCode == 301 || result1.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result1.statusCode);
} else {
assertThat(result1.statusCode, is(200));
}
}
@Test
public void test2(){
HTTPResponse result2 = request2.GET("http://127.0.0.1:8080/post/2/comments", params)
if (result2.statusCode == 301 || result2.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result2.statusCode);
} else {
assertThat(result2.statusCode, is(200));
}
}
@Test
public void test3(){
HTTPResponse result3 = request3.GET("http://127.0.0.1:8080/post/3/comments", params)
if (result3.statusCode == 301 || result3.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result3.statusCode);
} else {
assertThat(result3.statusCode, is(200));
}
}
@Test
public void test4(){
HTTPResponse result4 = request4.GET("http://127.0.0.1:8080/post/4/comments", params)
if (result4.statusCode == 301 || result4.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result4.statusCode);
} else {
assertThat(result4.statusCode, is(200));
}
}
}
무작위 요청을 확인하기 위해 찍어본 logger
nGrinder Test (Vuser: 296, 추가적인 부하는 주지 않았습니다.)
- case 1:
- case 2:
- case 3:
'Tool > nGrinder' 카테고리의 다른 글
nGrinder 설치 및 사용 (0) | 2018.05.12 |
---|
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- NoSQL
- output
- thread
- auth
- JWT
- 404
- iinput
- cors
- class
- ehcache
- ngrinder
- script
- URI
- https
- Token
- 대규모
- synchronized
- cross
- web
- Runnable
- MongoDB
- stateful
- Java
- Groovy
- Spring Boot
- SPOF
- stateless
- HTTP
- Cross Origin
- redis
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함