Re: [rest-assured] Is rest-assured thread safe?

4,304 views
Skip to first unread message

Johan Haleby

unread,
Feb 6, 2013, 1:51:41 PM2/6/13
to rest-a...@googlegroups.com
Good question. I would like to say yes but to be honest I've never tried so you may run into issues. It will not work if you need to access different servers with different "static" configuration but you can create Request- and Response specifications. Please report your findings!

Regards,
/Johan


On Wed, Feb 6, 2013 at 5:51 PM, Magnus <ari...@gmail.com> wrote:
Since all the setup seems to involve static calls to what I assume must be a singleton inside, I'm wondering how to use this in a multi-threaded environment?

Specifically, I have several servers at different hosts that I'd like to query in parallel from RestAssured.

Ordinarily I'd create separate instances and use one per thread, but is this possible with RestAssured?

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Vydra

unread,
Jul 8, 2013, 7:46:54 PM7/8/13
to rest-a...@googlegroups.com
Johan,

I am in a multi-tenant environment and need to run tests in parallel using different Basic Auth for some tests. Do you have any plans to refactor the code to support RestAssured.authentication via ThreadLocal to allow for parallel testing in the same JVM process?

Thanks,
David

Johan Haleby

unread,
Jul 9, 2013, 2:03:48 AM7/9/13
to rest-a...@googlegroups.com
How are you setting up the basic auth?

/Johan

Juraj Martinka

unread,
Aug 20, 2013, 11:05:55 AM8/20/13
to rest-a...@googlegroups.com
Hi,

I've tried to execute multiple tests using rest assured in parallel and many of them failed with following error (which happens only when RequestLoggingFilter and/or ResponseLoggingFilter is enabled):

  cause: java.lang.NullPointerException: Cannot invoke method filter() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)
at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)
at com.jayway.restassured.filter.log.RequestLoggingFilter.filter(RequestLoggingFilter.java:134)
at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)
at com.jayway.restassured.filter.FilterContext$next.call(Unknown Source)
at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:758)
at com.jayway.restassured.internal.RequestSpecificationImpl$invokeFilterChain.callCurrent(Unknown Source)
at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1142)
at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$applyPathParamsAndSendRequest.callCurrent(Unknown Source)
at com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy:135)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:231)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.my.classXXX


The code of rest api call is as follows:

given()
                .body(someJson)
//                .log().all()
        .when()
//                .log().all()
                .post("/my/rest/api")

There is a common configuration shared by all tests:

        baseURI = host
        authentication = preemptive().basic(user, password);
        filters(new RequestLoggingFilter(), new ResponseLoggingFilter())
        requestContentType(ContentType.JSON)

The problem here are the filters - RequestLoggingFilter and ResponseLoggingFilter. If I remove them then tests are passing.
However, I do want to log requests and responses and configure this at only one place - If I remove filters and use ".log().all()" then, again, tests are passing.

Any suggestions?


Dňa streda, 6. februára 2013 19:51:41 UTC+1 Johan Haleby napísal(-a):

Johan Haleby

unread,
Aug 22, 2013, 1:47:24 AM8/22/13
to rest-a...@googlegroups.com
Could you possibly reproduce this in a test case that you could send me?

Regards,
/Johan

Lalith Choudary

unread,
Aug 14, 2014, 2:29:57 PM8/14/14
to rest-a...@googlegroups.com
We attempted to write thread safe tests. So far its working

In BaseTest

@Before
    @After
    public void resetSessionCookies() {
        this.sessionFilter = new RestSessionFilter();
    }

    public RequestSpecification givenSession() {
        RequestSpecification spec = given();

        spec = spec.header("Accept", "application/json").filter(this.sessionFilter);

        return spec;
    }

    public RequestSpecification given() {
        RestAssuredConfig config = CONFIG.logConfig(LOG_CONFIG.defaultStream(new LoggerPrintStream(LOG, Level.ERROR)));
        RequestSpecification spec = RestAssured.given().baseUri(BASE_URI).config(config);
        return spec;
    }

-thanks,
Lalith
Reply all
Reply to author
Forward
0 new messages