{"id":20678386,"url":"https://github.com/codecentric/gatling-jdbc","last_synced_at":"2025-05-10T15:30:40.194Z","repository":{"id":20768730,"uuid":"90855714","full_name":"codecentric/gatling-jdbc","owner":"codecentric","description":"JDBC support for Gatling","archived":false,"fork":false,"pushed_at":"2022-03-29T14:45:40.000Z","size":110,"stargazers_count":22,"open_issues_count":4,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2023-07-26T23:14:37.066Z","etag":null,"topics":["gatling","jdbc","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codecentric.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-10T11:14:58.000Z","updated_at":"2022-12-02T05:39:16.000Z","dependencies_parsed_at":"2022-07-23T15:16:15.927Z","dependency_job_id":null,"html_url":"https://github.com/codecentric/gatling-jdbc","commit_stats":null,"previous_names":[],"tags_count":6,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecentric%2Fgatling-jdbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecentric%2Fgatling-jdbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecentric%2Fgatling-jdbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codecentric%2Fgatling-jdbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codecentric","download_url":"https://codeload.github.com/codecentric/gatling-jdbc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224970089,"owners_count":17400344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gatling","jdbc","scala"],"created_at":"2024-11-16T21:19:52.900Z","updated_at":"2024-11-16T21:19:53.589Z","avatar_url":"https://github.com/codecentric.png","language":"Scala","readme":"# Gatling JDBC Extension\nJDBC support for Gatling\n\n[![Build Status](https://travis-ci.org/codecentric/gatling-jdbc.svg?branch=master)](https://travis-ci.org/codecentric/gatling-jdbc)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.codecentric/jdbc-gatling_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.codecentric/jdbc-gatling_2.12)\n\n\nThe JDBC extension for Gatling was originally created to accompany a blog post that shows how to extend Gatling.\nCurrently, five SQL operations are being supported. See below for the usage.\n\n## :exclamation::exclamation: Even more Attention :exclamation::exclamation:\n\nThe development of this project continues in [this fork](https://github.com/rbraeunlich/gatling-jdbc).\nPlease refrain from cloning/forking this repository or creating issue. Please use the other one!\n\n## :exclamation: Attention :exclamation:\n\nIn order to avoid conflicts with `io.gatling:gatling-jdbc` the artifact name has been changed with version 2.0.1.\nInstead of `gatling-jdbc` it is now called `jdbc-gatling` (see issue #8). Apart from this, nothing changes. All package names etc. stayed the same.\n\n## Usage\n\n```scala\nlibraryDependencies += \"de.codecentric\" %% \"gatling-jdbc\" % \"version\"\n```\n\n### General\n\nIn order to use the JDBC functionality, your simulation has to import `de.codecentric.gatling.jdbc.Predef._`.\nThe JDBC configuration is done via `jdbc`, e.g.:\n\n```scala\nval jdbcConfig = jdbc\n  .url(\"jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE\")\n  .username(\"sa\")\n  .password(\"sa\")\n  .driver(\"org.h2.Driver\")\n```\nThose are currently all the options that can be provided and that have to be provided.\n\nThe entry point for the operations is the `jdbc()` method. The method itself takes a request name as parameter. This name will appear in the reports to represent the operation that follows.\n\n### CREATE TABLE\n\nCreating a table is done via `jdbc().create()`. In order to ease the creation of arbitrarily many columns, the helper class `\nimport de.codecentric.gatling.jdbc.builder.column.ColumnHelper._` was created. It is recommended to use it. The datatype of every column has to be provided as a string.\nAdditionally, constraints are optional, but also have to be passed as strings. E.g.:\n```scala\nscenario(\"createTable\").\n    exec(jdbc(\"bar table\")\n      .create()\n      .table(\"bar\")\n      .columns(\n        column(\n          name(\"abc\"),\n          dataType(\"INTEGER\"),\n          constraint(\"PRIMARY KEY\")\n        ),\n        column(\n          name(\"ac\"),\n          dataType(\"INTEGER\")\n        )\n      )\n    )\n```\n\n### INSERT\n\nInsertion is done via `jdbc().insert()`. For where to insert, two options are possible. Suppose you have the table from the example above. You can insert the values either by relying on the indices:\n```scala\nexec(jdbc(\"insertion\")\n  .insert()\n  .into(\"bar\")\n  .values(\"${n}, ${n}\")\n)\n```\nor by using the column names:\n```scala\nexec(jdbc(\"insertion\")\n  .insert()\n  .into(\"bar (abc, ac)\")\n  .values(\"${n}, ${n}\")\n)\n```\n\n### SELECT\n\nIn contrast to the previous operations, select directly requires a parameter and is called via `jdbc().select(\u003cwhat\u003e)`. The intention is to closely resemble the SQL syntax.\nUsing `where()` is optional for SELECT. Therefore, the following two ways are both valid:\n```scala\nexec(jdbc(\"selection\")\n  .select(\"*\")\n  .from(\"bar\")\n)\n```\nand\n```scala\nexec(jdbc(\"selection\")\n  .select(\"*\")\n  .from(\"bar\")\n  .where(\"abc=4\")\n)\n```\nOf course, as parameter to `select()`, every column or combination of columns can be used, as with basic SQL.\n\n### DELETE\n\nDeletion starts from `jdbc().delete()`. Here, the where clause is optional again. In order to delete certain values the following works:\n```scala\nrepeat(5, \"n\"){\n    exec(jdbc(\"deletion\")\n        .delete()\n        .from(\"bar\")\n        .where(\"abc=${n}\")  \n    )\n}\n```\nAlternatively, in order to delete everything:\n```scala\nexec(jdbc(\"deletion\")\n    .delete()\n    .from(\"bar\")\n)\n```\nPlease be careful, since no additional validation is being performed and you might lose some data.\n\n### DROP TABLE\n\nThe last operation that is being supported is DROP TABLE via `jdbc().drop()` The method only takes a single parameter, the table name. Please be careful again, which table you drop.\nDropping the \"bar\" table from the first example can be done in the following way:\n```scala\njdbc(\"drop bar table\").drop().table(\"bar\")\n```\n\n### Checks\n\nCurrently, checks are only implemented for SELECT. When importing `de.codecentric.gatling.jdbc.Predef._` two types of checks are provided.\nThe first type is the SimpleCheck.\n\n#### SimpleCheck\n\nThe `simpleCheck` method (importet via `Predef`) allows for very basic checks. This method takes a function from `List[Map[String, Any]]` to `Boolean`.\nEach element in the list represents a row and the map the individual columns. Checks are simply appended to the selection, e.g.:\n```scala\nexec(jdbc(\"selection\")\n  .select(\"*\")\n  .from(\"bar\")\n  .where(\"abc=4\")\n  .check(simpleCheck(result =\u003e result.head(\"FOO\") == 4))\n)\n```\nA SELECT without a WHERE clause can also be validated with a `simpleCheck`.\n\nThere is also another type of check that is more closely integrated with Gatling, the `CheckBuilders`.\n\n#### CheckBuilder\n\n`CheckBuilder` is actually a class provided by Gatling. Based on the Gatling classes, Gatling JDBC provides two types of them.\nThe `JdbcAnyCheckBuilder` object contains the instances `SingleAnyResult` and `ManyAnyResults`. Both can be used in the tests quickly by calling either `jdbcSingleResponse` or `jdbcManyResponse`.\n\nThe difference between the two is that the single response extracts the head out of the list of results. So you can only verify a `Map[String, Any]`.\nWhereas the many response, like the simple checks, returns a `List[Map[String, Any]]`. Validation is performed via the Gatling API.\nE.g. checking a single result can look like this:\n```scala\nexec(jdbc(\"selectionSingleCheck\")\n  .select(\"*\")\n  .from(\"bar\")\n  .where(\"abc=4\")\n  .check(jdbcSingleResponse.is(Map[String, Any](\"ABC\" -\u003e 4, \"FOO\" -\u003e 4)))\n)\n```\nThis validates the data in the two columns \"ABC\" and \"FOO\". Please note explicit typing of the map. Without it the compiler will complain.\n\nA check with multiple results doesn't look very different:\n```scala\nexec(jdbc(\"selectionManyCheck\")\n  .select(\"*\")\n  .from(\"bar\")\n  .where(\"abc=4 OR abc=5\")\n  .check(jdbcManyResponse.is(List(\n    Map(\"ABC\" -\u003e 4, \"FOO\" -\u003e 4),\n    Map(\"ABC\" -\u003e 5, \"FOO\" -\u003e 5)))\n  )\n)\n```\n\nThe advantage those CheckBuilder provide is that they can access certain functionality provided by the Gatling interfaces and classes they extend.\nThe most important one is the possibility to save the result of a selection to the current session.\nBy calling `saveAs` after a check you can place the result in the session under the given name. So e.g. if you want to store the result of the single check you can do it like this:\n```scala\nexec(jdbc(\"selectionSingleCheckSaving\")\n  .select(\"*\")\n  .from(\"bar\")\n  .where(\"abc=4\")\n  .check(jdbcSingleResponse.is(Map[String, Any](\"ABC\" -\u003e 4, \"FOO\" -\u003e 4))\n  .saveAs(\"myResult\"))\n)\n```\n\n### Final\n\nCovering all SQL operations is a lot of work and some special commands might not be required for performance tests.\nPlease keep in mind that the state of this Gatling extension can be considered experimental. Feel free to leave comments and create pull requests.\n\n## Publishing\n\nFirstly, you gotta have in your home `.sbt/1.0/sonatype.sbt` configured to contain your username and password for Sonatype.\nSecondly, open the sbt shell an perform the following steps:\n1. `set pgpSecretRing := file(\"/home/\u003cuser\u003e/.sbt/gpg/secring.asc\")` or where ever it is\n2. `release`\n\n## Executing the intergration tests\n\nIf you have to run Docker on your machine as sudo, then to execute the integration tests, sbt has to be started as sudo, too.\nOnly `sudo sbt gatling:test` will then be allowed to start the container of the databases.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecentric%2Fgatling-jdbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodecentric%2Fgatling-jdbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodecentric%2Fgatling-jdbc/lists"}