Skip to content

Commit

Permalink
Added speed test for RestClient and RestApi
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesde committed Aug 10, 2016
1 parent 2c4d9ea commit 73dcc28
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions base-component/tools/screen/Tools/Entity/SpeedTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this software (see the LICENSE.md file). If not, see
import org.moqui.entity.EntityCondition
import org.moqui.entity.EntityConditionFactory
import org.moqui.screen.ScreenTest
import org.moqui.service.RestClient
import java.text.DecimalFormat
import java.sql.Timestamp
Expand All @@ -53,6 +54,7 @@ along with this software (see the LICENSE.md file). If not, see
boolean directNoSqlCrudTests = true
boolean serviceCallTests = true
boolean screenRenderTests = true
boolean restApiTests = true
EntityFacade ef = ec.entity
Timestamp nowTs = new Timestamp(System.currentTimeMillis())
Expand Down Expand Up @@ -402,6 +404,34 @@ along with this software (see the LICENSE.md file). If not, see
if (!tarpitAlreadyDisabled) ec.artifactExecution.enableTarpit()
}
// ========== Service REST API tests ==========
if (restApiTests) {
boolean tarpitAlreadyDisabled = ec.artifactExecution.disableTarpit()
calls = (baseCallsNum / 100).intValue() ?: 1
String apiKey = ec.user.getLoginKey()
String enumUri = ec.web.getWebappRootUrl(true, null) + "/rest/s1/moqui/basic/enums/EsaaAlways"
// Render Dashboard (simple screen, mostly screen overhead)
startTime = System.nanoTime()
boolean gotError = false
try {
for (int i = 0; i < calls; i++) {
RestClient rc = ec.service.rest().method(RestClient.GET).uri(enumUri).addHeader("api_key", apiKey)
RestClient.RestResponse response = rc.call()
// logger.warn("REST response: ${response.text()}")
}
} catch (Exception e) {
logger.error("REST API error", e)
gotError = true
}
milliseconds = ((System.nanoTime() - startTime) / 1E6)
performanceList.add([operation : "REST Client API get /basic/enums" + (gotError ? " GOT ERROR" : ""), entity: "",
calls : calls, milliseconds: milliseconds, msPerCall: (milliseconds / calls),
callsPerSecond: ((calls / milliseconds) * 1000)])
if (!tarpitAlreadyDisabled) ec.artifactExecution.enableTarpit()
}
return performanceList
}
]]></script>
Expand Down

0 comments on commit 73dcc28

Please sign in to comment.