Some changes in performance tests

Change-Id: Ieeb2ec1bc3c771cfb0e511b400ab4e6b7666b9c0
This commit is contained in:
Dominik Adam Przybysz 2015-08-29 15:44:16 +02:00
parent 82434f46a3
commit ed217704f4
2 changed files with 10 additions and 9 deletions

View file

@ -19,8 +19,7 @@ import java.util.concurrent.TimeUnit
class ServerMockPT extends Specification { class ServerMockPT extends Specification {
@Timeout(value = 90)
@Timeout(value = 60)
def "should handle many request simultaneously"() { def "should handle many request simultaneously"() {
given: given:
HttpClient client = HttpClients.createDefault() HttpClient client = HttpClients.createDefault()
@ -28,7 +27,8 @@ class ServerMockPT extends Specification {
RemoteMockServer controlServerClient = new RemoteMockServer("localhost", 9999) RemoteMockServer controlServerClient = new RemoteMockServer("localhost", 9999)
int requestAmount = 1000 int requestAmount = 1000
String[] responses = new String[requestAmount] String[] responses = new String[requestAmount]
ExecutorService executorService = Executors.newFixedThreadPool(20) ExecutorService executorService = Executors.newCachedThreadPool()
when:
for (int i = 0; i < requestAmount; ++i) { for (int i = 0; i < requestAmount; ++i) {
int current = i int current = i
executorService.submit { executorService.submit {
@ -45,14 +45,15 @@ class ServerMockPT extends Specification {
restPost.entity = new StringEntity("<request$current/>", ContentType.create("text/xml", "UTF-8")) restPost.entity = new StringEntity("<request$current/>", ContentType.create("text/xml", "UTF-8"))
CloseableHttpResponse response = client.execute(restPost) CloseableHttpResponse response = client.execute(restPost)
responses[current] = Util.extractStringResponse(response) responses[current] = Util.extractStringResponse(response)
assert controlServerClient.removeMock("testRest$current", false).size() == 1 controlServerClient.removeMock("testRest$current", true)
} }
} }
when: executorService.shutdown()
executorService.awaitTermination(60, TimeUnit.SECONDS) executorService.awaitTermination(90, TimeUnit.SECONDS)
then: 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: cleanup:
executorService.shutdown()
httpMockServer.stop() httpMockServer.stop()
} }
} }

View file

@ -15,12 +15,12 @@ class ContextExecutor {
ContextExecutor(HttpServerWraper httpServerWraper, Mock initialMock) { ContextExecutor(HttpServerWraper httpServerWraper, Mock initialMock) {
this.httpServerWraper = httpServerWraper this.httpServerWraper = httpServerWraper
this.path = '/' + initialMock.path this.path = "/${initialMock.path}"
this.mocks = new CopyOnWriteArrayList<>([initialMock]) this.mocks = new CopyOnWriteArrayList<>([initialMock])
httpServerWraper.createContext(path) { httpServerWraper.createContext(path) {
HttpExchange ex -> HttpExchange ex ->
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI) 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}") log.debug("Request: ${request.text}")
for (Mock mock : mocks) { for (Mock mock : mocks) {
try { try {