/gatling-mongodb-protocol

MongoDB protocol for Gatling

Primary LanguageScalaMIT LicenseMIT

gatling-mongodb-protocol

Codacy Badge License

MongoDB protocol for Gatling

Mongo protocol configuration

Example:

val mongoProtocol = mongo
  .uri("mongodb://username:password@host:port/database")
  • hosts: Array of string in format: "host:port"

  • authSource: The database source for authentication credentials.

  • authMode: The authentication mode. By default set to scram-sha1 for SCRAM-SHA-1. Can be configured with mongocr for the backward compatible MONGODB-CR.

  • connectTimeoutMS: The number of milliseconds to wait for a connection to be established before giving up.

  • maxIdleTimeMS: The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed.

  • sslEnabled: It enables the SSL support for the connection (true|false).

  • sslAllowsInvalidCert: If sslEnabled is true, this one indicates whether to accept invalid certificates (e.g. self-signed).

  • tcpNoDelay: TCPNoDelay boolean flag (true|false).

  • keepAlive: TCP KeepAlive boolean flag (true|false).

  • nbChannelsPerNode: Number of channels (connections) per node.

  • writeConcern: The default write concern (default: acknowledged). unacknowledged: Option w set to 0, journaling off (j), fsync off, no timeout. acknowledged: Option w set to 1, journaling off, fsync off, no timeout. journaled: Option w set to 1, journaling on, fsync off, no timeout.

  • readPreference: The default read preference (primary|primaryPreferred|secondary|secondaryPreferred|nearest) (default is primary).

  • failover: The default failover strategy. default: The default/minimal strategy, with 10 retries with an initial delay of 100ms and a delay factor of retry count * 1.25 (100ms .. 125ms, 250ms, 375ms, 500ms, 625ms, 750ms, 875ms, 1s, 1125ms, 1250ms). remote: The strategy for remote MongoDB node(s); Same as default but with 16 retries. strict: A more strict strategy; Same as default but with only 5 retries. :x: The definition of a custom strategy; delay: The initial delay as a finite duration string accepted by the Duration factory. retries: The number of retry (Int). factor: The Double value to multiply the retry counter with, to define the delay factor (retryCount * factor).

  • monitorRefreshMS: The interval (in milliseconds) used by the ReactiveMongo monitor to refresh the node set (default: 10s); The minimal value is 100ms.

For more information see the MongoDB connection options

Example:

val mongoProtocol = mongo
  .hosts("host1", "host2:port2")
  .username("usr")
  .password("pass")
  .database("database")

Mongo scenario definition

Execute custom command

  • command: the json string with raw mongo command

For more information see the MongoDB command api

all parameters support Expression

Example:

val scn = scenario("Mongo scenario")
    .exec(mongo("Custom command").command.execute("{\"aggregate\": \"collection\", \"pipeline\": [{\"$match\": {\"_field\": \"value\"}}]}"))

Execute count command

  • selector: the collection name
  • selector: the json string with mongo filter
  • limit : the maximum number of matching documents to count
  • skip : the number of matching documents to skip before counting
  • hint : the index to use (either the index name or the index document)

all parameters support Expression

Example:

val scn = scenario("Mongo scenario")
    .exec(mongo("count before").collection("messages").count().skip(5).limit(7).hint("{\"_id\": -1}"))