eniss
11 years agoNew Contributor
How to lock Context in multi-call Mock Services
I'm working on SoapUI to test mock services with Groovy scripts. My mocks works fine in single-thread mode (only one execution at a time), but when I launch multithreaded mocks, responses from the mock are wrong (eg the second response takes the value of the first) because of concurrency in treatment of the mocks. This is due to the context in which I store the answers retrieved from a query.
My XML response :
My groovy script:
I saw this thread : viewtopic.php?t=2818 and tried to lock the context like this :
But it didn't work. How can I lock the context to avoid the concurrency exception ? Otherwise, Is there a way to get response from Mock without using context ?
Thanks in advance.
My XML response :
<item> ${id} </ item>
My groovy script:
groovyUtils def = new com.eviware.soapui.support.GroovyUtils (context)
def holder = groovyUtils.getXmlHolder (mockRequest.requestContent)
cstmt con.prepareCall def = ("{CALL STORED_PROCEDURE_X (,,)??}");
/ / parameters declaration of the procedure ...
cstmt.executeQuery def rs = ();
/ / Retrieve the response parameters
if (rs.next ())
{
context.id = rs.getString ("id");
}
I saw this thread : viewtopic.php?t=2818 and tried to lock the context like this :
context.lock = new Object();
synchronized(context.lock)
{
context.id = rs.getString("id");
}
But it didn't work. How can I lock the context to avoid the concurrency exception ? Otherwise, Is there a way to get response from Mock without using context ?
Thanks in advance.