This repository has been archived by the owner on Dec 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
nGrinder 스크립트 (조회)
Min Kuk Jo edited this page May 1, 2018
·
1 revision
- 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));
}
}
}
- case 1:
- case 2:
- case 3: