Code Monkey home page Code Monkey logo

clj-gatling's Introduction

clj-gatling Build Status

Create and run performance tests using Clojure (and get fancy reports). For reporting clj-gatling uses Gatling under the hood.

Installation

Add the following to your project.clj :dependencies:

[clj-gatling "0.4.0"]

Usage

Simple example

This will make 100 simultaneous http get requests to localhost. Single request is considered to be ok if it returns http status code 200.

(use 'clj-gatling.core)

(run-simulation
  [{:name "Localhost test cenario"
   :requests [{:name "Root request" :http "http://localhost"}]}] 100)

Simulation run shows some important statistics in console and also generates exactly the same kind of a html report that Gatling does. (clj-gatling uses Gatling internally to do this)

Defining test scenarios

clj-gatling runs scenarios concurrently. Scenario consists of one or more steps called requests. Scenario is defined as a Clojure map.

{:name "Order book scenario"
 :requests [{:name "Open frontpage" :fn open-frontpage}
            {:name "Select book"    :fn select-book
             :name "Pay order"      :fn pay-order}]}

Scenario above consists of three requests. Requests are defined as a Clojure maps. In request you can specify actual action either by giving keyword :http which will do http get request or by giving :fn keyword which lets you to specify your own function. The latter option is a preferred way in clj-gatling.

Your own functions should look like this:

(defn open-frontpage [user-id context callback]
  (let [was-call-succesful? (do-your-call-here)
    (callback was-call-succesful? context)))

Ideally your calls should be asynchronous and non-blocking. That's why in function signature clj-gatling uses callback instead of function return value. When calling callback function the first parameter is boolean which tells clj-gatling whether call was succesful.

The second parameter to callback is context that is passed through requests within same scenario and virtual user. You can utilize it in a following way:

;In "Select book" request
(callback true (assoc context :book-id 1}))

;And then in next requst
(defn pay-order [user-id context callback]
  (pay-order-call-with-book-id (:book-id context))
    ...)

Options

Request timeout

By default clj-gatling uses timeout for 5000 ms for all functions. You can override that behaviour by setting option :timeout-in-ms

Constant load

You can run same scenario multiple times to generate constant load within a longer time period by specifying option :requests. Default number of requests is same as number of users (which means run only once)

(run-simulation [test-scenario] 10 {:requests 500})

You can run same scenario multiple times within given time period to generate constant load by specifying option :duration.

(require '[clj-time.core :as t])

(run-simulation [test-scenario] 10 {:duration (t/minutes 2)})

License

Copyright (C) 2014 Markus Hjort

Distributed under the Eclipse Public License, the same as Clojure.

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.