Some changes in performance tests
Change-Id: Ieeb2ec1bc3c771cfb0e511b400ab4e6b7666b9c0
This commit is contained in:
parent
82434f46a3
commit
ed217704f4
2 changed files with 10 additions and 9 deletions
|
@ -19,8 +19,7 @@ import java.util.concurrent.TimeUnit
|
|||
|
||||
class ServerMockPT extends Specification {
|
||||
|
||||
|
||||
@Timeout(value = 60)
|
||||
@Timeout(value = 90)
|
||||
def "should handle many request simultaneously"() {
|
||||
given:
|
||||
HttpClient client = HttpClients.createDefault()
|
||||
|
@ -28,7 +27,8 @@ class ServerMockPT extends Specification {
|
|||
RemoteMockServer controlServerClient = new RemoteMockServer("localhost", 9999)
|
||||
int requestAmount = 1000
|
||||
String[] responses = new String[requestAmount]
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(20)
|
||||
ExecutorService executorService = Executors.newCachedThreadPool()
|
||||
when:
|
||||
for (int i = 0; i < requestAmount; ++i) {
|
||||
int current = i
|
||||
executorService.submit {
|
||||
|
@ -45,14 +45,15 @@ class ServerMockPT extends Specification {
|
|||
restPost.entity = new StringEntity("<request$current/>", ContentType.create("text/xml", "UTF-8"))
|
||||
CloseableHttpResponse response = client.execute(restPost)
|
||||
responses[current] = Util.extractStringResponse(response)
|
||||
assert controlServerClient.removeMock("testRest$current", false).size() == 1
|
||||
controlServerClient.removeMock("testRest$current", true)
|
||||
}
|
||||
}
|
||||
when:
|
||||
executorService.awaitTermination(60, TimeUnit.SECONDS)
|
||||
executorService.shutdown()
|
||||
executorService.awaitTermination(90, TimeUnit.SECONDS)
|
||||
then:
|
||||
responses.eachWithIndex { res, i -> assert new XmlSlurper().parseText(res).name() == "goodResponse$i" as String }
|
||||
responses.eachWithIndex { res, i -> assert res && new XmlSlurper().parseText(res).name() == "goodResponse$i" as String }
|
||||
cleanup:
|
||||
executorService.shutdown()
|
||||
httpMockServer.stop()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ class ContextExecutor {
|
|||
|
||||
ContextExecutor(HttpServerWraper httpServerWraper, Mock initialMock) {
|
||||
this.httpServerWraper = httpServerWraper
|
||||
this.path = '/' + initialMock.path
|
||||
this.path = "/${initialMock.path}"
|
||||
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
||||
httpServerWraper.createContext(path) {
|
||||
HttpExchange ex ->
|
||||
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI)
|
||||
log.info("Mock received input")
|
||||
log.info('Mock received input')
|
||||
log.debug("Request: ${request.text}")
|
||||
for (Mock mock : mocks) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue