I have a list of user ids, they can be stored in a Collection or Feeder. In the test I create users with provided ids (around 2000 users) in one POST request and then send GET requests to verify that the users were created. It may take 5-10 seconds to create all the users, but first users start to appear after 0.5-1 second. I am creating and verifying users simultaneously in two different scenarios. The problem is that verifyUsers(ids) will send GET requests for each id one by one, but I need them to be sent in parallel because each GET request will take some time and I don't want to create a queue.
def createUsers(ids: List[String]): ScenarioBuilder = scenario("Create users")
.exec(createUsersForIds(ids))
def verifyUsers(ids: List[String]) = scenario("Verify users")
.repeat(ids.size, "iterator") {
exec(session => {
val index: Int = session("iterator").as[Int]
session.set("id", ids.take(index))
})
.exec(verifyUserWithId) // verifyUserWithId will then take a userId from the session and send a GET request with that id
}
setUp(
createUsers(ids).inject(atOnceUsers(1)),
verifyUsers(ids).inject(atOnceUsers(1))
)
In short, you want multiple producers (virtual users in the createUsers
scenario) and multiple consumers (virtual users in the verifyUsers
scenario), with a queue in between.
Some hints:
java.util.concurrent.ConcurrentLinkedQueue
AtomicLong
to keep track of the number of records produced and consumed so you can detect when you've consumed all the records you've ultimately produced.asLongAs
) with a pause.Edit: If your use case is actually that the producer produces all records at once, the solution is way easier:
Hope it helps!