Giter Club home page Giter Club logo

gatlingcql's Introduction

GatlingCql

Gatling DSL support for Apache Cassandra CQL

Features

Basic Gatling DSL for Apache Cassandra CQL, prepared statements are supported as well

class CassandraSimulation extends Simulation {
  val keyspace = "test"
  val table_name = "test_table"
  val session = Cluster.builder().addContactPoint("127.0.0.1")
                  .build().connect(s"$keyspace") //Your C* session
  val cqlConfig = cql.session(session) //Initialize Gatling DSL with your session

  //Setup
  session.execute(s"""CREATE KEYSPACE IF NOT EXISTS $keyspace 
                      WITH replication = { 'class' : 'SimpleStrategy', 
                                          'replication_factor': '1'}""")
  session.execute(s"""CREATE TABLE IF NOT EXISTS $table_name (
          id timeuuid,
          num int,
          str text,
          PRIMARY KEY (id)
        );
      """)
  //It's generally not advisable to use secondary indexes in you schema
  session.execute(f"""CREATE INDEX IF NOT EXISTS $table_name%s_num_idx 
                      ON $table_name%s (num)""")


  //Prepare your statement, we want to be effective, right?
  val prepared = session.prepare(s"""INSERT INTO $table_name 
                                      (id, num, str) 
                                      VALUES 
                                      (now(), ?, ?)""")

  val random = new util.Random
  val feeder = Iterator.continually( 
      // this feader will "feed" random data into our Sessions
      Map(
          "randomString" -> random.nextString(20), 
          "randomNum" -> random.nextInt()
          ))

  val scn = scenario("Two statements").repeat(1) { //Name your scenario
    feed(feeder)
    .exec(cql("simple SELECT") 
         // 'execute' can accept a string 
         // and understands Gatling expression language (EL), i.e. ${randomNum}
        .execute("SELECT * FROM test_table WHERE num = ${randomNum}")) 
    .exec(cql("prepared INSERT")
         // alternatively 'execute' accepts a prepared statement
        .execute(prepared)
         // you need to provide parameters for that (EL is supported as well)
        .withParams(Integer.valueOf(random.nextInt()), "${randomString}")
        // and set a ConsistencyLevel optionally
        .consistencyLevel(ConsistencyLevel.ANY)) 
  }

  setUp(scn.inject(rampUsersPerSec(10) to 100 during (30 seconds)))
    .protocols(cqlConfig)
}

Installation

  • Get a release TGZ
  • Unpack into Gatling folder: tar -xjf GatlingCql-0.0.2-SNAPSHOT-release.tar.gz -C gatling-charts-highcharts-2.0.0-RC5/
  • Run Gatling and you should see cassandra.CassandraSimulation in your simulations list

More Information

gatlingcql's People

Contributors

mishail avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.