Giter VIP home page Giter VIP logo

gatling-websocket's Introduction

gatling-websocket

This is a simple addon to add WebSocket support to Gatling.

Usage

First create the jar:

sbt package

... then copy target/gatling-websocket-0.0.9.jar to Gatling's lib directory.

In your simulation, import the DSL:

import com.giltgroupe.util.gatling.websocket.Predef._

You can now open a websocket:

websocket("socket").open("ws://<url>/", "socket_open")

The parameter to websocket is the name of the session attribute used to reference the socket later in the simulation. The second parameter to open is optional and is the name used to record the amount of time the socket took to open in the log; if omitted it defaults to the name of the session attribute.

You can specify extra headers to include in the initial HTTP request that sets up the socket:

websocket("socket").open("ws://<url>/", "socket_open").
  header("header", "value").
  headers(Map("header1" -> "value1", "header2" -> "value2"))

HTTP BASIC authentication is supported:

websocket("socket").open("ws://<url>/", "socket_open").
  basicAuth("myUser", "myPassword")

You can send a text frame on an open socket:

 websocket("socket").sendMessage("test", "socket_send")

Again, the second parameter is optional and is the request name used to record whether sending succeeded or not in the log (the time taken to send is usually less than 1 millisecond).

Finally, you should close the socket at the end of the simulation:

websocket("socket").close("socket_close")

The parameter is the optional request name again.

Complete example

class WebsocketSimulation extends Simulation {
  val scn = scenario("Scenario name")
    .exec(websocket("socket").open("ws://localhost:8000/ws", "socket_open"))
    .exec(websocket("socket").sendMessage("my data", "socket_send"))
    .pause(10)
    .exec(websocket("socket").close("socket_close"))

  setUp(scn.users(10).ramp(2))
}

License

Copyright 2012-2013 Gilt Groupe, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

gatling-websocket's People

Contributors

amjjd avatar

Watchers

James Cloos avatar  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.