简体   繁体   中英

How to make concurrent rest requests

Hi I am trying to write an integration test which will make concurrent (say 3 concurrent for example) restful api calls, and I need to assert the data returned in each call is different. This is because I have a find and update and return data within a synchronized block,so I need to test the data returned is different for each thread. I have looked at the junit activetestsuite but unsure how to apply this to my integration test. API call i want to make in my IT test is below

  ResponseEntity<String> response = this.restTemplate
                .exchange("endpoint/",HttpMethod.GET,String.class);

 //make assertions on each returned call

Maybe take a look at ReactiveX zip method for Java:

http://reactivex.io/documentation/operators/zip.html

Assume that you would like to run the UnitTest concurrently. The Concurrent JUnit can help on this. https://github.com/ThomasKrieger/concurrent-junit There is also a step-by-step guide line in here: https://examples.javacodegeeks.com/core-java/junit/junit-multithreaded-test-example/

Hope it help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM