SaraCavelind
13 years agoContributor
Load testing with mocked servcies
Hi!
We have developed a mock server (17 services) that we use to easy the testdata handling. Now we're considering load testing applications that use the mock server.
I realise that the mockserver might now become a problem in itself since I have not done anything to make the mock dispatch scripts threadsafe.
I'm a technical tester and find that this might be a little to difficult but I'm willing to give it a try before I call someone....
Is there any hints on what I need to do in order to make my dispatch scripts better so it can handle load?
This is the dispatch script. In summary it checks if a has of the request exists on disk, then loads it; otherwise calls the real backend, saves the file and returns the response.
import com.eviware.soapui.model.testsuite.TestRunner.Status
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.impl.wsdl.WsdlSubmitContext
import com.eviware.soapui.impl.wsdl.WsdlSubmit
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.mock.MockResponse
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
def idSSN=holder["//*:ssn"]
outputDir=context.expand( '${#Project#outputfolder}')
def BindingName="getPerson-2.0Binding"
def operationName="getPerson-2.0Op"
def requestName="Request 1"
def outputLocation="${outputDir}${BindingName}/"
log.info "Data sparas till:${outputLocation}"
// get reference to project
WsdlProject project = (WsdlProject)mockOperation.mockService.project
// get reference to request
WsdlRequest request = (WsdlRequest)project.interfaces["${BindingName}"].operations["${operationName}"].getRequestByName("${requestName}")
// set request content from incoming mockRequest
request.setRequestContent(mockRequest.getRequestContent())
// get util testcase
def testCase = project.testSuites["utils"].testCases["hashContent"]
// set arguments as properties
testCase.setPropertyValue( "content", mockRequest.requestContent )
// run testCase
def runner = testCase.run( new com.eviware.soapui.support.types.StringToObjectMap(), false )
fileHashName="-"+testCase.getPropertyValue( "hash" )
if(idSSN)
{
fullFileName="${outputLocation}"+idSSN+fileHashName
log.info "SSN"
log.info idSSN
}
// Change for each service
log.info (fullFileName)
def fileH = new File( fullFileName)
if (fileH.exists()==false)
{
log.info "Filen finns inte, hämtar och sparar!"
WsdlSubmit submit=request.submit( new WsdlSubmitContext( request ), false )
// wait for the response
Response response = submit.getResponse();
// get reference to MockResponse
requestContext.responseMessage = response.getContentAsString()
def fileW = new File(fullFileName)
fileW.createNewFile()
fileW.setWritable(true, false)
log.info "Skrivbar:"+fileW.canWrite()
log.info "Innehåll"
log.info requestContext.responseMessage
fileW.write(requestContext.responseMessage)
}
else
{
log.info "Filen existerar redan"
requestContext.responseMessage=fileH.getText()
}
We have developed a mock server (17 services) that we use to easy the testdata handling. Now we're considering load testing applications that use the mock server.
I realise that the mockserver might now become a problem in itself since I have not done anything to make the mock dispatch scripts threadsafe.
I'm a technical tester and find that this might be a little to difficult but I'm willing to give it a try before I call someone....
Is there any hints on what I need to do in order to make my dispatch scripts better so it can handle load?
This is the dispatch script. In summary it checks if a has of the request exists on disk, then loads it; otherwise calls the real backend, saves the file and returns the response.
import com.eviware.soapui.model.testsuite.TestRunner.Status
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.impl.wsdl.WsdlSubmitContext
import com.eviware.soapui.impl.wsdl.WsdlSubmit
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.mock.MockResponse
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
def idSSN=holder["//*:ssn"]
outputDir=context.expand( '${#Project#outputfolder}')
def BindingName="getPerson-2.0Binding"
def operationName="getPerson-2.0Op"
def requestName="Request 1"
def outputLocation="${outputDir}${BindingName}/"
log.info "Data sparas till:${outputLocation}"
// get reference to project
WsdlProject project = (WsdlProject)mockOperation.mockService.project
// get reference to request
WsdlRequest request = (WsdlRequest)project.interfaces["${BindingName}"].operations["${operationName}"].getRequestByName("${requestName}")
// set request content from incoming mockRequest
request.setRequestContent(mockRequest.getRequestContent())
// get util testcase
def testCase = project.testSuites["utils"].testCases["hashContent"]
// set arguments as properties
testCase.setPropertyValue( "content", mockRequest.requestContent )
// run testCase
def runner = testCase.run( new com.eviware.soapui.support.types.StringToObjectMap(), false )
fileHashName="-"+testCase.getPropertyValue( "hash" )
if(idSSN)
{
fullFileName="${outputLocation}"+idSSN+fileHashName
log.info "SSN"
log.info idSSN
}
// Change for each service
log.info (fullFileName)
def fileH = new File( fullFileName)
if (fileH.exists()==false)
{
log.info "Filen finns inte, hämtar och sparar!"
WsdlSubmit submit=request.submit( new WsdlSubmitContext( request ), false )
// wait for the response
Response response = submit.getResponse();
// get reference to MockResponse
requestContext.responseMessage = response.getContentAsString()
def fileW = new File(fullFileName)
fileW.createNewFile()
fileW.setWritable(true, false)
log.info "Skrivbar:"+fileW.canWrite()
log.info "Innehåll"
log.info requestContext.responseMessage
fileW.write(requestContext.responseMessage)
}
else
{
log.info "Filen existerar redan"
requestContext.responseMessage=fileH.getText()
}