gatling官方文档翻译3

第三篇
http://gatling.io/docs/2.2.1/migration_guides/1.5.x-to-2.0.html

Migrating from 1.5.x to 2.0
Global changes
Gatling requires at least JDK7u6
As targeting newer JDKs provides bug fixes, speed improvements and opens opportunities for optimization, Gatling now requires at least a JDK7u6 (released almost two years ago already).

Scala 2.10
Gatling is built with Scala 2.10. If you’re using Scala IDE, make sure you’re using a version compatible with Scala 2.10.

Gatling is now available on Maven Central
Gatling releases are now available on Maven Central, and snapshots are deployed on each successful build by Travis CI to Sonatype’s snapshots repository. If you were using Gatling with its Maven plugin, you no longer need to add the Excilys repository in your pom.xml.

Package and GroupId changes
Gatling’s artifacts groupId and package are now io.gatling. You’ll have to :

Update your build scripts to change the groupId of Gatling’s dependencies from com.excilys.ebi.gatling to io.gatling
Update your simulations to replace the com.excilys.ebi.gatling part in the imports by io.gatling
Simulation
Necessary imports
akka.util.duration classes have been ported to the scala.concurrent.duration package. Simply replace import akka.util.duration. by import scala.concurrent.duration..
import bootstrap. and import assertions. are now unnecessary and have to be removed.
import com.excilys.ebi.gatling.http.Headers.Names. is now unnecessary, headers names are now directly available from HeaderNames.
import com.excilys.ebi.gatling.http.Headers.Values.
is now unnecessary, headers values are now directly available from HeaderValues.
Protocols setup
Protocols are no longer configured by scenario and are now configured by simulation, using the protocols method.

A 1.4.x-1.5.x setUp like this one:

setUp(scn.(…).protocolConfig(httpConfig))
would now be with Gatling 2.0:

setUp(scn.(…)).protocols(httpConfig)
Assertions setup
The assertThat method has been removed, assertions are now configured using assertions in the same fashion as protocols are, e.g.

setup(scn.(…).protocolConfig(httpConfig))

assertThat(global.responseTime.max.lessThan(1000))
becomes:

