Skip to content

Instantly share code, notes, and snippets.

@bilzard
Last active February 10, 2020 06:42
Show Gist options
  • Save bilzard/1de5a09186a6c5e154fb5910d40378e3 to your computer and use it in GitHub Desktop.
Save bilzard/1de5a09186a6c5e154fb5910d40378e3 to your computer and use it in GitHub Desktop.

Gatling の EL (Expression Language) と Scala の string interpolation

文字列の先頭に s をつけると Scala の string interpolation が実行される。 Gatling の EL は単なるマクロ置換なので、ELを使う場合は文字列の先頭に s はつけない。

例)

  • s"Hello, ${name}" => 変数 name の値が展開される(string interporation; Scala)
  • "Hello, ${name}" => セッションの name の値が展開される(EL; Gatling DSL)

セッションキーの値を変数として渡したい場合は以下のようにする:

s"Bearer $${${sessionKey}}"

コンパイラは以下のように評価する:

s"Bearer $${${sessionKey}}"
=> s"Bearer $${access-token}"
=> "Bearer ${access-token}"
=> "Bearer 01234567890ABCDEF..."

最後から2番目の式は EL によってセッションキー merchant-access-token の値に展開される。

(なお、Gatling で「セッション」という用語は、サーバサイドセッションではなく、クライアントサイドセッションに使われることに注意)

https://gatling.io/docs/current/session/expression_el/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment