json 데이터를 post로 보내서 테스트하고 싶은 경우에 사용시..
from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from net.grinder.script.Grinder import grinder from HTTPClient import NVPair from java.util import Random, Date test1 = Test(1, "JSON POST TEST") requestGet = test1.wrap(HTTPRequest(url="http://1.1.1.1:1111")) logger = grinder.logger class TestRunner: def __init__(self): print "Init" def __call__(self): grinder.statistics.delayReports = 1 url = "/event" json="{\"result\" : [{ \"to\":[\"1111\"] }] }" result = requestGet.POST(url, json, ( NVPair('Content-Type', 'application/json'), )) grinder.sleep(1000) logger.output(str(result.statusCode)) if result.statusCode > 200 or result.text == "null": grinder.statistics.forLastTest.success = 0 else : grinder.statistics.forLastTest.success = 1 |
아래는 그냥 간단한 테스트 샘플
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from HTTPClient import NVPair
from net.grinder.script.Grinder import grinder
from java.util import Random, Date
test1 = Test(1, "test")
requestGet = test1.wrap(HTTPRequest(url="http://1.1.1.1"))
logger = grinder.logger
params = []
params.append("a=111&n=222")
params.append("a=222&n=222")
params.append("a=333&n=222")
params.append("a=444&n=222")
params.append("a=555&n=222")
class TestRunner:
def __init__(self):
print "Init"
def __call__(self):
random = Random()
randomInt = random.nextInt(len(params))
grinder.statistics.delayReports = 1
url = "/count?" + params[randomInt]
result = requestGet.GET(url)
grinder.sleep(1000)
if result.statusCode > 200 or result.text == "null":
grinder.statistics.forLastTest.success = 0
else :
grinder.statistics.forLastTest.success = 1