Stress , load or concurrency testing using rest assured

1,570 views
Skip to first unread message

vinod komeershetty

unread,
Aug 28, 2016, 4:16:37 PM8/28/16
to REST assured
Any pointers or hints on how to perform
Stress , load or concurrency testing using rest assured frame work for apis

Todd Bradley

unread,
Aug 28, 2016, 4:53:21 PM8/28/16
to rest-a...@googlegroups.com
In the past we've built tests in Java using REST-assured and TestNG, and then run them using NGrinder.

On Sun, Aug 28, 2016 at 1:43 PM, vinod komeershetty <komeersh...@gmail.com> wrote:
Any pointers or hints on how to perform
 Stress , load or concurrency testing using rest assured frame work for apis

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Hoadrea

unread,
Sep 23, 2016, 10:06:23 AM9/23/16
to REST assured
Have you succeed doing this with TestNG and NGrinder ?
Have you found any other solutions ? 
I am also interested in this topic, as I will have to do performance in a few months, I was thinking of rewriting the tests in JMeter, but that is not very efficient as I have them already in RestAssured. 

Johan Haleby

unread,
Sep 23, 2016, 10:11:40 AM9/23/16
to rest-a...@googlegroups.com
REST Assured is not built for performance testing so I would rather use a specific tool designed for this purpose. I'm mostly using gatling nowdays and find the DSL to be quite nice.

--
Message has been deleted

Yulia Atlasova

unread,
Sep 25, 2016, 12:33:15 PM9/25/16
to REST assured
For concurrency we used java.util.concurrent that allows to start calls simultaneously. Number of calls depends on available processors.
Countdown latch guarantees that processes would be started simultaneously.

import com.google.gson.Gson;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

import static io.restassured.RestAssured.UNDEFINED_PORT;
import static io.restassured.RestAssured.given;
import static org.apache.commons.lang3.time.DateUtils.addSeconds;
import static org.junit.Assert.assertTrue;

/**
 * Created by Yulia_Atlasova on 9/25/2016.
 */
public class Example {

    @Test
    public void canCreateLibrariesSimultaneously() throws ExecutionException, InterruptedException {
        int threads = Runtime.getRuntime().availableProcessors();
        ExecutorService service = Executors.newFixedThreadPool(threads);
        CountDownLatch latch = new CountDownLatch(threads);
        List<Future<Library>> futures = new ArrayList<>(threads);
        List<Library> libraries = new ArrayList<>(threads);
        Gson gson = new Gson();
        for (int i = 0; i < threads; i++) {
            Future<Library> future = service.submit(() -> {
                latch.countDown();
                latch.await();
                return gson.fromJson(given()
                        .port(UNDEFINED_PORT)
                        .urlEncodingEnabled(false)
                        .queryParam("RequestId", new Date().getTime())
                        .post().asString(), Library.class);
            });
            futures.add(future);
        }

        for (Future<Library> future : futures) {
            libraries.add(future.get());
        }
        Date now = new Date();
        service.shutdown();
        for (Library library : libraries) {
            Date created = library.getServiceData().getCreatedTimestamp();
            assertTrue("Created timestamp should be within last 2 seconds, but it is: " + created,
                    created.after(addSeconds(now, -2)) && created.before(now));

        }
    }
}


On Sunday, 28 August 2016 23:16:37 UTC+3, vinod komeershetty wrote:
Reply all
Reply to author
Forward
0 new messages