Skip to content

Instantly share code, notes, and snippets.

@shoaib42
Last active February 19, 2022 18:22
Show Gist options
  • Save shoaib42/5599f774f134901bc24396f537180bf6 to your computer and use it in GitHub Desktop.
Save shoaib42/5599f774f134901bc24396f537180bf6 to your computer and use it in GitHub Desktop.
Testing RPOPLPUSH for gatling feeder
package computerdatabase;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
import static io.gatling.javaapi.redis.RedisDsl.redisFeeder;
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
import io.gatling.javaapi.redis.RedisFeederBuilder;
import java.time.Duration;
public class RedisSimulationJava extends Simulation {
HttpProtocolBuilder httpProtocol =
http
// Here is the root for all relative URLs
.baseUrl("http://computer-database.gatling.io")
// Here are the common headers
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");
com.redis.RedisClientPool redisPool =
new com.redis.RedisClientPool(
"localhost",
6379,
8,
0,
scala.Option.apply(null),
0,
-1,
3000,
scala.Option.apply(null),
com.redis.RedisClient.SINGLE$.MODULE$);
RedisFeederBuilder rf = redisFeeder(redisPool, "mylist", "myotherlist").RPOPLPUSH();
RedisFeederBuilder rfo = redisFeeder(redisPool, "myotherlist", "myotherlist").RPOPLPUSH();
// A scenario is a chain of requests and pauses
ScenarioBuilder scn =
scenario("Add records")
.repeat(5).on(
feed(rf)
.exec(
http("addComputer")
// Here's an example of a POST request
.post("/computers")
// Note the triple double quotes: used in Scala for protecting a whole chain of
// characters (no need for backslash)
.formParam("name", "#{mylist}")
.formParam("introduced", "2012-05-30")
.formParam("discontinued", "")
.formParam("company", "37"))
.pause(1)
);
ScenarioBuilder scnNext =
scenario("Read records")
.repeat(13).on(
feed(rfo).exec(http("filterByName").get("/computers?f=#{myotherlist}")).pause(1)
);
{
setUp(scn.injectOpen(atOnceUsers(1)).andThen(scnNext.injectOpen(atOnceUsers(1)))).protocols(httpProtocol);
}
}
package computerdatabase;
import io.gatling.redis.Predef._
import com.redis._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class RedisSimulationScala extends Simulation {
val httpProtocol =
http
// Here is the root for all relative URLs
.baseUrl("http://computer-database.gatling.io")
// Here are the common headers
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val redisPool = new RedisClientPool("localhost", 6379)
val rf = redisFeeder(redisPool, "mylist", "myotherlist").RPOPLPUSH();
val rfo = redisFeeder(redisPool, "myotherlist", "myotherlist").RPOPLPUSH();
// A scenario is a chain of requests and pauses
val scn =
scenario("Add records")
.repeat(5)(
feed(rf)
.exec(
http("addComputer")
// Here's an example of a POST request
.post("/computers")
// Note the triple double quotes: used in Scala for protecting a whole chain of
// characters (no need for backslash)
.formParam("name", "#{mylist}")
.formParam("introduced", "2012-05-30")
.formParam("discontinued", "")
.formParam("company", "37"))
.pause(1)
)
val scnNext =
scenario("Read records")
.repeat(10)(
feed(rfo).exec(http("filterByName").get("/computers?f=#{myotherlist}")).pause(1)
)
{
setUp(scn.inject(atOnceUsers(1)).andThen(scnNext.inject(atOnceUsers(1)))).protocols(httpProtocol);
}
}
package computerdatabase;
import io.gatling.redis.Predef._
import com.redis._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
class RedisSimulationScalaPOP extends Simulation {
val httpProtocol =
http
// Here is the root for all relative URLs
.baseUrl("http://computer-database.gatling.io")
// Here are the common headers
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val redisPool = new RedisClientPool("localhost", 6379)
val rf = redisFeeder(redisPool, "mylist", "myotherlist").RPOPLPUSH();
val rfo = redisFeeder(redisPool, "myotherlist").LPOP();
// A scenario is a chain of requests and pauses
val scn =
scenario("Add records")
.repeat(5)(
feed(rf)
.exec(
http("addComputer")
// Here's an example of a POST request
.post("/computers")
// Note the triple double quotes: used in Scala for protecting a whole chain of
// characters (no need for backslash)
.formParam("name", "#{mylist}")
.formParam("introduced", "2012-05-30")
.formParam("discontinued", "")
.formParam("company", "37"))
.pause(1)
)
val scnNext =
scenario("Read records")
.repeat(10)(
feed(rfo).exec(http("filterByName").get("/computers?f=#{myotherlist}")).pause(1)
)
{
setUp(scn.inject(atOnceUsers(1)).andThen(scnNext.inject(atOnceUsers(1)))).protocols(httpProtocol);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment