Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코드스피츠
- 개미수열
- cache-control
- LastModified
- 알게뭐냐
- 워드프레스
- i18n
- 지뢰찾기
- Spring
- 지수반등
- brotli
- etag
- jsr380
- Kotlin
- jsr303
- kotliln
- 랜선아미안해
- 이렇게살아야되나자괴감이
- 리얼월드HTTP
- 클래스레벨밸리데이션
- 알고리즘
- 스프링
- cross parameter
- HTTP
- 브로틀리
Archives
- Today
- Total
취미개발 블로그와 마음수양
Ngrinder 관련 정리 본문
음 인생을 백엔드반 프론트반 짬뽕으로 살다가( -_ -) 아니.. 회사 일 하다보니 정신차리고보니 이런 포지션이더라. ㅋ
아무튼 그래도 뭐 .. NGrinder 같은 것들도 좀 봐야겠다 싶어서 정리..
내가 따로 글 쓸 것은 없고 이곳저곳에서 잘 모아봐야겠다.싶다.
https://nesoy.github.io/articles/2018-10/nGrinder-Start
nGrinder JSON 요청할때 참고할 만한 부분
https://www.cnblogs.com/lindows/p/9375306.html
https://blog.csdn.net/meyoung01/article/details/50435881
소스복붙 (혹시모르니)
import HTTPClient.HTTPResponse
import HTTPClient.NVPair
import ch.qos.logback.classic.Level
import net.grinder.plugin.http.HTTPPluginControl
import net.grinder.plugin.http.HTTPRequest
import net.grinder.script.GTest
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import org.junit.Test
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory
import static net.grinder.script.Grinder.grinder
import static org.hamcrest.Matchers.is
import static org.junit.Assert.assertThat
/**
* Created by nd-xm-mac5 on 15/12/24.
*/
@RunWith(GrinderRunner)
class LoginDemo {
public static GTest test
public static HTTPRequest request
@BeforeProcess
public static void beforeProcess() {
HTTPPluginControl.getConnectionDefaults().timeout = 6000
test = new GTest(1, "192.168.70.206")
request = new HTTPRequest()
test.record(request);
grinder.logger.info("before process.");
}
@BeforeThread
public void beforeThread() {
// 只打印错误的log
LoggerFactory.getLogger("worker").setLevel(Level.ERROR)
grinder.statistics.delayReports = true;
grinder.logger.info("before thread.");
}
private NVPair[] headers() {
return [
new NVPair("Content-type", "application/json;charset=UTF-8")
];
}
@Test
public void test1() {
// json字符串
def json = '{"tenant_code":"XXX","user_name":"XX","password":"X","skip_duplicate_entries":true,"type":"0"}';
// 发起请求
HTTPResponse result = request.POST("http://192.XXX.XX.XXX:XXXX/XXX/XX/login", json.getBytes(), headers());
grinder.logger.info(result.getText());
grinder.logger.info(result.getHeader("Content-type"));
if (result.statusCode == 301 || result.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
} else {
assertThat(result.statusCode, is(200));
}
}
파이썬
# -*- coding:utf-8 -*-
#
# 一个简单的HTTP请求脚本示例
#
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from net.grinder.plugin.http import HTTPPluginControl
from HTTPClient import NVPair
#导入对JSON格式返回值的处理函数
from org.json import JSONObject
control = HTTPPluginControl.getConnectionDefaults()
#请求重定向开关
# control.followRedirects = 1
#超时时间设置
control.timeout = 6000
test1 = Test(1, "Test1")
request1 = HTTPRequest()
# Make any method call on request1 increase TPS
test1.record(request1)
class TestRunner:
#初始化,仅执行一次
def __init__(self):
grinder.statistics.delayReports=True
pass
#类似LR的action,压测时会多次执行
# test method
def __call__(self):
#url地址
url = 'http://www.xxx.com/v0.93/login'
#headers信息
headers = [NVPair("Content-Type","application/json"),
NVPair("Authorization","123")
]
#JSON格式的请求内容
submitdata = '{"login_name":"156599@ND","password":"80fba977d063a6f7262a8a9c95f61140"}'
#URL请求
result = request1.POST(url,submitdata,headers)
#打印输出URL请求返回内容
#grinder.logger.info(result.getText())
#返回结果检查,有返回特定字符,则判断请求成功
if result.getText().find("检查内容") != -1 :
grinder.statistics.forLastTest.success = 1
else :
grinder.statistics.forLastTest.success = 0
#请求失败,则输出失败时服务器返回的值
grinder.logger.info(result.getText())