일단 나는 kotlin을 사용중인데, Groovy가 뭔지 모르는 사람임..
부하 테스트를 하기 위해서 Groovy 스크립트로 작성되어야 한다는데 무슨말인지 몰라서 한참을 찾았다.
nGrinder에서 kotlin을 직접 실행을 지원하지 않는다.
코틀린 코드로 테스트를 하기 위해선 Groovy 스크립트를 사용해야한다. (ㅅㅂ)
스크립트를 작성하기 위해서는
1. 테스트 할 해당 서비스의 엔드포인트를 알아야한다.
2. 스크립트를 작성한다 (어캐씀?)
3. 스크립트를 검증 후 실행한다....
이 스크립트가 자바코드로 되어있어서 아직 나는 자바코드를 작성하는법을 모르기 때문에..
지피티에게 내 테스트코드를 변환해달라고 맡겼다.
분명 코틀린을 배우고 있는데, 자바 코드를 더 많이보는 것 같다.. 빨리 자바 공부해야지..
import net.grinder.plugin.http.HTTPRequest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.script.GTest
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import net.grinder.scriptengine.groovy.junit.annotation.Test
import org.junit.runner.RunWith
import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
@RunWith(GrinderRunner)
class CouponServiceTest {
public static GTest test
public static HTTPRequest request
@BeforeProcess
public static void beforeProcess() {
test = new GTest(1, "CouponService Test")
request = new HTTPRequest()
grinder.logger.info("beforeProcess.")
}
@BeforeThread
public void beforeThread() {
grinder.statistics.delayReports=true
}
@Test
public void testCreateCoupon() {
def httpResponse = request.POST("http://your-service-domain/coupons",
"application/json",
'{"couponId": 20, "type": "dd", "amount": 5, "userId": 1}',
[headers: ["Content-Type":"application/json"]])
assert httpResponse.statusCode == 200
}
}
변환 해 준 스크립트이다. 엔드포인트 부분만 수정해서 검증시켰는데, 에러가 발생했다.
2024-03-24 01:52:44,797 INFO Setting of nGrinder local DNS successfully
2024-03-24 01:52:44,798 INFO The Grinder version 3.9.1
2024-03-24 01:52:44,799 INFO Java(TM) SE Runtime Environment 17.0.10+11-LTS-240: Java HotSpot(TM) 64-Bit Server VM (17.0.10+11-LTS-240, mixed mode, sharing) on Mac OS X aarch64 14.3.1
2024-03-24 01:52:44,807 INFO time zone is KST (+0900)
2024-03-24 01:52:44,828 INFO worker process 0 of agent number 0
2024-03-24 01:52:44,832 INFO Instrumentation agents: byte code transforming instrumenter for Java
2024-03-24 01:52:45,110 ERROR Script error - Error while initialize test runner
net.grinder.engine.common.EngineException: Error while initialize test runner
at net.grinder.scriptengine.groovy.GroovyScriptEngine.<init>(GroovyScriptEngine.java:71)
at net.grinder.scriptengine.groovy.GroovyScriptEngineService.createScriptEngine(GroovyScriptEngineService.java:87)
at net.grinder.engine.process.ScriptEngineContainer.getScriptEngine(ScriptEngineContainer.java:105)
at net.grinder.engine.process.GrinderProcess.run(GrinderProcess.java:345)
at net.grinder.engine.process.WorkerProcessEntryPoint.run(WorkerProcessEntryPoint.java:87)
at net.grinder.engine.process.WorkerProcessEntryPoint.main(WorkerProcessEntryPoint.java:60)
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Unsupported class file major version 61
지금 내가 사용하고 있는 JDK는 17버전인데, nGrinder의 Groovy 컴파일러가 17버전을 지원하지 않는다고 한다.
그래서 JDK를 11버전으로 다운그레이드 해야하는데,,
jdk 11버전이 안깔려 있으므로 설치해준다.
https://www.azul.com/downloads/?package=jdk#download-openjdk
[Azul Downloads
No matter the size of your company, Azul offers competitive pricing options to fit your needs, your budget, and your ambition.
www.azul.com](https://www.azul.com/downloads/?package=jdk#download-openjdk)
m3니까 arm으로 설치하면 된다
환경변수에 세팅하기 위해서 경로복사를 한다.
난 zsh를 사용하기 때문에 .zshrc 파일에 환경변수를 설정해야한다.
터미널에서 vim ~/.zshrc 명령어를 실행한다.
i를 누르고
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
두가지를 추가 후 ESC 를 눌러 :wq로 저장
source ~/.zshrc
변경사항을 저장하는 명령어 실행하면 JDK 버전이 변경된다.
진짜 설정하는데 너무 오래걸렸다. 꼭 까먹지말길;;
JDK 버전을 변경했으니 nGrinder를 재실행시켜준다.
스크립트 검증
2024-03-24 03:24:19,677 INFO Setting of nGrinder local DNS successfully
2024-03-24 03:24:19,679 INFO The Grinder version 3.9.1
2024-03-24 03:24:19,680 INFO OpenJDK Runtime Environment 11.0.22+7-LTS: OpenJDK 64-Bit Server VM (11.0.22+7-LTS, mixed mode) on Mac OS X aarch64 14.3.1
2024-03-24 03:24:19,690 INFO time zone is KST (+0900)
2024-03-24 03:24:19,710 INFO worker process 0 of agent number 0
2024-03-24 03:24:19,722 INFO Instrumentation agents: byte code transforming instrumenter for Java
2024-03-24 03:24:20,200 INFO registered plug-in net.grinder.plugin.http.HTTPPlugin
2024-03-24 03:24:20,220 INFO beforeProcess.
2024-03-24 03:24:20,221 INFO Running "test-createCoupon.groovy" using GroovyScriptEngine running with groovy version: 3.0.5
2024-03-24 03:24:20,232 INFO starting, will do 1 run
2024-03-24 03:24:20,232 INFO Start time is 1711218260232 ms since Epoch
2024-03-24 03:24:20,238 ERROR No signature of method: org.ngrinder.http.HTTPRequest.POST() is applicable for argument types: (String, String, String, LinkedHashMap) values: [http://localhost:8080/coupons/creates, application/json, {"couponId": 20, "type": "dd", "amount": 5, "userId": 1}, ...]
Possible solutions: POST(java.lang.String, [B, java.util.List), POST(java.lang.String, java.util.List, java.util.List), POST(java.lang.String, java.util.Map, java.util.List), POST(java.lang.String, org.apache.hc.core5.http.nio.AsyncEntityProducer, java.util.List), wait(), dump()
groovy.lang.MissingMethodException: No signature of method: org.ngrinder.http.HTTPRequest.POST() is applicable for argument types: (String, String, String, LinkedHashMap) values: [http://localhost:8080/coupons/creates, application/json, {"couponId": 20, "type": "dd", "amount": 5, "userId": 1}, ...]
Possible solutions: POST(java.lang.String, [B, java.util.List), POST(java.lang.String, java.util.List, java.util.List), POST(java.lang.String, java.util.Map, java.util.List), POST(java.lang.String, org.apache.hc.core5.http.nio.AsyncEntityProducer, java.util.List), wait(), dump()
at CouponServiceTest.testCreateCoupon(test-createCoupon.groovy:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at net.grinder.scriptengine.groovy.junit.GrinderRunner.run(GrinderRunner.java:164)
at net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyWorkerRunnable.run(GroovyScriptEngine.java:147)
at net.grinder.engine.process.GrinderThread.run(GrinderThread.java:118)
2024-03-24 03:24:20,239 INFO finished 1 run
2024-03-24 03:24:20,239 INFO elapsed time is 7 ms
2024-03-24 03:24:20,239 INFO Final statistics for this process:
2024-03-24 03:24:20,241 INFO
Tests Errors Mean Test Test Time TPS Mean Response Response Mean time to Mean time to Mean time to
Time (ms) Standard response bytes per errors resolve host establish first byte
Deviation length second connection
(ms)
Totals 0 0 NaN 0.00 0.00 NaN 0.00 0 NaN NaN NaN
Tests resulting in error only contribute to the Errors column.
Statistics for individual tests can be found in the data file, including
(possibly incomplete) statistics for erroneous tests. Composite tests
are marked with () and not included in the totals.
2024-03-24 03:24:20,222 INFO validation-0: Starting threads
2024-03-24 03:24:20,241 INFO validation-0: Finished
스크립트를 검증하니 JDK에 대한 에러는 사라졌으나 http 요청 메서드에서 오류가 발생했다.
그냥 지피티한테 맡기지말고 내가 써야될듯 하다.
테스트 스크립트를 작성하는법을 모르니 어떤부분에서 문제가 생긴지도 파악이 안되는 상황이다.
내일 차근차근 작성해봐야할듯
'Setting' 카테고리의 다른 글
nGrinder 설정하기 (1) | 2024.03.24 |
---|