setup(scn.(…))
.protocols(httpConfig)
.assertions(global.responseTime.max.lessThan(1000)
New Injection DSL
The users, ramp and delay methods to configure the injection profile for your scenario have been removed in favor of a full-blown dedicated DSL.

Injection steps are now configured using the inject method available on your configured scenario.

Migrating users

// With Gatling 1.5.X
setUp(scn.users(10)…)

// With Gatling 2.0
setUp(scn.inject(atOnceUsers(10))…
Migrating ramp

// With Gatling 1.5.X
setUp(scn.users(10).ramp(30)…)

// With Gatling 2.0
setUp(scn.inject(rampUsers(10) over (30 seconds))…
Migrating delay

// With Gatling 1.5.X
setUp(scn.users(10).delay(5)…)

// With Gatling 2.0
setUp(scn.inject(nothingFor(5 seconds), atOnceUsers(10))…
For more information on the new Injection DSL, please consult the Injection DSL reference documentation.

Core
Checks
whatever has been renamed to optional.

Structure Elements
The first parameter of foreach is now an Expression (e.g. a Gatling EL string), not the name of the attribute to loop over.
For example, if you have a list attribute in the user’s session holding a list of values:

.foreach(“list”, “elem”) {

}
becomes:

.foreach(“${list}”, “elem”) {

}
In asLongAs, exitASAP now defaults to true. For more information on the change of behaviour it introduces, see asLongAs documentation.
Session
Session has been under major refactoring:

session.get(“foobar”) becomes session(“foobar”)
session.getTypedAttributeT becomes session(“foobar”).as[T]
session.getAttributeAsOptionT becomes session(“foobar”).asOption[T]
session.setAttribute(“foobar”, 1234) becomes session.set(“foobar”, 1234)
session.setAttributes(Map(“foo” -> 1, “bar” -> 2) becomes session.setAll(“foo” -> 1, “bar” -> 2)
session.removeAttribute(“foobar”) becomes session.remove(“foobar”)
session.isAttributeDefined(“foobar”) becomes session.contains(“foobar”)
HTTP
Protocol
HTTP protocol bootstrapper, httpProtocol, has been renamed to http.

Query parameters
Removed

Versions of queryParam and multivaluedQueryParam that took no other parameters than the key (resolving the value from the session, using the key’s name to find the attribute with the same name) have been removed.

Modified

multivaluedQueryParam can now resolve the values directly from the session, using Gatling’s EL.

Form parameters (for POST requests)
Renamed

Methods for adding form parameters to the request have been renamed:

param => formParam
multiValuedParam => multivaluedFormParam
Removed

Versions of queryParam and multivaluedQueryParam that took no other parameters than the key (resolving the value from the session, using the key’s name to find the attribute with the same name) have been removed.

Modified

multivaluedFormParam can now resolve the values directly from the session, using Gatling’s EL.

Request bodies
Scalate templates support has been dropped. ElFileBody (see below) is the best suited to replace your existing Scalate templates.
The API for setting request bodies on request has changed. Instead of having several methods like body, fileBody and byteArrayBody, there is a now a single method, body(…) in which you set the type of body to send.
Migrating .body(body)

.body(body) has been replaced by .body(StringBody(body)).

http(“my post request”)
.post(“http://www.example.org“)
.body(“Look Ma, I’m a request body !”)
becomes:

http(“my post request”)
.post(“http://www.example.org“)
.body(StringBody(“Look Ma, I’m a request body !”))
Migrating .fileBody(filePath)

.fileBody(filePath) has been replaced by .body(RawFileBody(filePath)).

http(“my post request”)
.post(“http://www.example.org“)
.fileBody(“my_upload.xslx”)
becomes:

http(“my post request”)
.post(“http://www.example.org“)
.body(FileBody(“my_upload.xslx”))
Migrating .fileBody(filePath, values)

.fileBody(filePath, values) has been replaced by .body(ElFileBody(filePath)). values are now directly resolved from the virtual user’s session’s content.

http(“my post request”)
.post(“http://www.example.org“)
.fileBody(“my_template.txt”, Map(“userName” -> “user123”)
becomes:

http(“my post request”)
.post(“http://www.example.org“)
.body(ElFileBody(“my template.txt”))
If my template.txt contains:

Hi, my name is ${userName}
and the virtual user’s session has an attribute userName set to user123,

Then the effectively sent request body would be:

Hi, my name is user123
Migrating .byteArrayBody(byteArray)

.byteArrayBody(byteArray) has been replaced by .body(ByteArrayBody(bytes)).

http(“my post request”)
.post(“http://www.example.org“)
.byteArrayBody(Array(1, 2, 3, 4))
becomes:

http(“my post request”)
.post(“http://www.example.org“)
.body(ByteArrayBody(Array(1, 2, 3, 4)))
For more information, see the Request bodies reference section.

Misc
ExtendedResponse has been renamed into Response.
requestInfoExtractor and responseInfoExtractor have been merged into a single extraInfoExtractor, which takes a ExtraInfo => List[Any] function.
For more information on extraInfoExtractor, please refer to its documentation.

Logs
simulation.log has been redesigned.

If you wrote your own specific simulation.log parser, you’ll need to migrate it to the new structure.

Recorder
Until now, when setting up the Recorder, you had to setup two ports for the Recorder’s local proxy: one for HTTP, one for HTTPS. This is not needed anymore, as the Recorder handles itself the switch to an HTTPS connection if necessary, and only a single port needs to be specified.

Maven Plugin
The and configuration options have been removed. Should you want to select a specific simulation to run, you can use the config option to do so.

For more information, see the Maven plugin documentation.

从1.5迁移到2.0

全局变化
gatling至少需要JDK7u6

提供新jdk针对的是bug修复、优化速度和打开优化速度,gatling现在至少需要JDK7u6(大约两年前已经发布)。
Scala 2.10

gatling使用Scala 2.10。如果你使用Scala的IDE,确保您正在使用一个版本能与Scala 2.10兼容。
gatling现在可用在Maven中央库

galtling版本现在可以使用Maven中央,以及快照部署在每个成功构建了 Travis CI Sonatype快照存储库。如果你是使用gatling的Maven插件,您不再需要添加pom.xml Excilys存储库。

package和GroupId变化

gatling的groupId和package现在io.gatling组件。
你必须:
更新您的构建脚本改变从com.excilys.ebi groupId gatling的依赖关系。gatling,io.gatling更新你的模拟来代替com.excilys.ebi。io.gatling
更新你的模拟器来代替com.excilys.ebi.io.gatling部分通过引入io.gatling

akka.util.duration 类 已经移植到 scala.concurrent.duration 包中。简单从 import akka.util.duration. 替换到 import scala.concurrent.duration..

import bootstrap. 和 import assertions. 现在不是必须的,已经被移除.

import com.excilys.ebi.gatling.http.Headers.Names._ 现在不是必须的, headers 名字 直接使用HeaderNames.

import com.excilys.ebi.gatling.http.Headers.Values._ 现在不是必须的, headers 值 直接使用HeaderValues.

协议设置
协议已经不再配置场景,现在配置模拟器,使用协议的方法。

A 1.4.x-1.5.x 设置如下:

setUp(scn.(…).protocolConfig(httpConfig))
Gatling 2.0将会这样设置:

setUp(scn.(…)).protocols(httpConfig)

Assertions 设置

assertThat方法已经被移除,assertions配置使用assertions以相同的方式作为协议.如下

setup(scn.(…).protocolConfig(httpConfig))

assertThat(global.responseTime.max.lessThan(1000))

改变
setup(scn.(…))
.protocols(httpConfig)
.assertions(global.responseTime.max.lessThan(1000)
新的DSL语言注入

通过用户、增长和延迟来配置你的场景注入剖面的方法已被拆除,取而代之的是一个完整的专用的DSL。

注入步骤现在使用注射方法配置可用的配置。

合并 users

// With Gatling 1.5.X
setUp(scn.users(10)…)

// With Gatling 2.0
setUp(scn.inject(atOnceUsers(10))…
合并 ramp

// With Gatling 1.5.X
setUp(scn.users(10).ramp(30)…)

// With Gatling 2.0
setUp(scn.inject(rampUsers(10) over (30 seconds))…
合并 delay

// With Gatling 1.5.X
setUp(scn.users(10).delay(5)…)

// With Gatling 2.0
setUp(scn.inject(nothingFor(5 seconds), atOnceUsers(10))…

新注入的DSL的更多信息,请查阅注入DSL参考文档。

核心
Checks
whatever 现在被改名为 optional.

Structure Elements

The first parameter of foreach is now an Expression (e.g. a Gatling EL string), not the name of the attribute to loop over.

foreach现在是一个表达式的第一个参数(如gatling EL string),不是遍历属性的名称。

For example, if you have a list attribute in the user’s session holding a list of values:

例如,如果您有一个属性列表在用户的会话持有的值列表:

.foreach(“list”, “elem”) {

}
变为:

.foreach(“${list}”, “elem”) {

}
In asLongAs, exitASAP now defaults to true. For more information on the change of behaviour it introduces, see asLongAs documentation.

在 asLongAs exitASAP 现在默认设置是true.有关的行为改变的更多信息介绍,请看asLongAs文档。

Session

会话已经作为主要的重构:

session.get(“foobar”) becomes session(“foobar”)
session.getTypedAttributeT becomes session(“foobar”).as[T]
session.getAttributeAsOptionT becomes session(“foobar”).asOption[T]
session.setAttribute(“foobar”, 1234) becomes session.set(“foobar”, 1234)
session.setAttributes(Map(“foo” -> 1, “bar” -> 2) becomes session.setAll(“foo” -> 1, “bar” -> 2)
session.removeAttribute(“foobar”) becomes session.remove(“foobar”)
session.isAttributeDefined(“foobar”) becomes session.contains(“foobar”)

HTTP协议
HTTP协议启动加载器、httpProtocol已经更名为HTTP。
Query 参数
移除
版本的queryParam和multivaluedQueryParam,没有其他比的关键参数(解决会话中的值,使用关键的名字找到具有相同名称的属性)已被移除。

Modified

multivaluedFormParam现在可以解决直接从会话值,使用gatling的EL。

Request bodies

Scalate templates support has been dropped.
对Scalate templates 支持已经放弃。

ElFileBody (如下) 是当前代替Scalate templates最佳方案

api的请求体的设置意境改变。现在用这几个方法来代替body fileBody byteArrayBody.现在有一个单独的方法。body(…)通过你设置的类型的body来发送。
合并 .body(body)

body(body) 已经被 .body(StringBody(body))代替.

http(“my post request”)
.post(“http://www.example.org“)
.body(“Look Ma, I’m a request body !”)
变成:

http(“my post request”)
.post(“http://www.example.org“)
.body(StringBody(“Look Ma, I’m a request body !”))

合并 .fileBody(filePath)

.fileBody(filePath) 被 .body(RawFileBody(filePath))代替.

http(“my post request”)
.post(“http://www.example.org“)
.fileBody(“my_upload.xslx”)
becomes:

http(“my post request”)
.post(“http://www.example.org“)
.body(FileBody(“my_upload.xslx”))

合并 .fileBody(filePath, values)

.fileBody(filePath, values) 已经被 .body(ElFileBody(filePath))代替.
值现在直接解决虚拟用户会话的内容。

http(“my post request”)
.post(“http://www.example.org“)
.fileBody(“my_template.txt”, Map(“userName” -> “user123”)

变为

http(“my post request”)
.post(“http://www.example.org“)
.body(ElFileBody(“my template.txt”))

如果 template.txt 包含:

Hi, my name is ${userName}

和虚拟用户的会话属性的用户名设置为user123,

然后将发送有效地请求主体:
Hi, my name is user123

合并 .byteArrayBody(byteArray)

.byteArrayBody(byteArray) 被 .body(ByteArrayBody(bytes))代替.

http(“my post request”)
.post(“http://www.example.org“)
.byteArrayBody(Array(1, 2, 3, 4))

变为:

http(“my post request”)
.post(“http://www.example.org“)
.body(ByteArrayBody(Array(1, 2, 3, 4)))

更多有关信息,请参见请求机构引用部分。

Misc
ExtendedResponse已经重命名为响应。requestInfoExtractor和responseInfoExtractor已经合并成一个单一的extraInfoExtractor,ExtraInfo => List[Any] function.。
在extraInfoExtractor的更多信息,请参阅文档。

Logs
simulation.log 被重新设计。

If you wrote your own specific simulation.log parser, you’ll need to migrate it to the new structure.
如果你写自己的simulation.log解析器,您需要它迁移到新结构

Recorder
录制器
Until now, 当你设置 Recorder时, 你必须设置两个端口记录器的当地代理:一个用于HTTP,HTTPS。 这再也不需要了, 因为record处理本身转向一个HTTPS连接如果必要,并且只需要指定一个单独的端口。