@gatling.io/core 3.11.7 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/jest.config.js +5 -0
  2. package/package.json +3 -3
  3. package/src/assertions.ts +305 -0
  4. package/src/body.ts +211 -0
  5. package/src/checks/builder.ts +14 -0
  6. package/src/checks/captureGroup.ts +22 -0
  7. package/src/checks/condition.ts +24 -0
  8. package/src/checks/final.ts +31 -0
  9. package/src/checks/find.ts +23 -0
  10. package/src/checks/index.ts +540 -0
  11. package/src/checks/jsonOfTypeFind.ts +81 -0
  12. package/src/checks/jsonOfTypeMultipleFind.ts +84 -0
  13. package/src/checks/multipleFind.ts +87 -0
  14. package/src/checks/validate.ts +336 -0
  15. package/src/closedInjection.ts +182 -0
  16. package/src/common.ts +3 -0
  17. package/src/feeders.ts +279 -0
  18. package/src/filters.ts +49 -0
  19. package/src/gatlingJvm/app.ts +5 -0
  20. package/src/gatlingJvm/byteArrays.ts +14 -0
  21. package/src/gatlingJvm/collections.ts +28 -0
  22. package/src/globalStore.ts +104 -0
  23. package/src/index.test.ts +543 -0
  24. package/src/index.ts +158 -0
  25. package/src/openInjection.ts +286 -0
  26. package/src/parameters.ts +38 -0
  27. package/src/population.ts +105 -0
  28. package/src/protocol.ts +5 -0
  29. package/src/scenario.ts +37 -0
  30. package/src/session.ts +182 -0
  31. package/src/structure/asLongAs.ts +121 -0
  32. package/src/structure/asLongAsDuring.ts +337 -0
  33. package/src/structure/choices.ts +41 -0
  34. package/src/structure/doIf.ts +140 -0
  35. package/src/structure/doIfOrElse.ts +160 -0
  36. package/src/structure/doSwitch.ts +46 -0
  37. package/src/structure/doSwitchOrElse.ts +61 -0
  38. package/src/structure/doWhile.ts +53 -0
  39. package/src/structure/doWhileDuring.ts +337 -0
  40. package/src/structure/during.ts +182 -0
  41. package/src/structure/errors.ts +266 -0
  42. package/src/structure/execs.ts +66 -0
  43. package/src/structure/feeds.ts +62 -0
  44. package/src/structure/forEach.ts +68 -0
  45. package/src/structure/forever.ts +25 -0
  46. package/src/structure/groups.ts +23 -0
  47. package/src/structure/index.ts +130 -0
  48. package/src/structure/jvmStructureBuilder.ts +52 -0
  49. package/src/structure/on.ts +20 -0
  50. package/src/structure/paces.ts +156 -0
  51. package/src/structure/pauses.ts +211 -0
  52. package/src/structure/randomSwitch.ts +34 -0
  53. package/src/structure/randomSwitchOrElse.ts +45 -0
  54. package/src/structure/rendezVous.ts +23 -0
  55. package/src/structure/repeat.ts +64 -0
  56. package/src/structure/roundRobinSwitch.ts +34 -0
  57. package/src/structure/uniformRandomSwitch.ts +34 -0
  58. package/src/throttling.ts +67 -0
  59. package/src/utils/duration.ts +28 -0
  60. package/target/structure/errors.d.ts +70 -10
  61. package/target/structure/errors.js +29 -8
  62. package/target/structure/index.d.ts +4 -2
  63. package/target/structure/index.js +5 -3
  64. package/tsconfig.json +18 -0
@@ -0,0 +1,286 @@
1
+ import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";
2
+
3
+ import { Duration, toJvmDuration } from "./utils/duration";
4
+ import { Wrapper } from "./common";
5
+
6
+ import JvmOpenInjectionStep = io.gatling.javaapi.core.OpenInjectionStep;
7
+ import JvmOpenInjectionStepRamp = io.gatling.javaapi.core.OpenInjectionStep$Ramp;
8
+ import JvmOpenInjectionStepStressPeak = io.gatling.javaapi.core.OpenInjectionStep$StressPeak;
9
+ import JvmOpenInjectionStepConstantRate = io.gatling.javaapi.core.OpenInjectionStep$ConstantRate;
10
+ import JvmOpenInjectionStepConstantRateConstantRateOpenInjectionStep = io.gatling.javaapi.core.ConstantRate$ConstantRateOpenInjectionStep;
11
+ import JvmOpenInjectionStepRampRate = io.gatling.javaapi.core.OpenInjectionStep$RampRate;
12
+ import JvmOpenInjectionStepRampRateDuring = io.gatling.javaapi.core.RampRate$During;
13
+ import JvmOpenInjectionStepRampRateRampRateOpenInjectionStep = io.gatling.javaapi.core.RampRate$RampRateOpenInjectionStep;
14
+ import JvmOpenInjectionStepStairs = io.gatling.javaapi.core.OpenInjectionStep$Stairs;
15
+ import JvmOpenInjectionStepStairsTimes = io.gatling.javaapi.core.Stairs$Times;
16
+ import JvmOpenInjectionStepStairsComposite = io.gatling.javaapi.core.Stairs$Composite;
17
+
18
+ /**
19
+ * An injection profile step for using an open workload model where you control the arrival rate of
20
+ * new users. In 99.99% of the cases, the right choice, over closed workload model.
21
+ *
22
+ * <p>Immutable, so all methods return a new occurrence and leave the original unmodified.
23
+ */
24
+ export interface OpenInjectionStep extends Wrapper<JvmOpenInjectionStep> {}
25
+
26
+ const wrapOpenInjectionStep = (_underlying: JvmOpenInjectionStep): OpenInjectionStep => ({ _underlying });
27
+
28
+ export interface ConstantRateOpenInjectionStep extends OpenInjectionStep {
29
+ randomized(): OpenInjectionStep;
30
+ }
31
+
32
+ const wrapConstantRateOpenInjectionStep = (
33
+ _underlying: JvmOpenInjectionStepConstantRateConstantRateOpenInjectionStep
34
+ ): ConstantRateOpenInjectionStep => ({
35
+ _underlying,
36
+ randomized: () => wrapOpenInjectionStep(_underlying.randomized())
37
+ });
38
+
39
+ /**
40
+ * A DSL for creating a {@link OpenInjectionStep} that will inject a stock of users distributed
41
+ * evenly on a given period of time. Strictly equivalent to {@link ConstantRateOpenInjectionStep}
42
+ */
43
+ export interface OpenInjectionStepRamp extends Wrapper<JvmOpenInjectionStepRamp> {
44
+ /**
45
+ * Define the duration of the ramp
46
+ *
47
+ * @param duration - the ramp duration
48
+ * @returns a new OpenInjectionStep
49
+ */
50
+ during(duration: Duration): OpenInjectionStep;
51
+ }
52
+
53
+ const wrapOpenInjectionStepRamp = (_underlying: JvmOpenInjectionStepRamp): OpenInjectionStepRamp => ({
54
+ _underlying,
55
+ during: (duration: Duration) => wrapOpenInjectionStep(_underlying.during(toJvmDuration(duration)))
56
+ });
57
+
58
+ /**
59
+ * A DSL for creating a {@link OpenInjectionStep} that will inject a stock of users distributed
60
+ * with a <a hreh="https://en.wikipedia.org/wiki/Heaviside_step_function">Heaviside</a>
61
+ * distribution on a given period of time. Strictly equivalent to {@link OpenInjectionStepConstantRate}
62
+ */
63
+ export interface OpenInjectionStepStressPeak extends Wrapper<JvmOpenInjectionStepStressPeak> {
64
+ /**
65
+ * Define the duration of the Heaviside distribution
66
+ *
67
+ * @param duration - the duration
68
+ * @returns a new OpenInjectionStep
69
+ */
70
+ during(duration: Duration): OpenInjectionStep;
71
+ }
72
+
73
+ const wrapOpenInjectionStepStressPeak = (_underlying: JvmOpenInjectionStepStressPeak): OpenInjectionStepStressPeak => ({
74
+ _underlying,
75
+ during: (duration: Duration) => wrapOpenInjectionStep(_underlying.during(toJvmDuration(duration)))
76
+ });
77
+
78
+ /**
79
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users at a constant rate for a
80
+ * given duration.
81
+ */
82
+ export interface OpenInjectionStepConstantRate extends Wrapper<JvmOpenInjectionStepConstantRate> {
83
+ /**
84
+ * Define the duration of the step
85
+ *
86
+ * @param duration - the duration
87
+ * @returns a new OpenInjectionStep
88
+ */
89
+ during(duration: Duration): ConstantRateOpenInjectionStep;
90
+ }
91
+
92
+ const wrapOpenInjectionStepConstantRate = (
93
+ _underlying: JvmOpenInjectionStepConstantRate
94
+ ): OpenInjectionStepConstantRate => ({
95
+ _underlying,
96
+ during: (duration: Duration) => wrapConstantRateOpenInjectionStep(_underlying.during(toJvmDuration(duration)))
97
+ });
98
+
99
+ /**
100
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users at a rate that will
101
+ * increase linearly for a given duration.
102
+ */
103
+ export interface OpenInjectionStepRampRate extends Wrapper<JvmOpenInjectionStepRampRate> {
104
+ /**
105
+ * Define the target rate at the end of the ramp
106
+ *
107
+ * @param to - the target rate
108
+ * @returns the next DSL step
109
+ */
110
+ to(to: number): OpenInjectionStepRampRateDuring;
111
+ }
112
+
113
+ const wrapOpenInjectionStepRampRate = (_underlying: JvmOpenInjectionStepRampRate): OpenInjectionStepRampRate => ({
114
+ _underlying,
115
+ to: (to: number) => wrapOpenInjectionStepRampRateDuring(_underlying.to(to))
116
+ });
117
+
118
+ /**
119
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users at a rate that will
120
+ * increase linearly for a given duration.
121
+ */
122
+ export interface OpenInjectionStepRampRateDuring extends Wrapper<JvmOpenInjectionStepRampRateDuring> {
123
+ /**
124
+ * Define the duration of the ramp
125
+ *
126
+ * @param duration - the duration
127
+ * @returns a new OpenInjectionStep
128
+ */
129
+ during(duration: Duration): RampRateOpenInjectionStep;
130
+ }
131
+
132
+ const wrapOpenInjectionStepRampRateDuring = (
133
+ _underlying: JvmOpenInjectionStepRampRateDuring
134
+ ): OpenInjectionStepRampRateDuring => ({
135
+ _underlying,
136
+ during: (duration: Duration) => wrapRampRateOpenInjectionStep(_underlying.during(toJvmDuration(duration)))
137
+ });
138
+
139
+ /**
140
+ * A special {@link OpenInjectionStep} that supports "randomized".
141
+ */
142
+ export interface RampRateOpenInjectionStep extends OpenInjectionStep {
143
+ randomized(): OpenInjectionStep;
144
+ }
145
+
146
+ const wrapRampRateOpenInjectionStep = (
147
+ _underlying: JvmOpenInjectionStepRampRateRampRateOpenInjectionStep
148
+ ): ConstantRateOpenInjectionStep => ({
149
+ _underlying,
150
+ randomized: () => wrapOpenInjectionStep(_underlying.randomized())
151
+ });
152
+
153
+ /**
154
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users with stairs rates.
155
+ */
156
+ export interface OpenInjectionStepStairs extends Wrapper<JvmOpenInjectionStepStairs> {
157
+ /**
158
+ * Define the number of levels
159
+ *
160
+ * @param levels - the number of levels in the stairs
161
+ * @returns the next DSL step
162
+ */
163
+ times(levels: number): OpenInjectionStepStairsTimes;
164
+ }
165
+
166
+ const wrapOpenInjectionStepStairs = (_underlying: JvmOpenInjectionStepStairs): OpenInjectionStepStairs => ({
167
+ _underlying,
168
+ times: (levels: number) => wrapOpenInjectionStepStairsTimes(_underlying.times(levels))
169
+ });
170
+
171
+ /**
172
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users with stairs rates.
173
+ */
174
+ export interface OpenInjectionStepStairsTimes extends Wrapper<JvmOpenInjectionStepStairsTimes> {
175
+ /**
176
+ * Define the duration of each level
177
+ *
178
+ * @param duration - the duration
179
+ * @returns the next DSL step
180
+ */
181
+ eachLevelLasting(duration: Duration): OpenInjectionStepStairsComposite;
182
+ }
183
+
184
+ const wrapOpenInjectionStepStairsTimes = (
185
+ _underlying: JvmOpenInjectionStepStairsTimes
186
+ ): OpenInjectionStepStairsTimes => ({
187
+ _underlying,
188
+ eachLevelLasting: (duration: Duration) =>
189
+ wrapOpenInjectionStepStairsComposite(_underlying.eachLevelLasting(toJvmDuration(duration)))
190
+ });
191
+
192
+ /**
193
+ * A DSL for creating a {@link OpenInjectionStep} that will inject users with stairs rates.
194
+ */
195
+ export interface OpenInjectionStepStairsComposite extends OpenInjectionStep {
196
+ /**
197
+ * Define the initial number of users per second rate (optional)
198
+ *
199
+ * @param startingRate - the initial rate
200
+ * @returns a usable {@link OpenInjectionStep}
201
+ */
202
+ startingFrom(startingRate: number): OpenInjectionStepStairsComposite;
203
+
204
+ /**
205
+ * Define ramps separating levels (optional)
206
+ *
207
+ * @param duration - the duration
208
+ * @returns a usable {@link OpenInjectionStep}
209
+ */
210
+ separatedByRampsLasting(duration: Duration): OpenInjectionStepStairsComposite;
211
+ }
212
+
213
+ const wrapOpenInjectionStepStairsComposite = (
214
+ _underlying: JvmOpenInjectionStepStairsComposite
215
+ ): OpenInjectionStepStairsComposite => ({
216
+ _underlying,
217
+ startingFrom: (startingRate: number) => wrapOpenInjectionStepStairsComposite(_underlying.startingFrom(startingRate)),
218
+ separatedByRampsLasting: (duration: Duration) =>
219
+ wrapOpenInjectionStepStairsComposite(_underlying.separatedByRampsLasting(toJvmDuration(duration)))
220
+ });
221
+
222
+ /**
223
+ * Bootstrap a new open workload rampUsers injection profile, see {@link OpenInjectionStepRamp}
224
+ *
225
+ * @param users - the total number of users to inject
226
+ * @returns the next DSL step
227
+ */
228
+ export const rampUsers = (users: number): OpenInjectionStepRamp =>
229
+ wrapOpenInjectionStepRamp(JvmCoreDsl.rampUsers(users));
230
+
231
+ /**
232
+ * Bootstrap a new open workload stress peak injection profile, see {@link
233
+ * OpenInjectionStepStressPeak}
234
+ *
235
+ * @param users - the total number of users to inject
236
+ * @returns the next DSL step
237
+ */
238
+ export const stressPeakUsers = (users: number): OpenInjectionStepStressPeak =>
239
+ wrapOpenInjectionStepStressPeak(JvmCoreDsl.stressPeakUsers(users));
240
+
241
+ /**
242
+ * Inject a bunch of users at the same time.
243
+ *
244
+ * @param users - the number of users to inject
245
+ * @returns a new OpenInjectionStep
246
+ */
247
+ export const atOnceUsers = (users: number): OpenInjectionStep => wrapOpenInjectionStep(JvmCoreDsl.atOnceUsers(users));
248
+
249
+ /**
250
+ * Bootstrap a new open workload constantUsersPerSec injection profile, see {@link
251
+ * OpenInjectionStepConstantRate}
252
+ *
253
+ * @param rate - the users per second rate
254
+ * @returns the next DSL step
255
+ */
256
+ export const constantUsersPerSec = (rate: number): OpenInjectionStepConstantRate =>
257
+ wrapOpenInjectionStepConstantRate(JvmCoreDsl.constantUsersPerSec(rate));
258
+
259
+ /**
260
+ * Bootstrap a new open workload rampUsersPerSec injection profile, see {@link
261
+ * OpenInjectionStepRampRate}
262
+ *
263
+ * @param rate - the users per second start rate
264
+ * @returns the next DSL step
265
+ */
266
+ export const rampUsersPerSec = (rate: number): OpenInjectionStepRampRate =>
267
+ wrapOpenInjectionStepRampRate(JvmCoreDsl.rampUsersPerSec(rate));
268
+
269
+ /**
270
+ * Don't inject any new user for a given duration
271
+ *
272
+ * @param duration - the duration
273
+ * @returns a new OpenInjectionStep
274
+ */
275
+ export const nothingFor = (duration: Duration): OpenInjectionStep =>
276
+ wrapOpenInjectionStep(JvmCoreDsl.nothingFor(toJvmDuration(duration)));
277
+
278
+ /**
279
+ * Bootstrap a new open workload incrementUsersPerSec injection profile, see {@link
280
+ * OpenInjectionStepStairs}
281
+ *
282
+ * @param rateIncrement - the difference of users per second rate between levels of the stairs
283
+ * @returns the next DSL step
284
+ */
285
+ export const incrementUsersPerSec = (rateIncrement: number): OpenInjectionStepStairs =>
286
+ wrapOpenInjectionStepStairs(JvmCoreDsl.incrementUsersPerSec(rateIncrement));
@@ -0,0 +1,38 @@
1
+ import { System as JvmSystem } from "@gatling.io/jvm-types";
2
+
3
+ export interface GetWithDefault {
4
+ (name: string): string | undefined;
5
+ (name: string, defaultValue: string): string;
6
+ }
7
+
8
+ /**
9
+ * Gets the parameter indicated by the specified name.
10
+ *
11
+ * Parameters can be specified in the `gatling run` command by passing arguments with the format `key=value`, e.g.
12
+ * `gatling run parameter1=foo parameter2=bar`. You would then retrieve them in your simulation by calling
13
+ * `getParameter("parameter1")` and `getParameter("parameter2")`.
14
+ *
15
+ * @param key - the key of the parameter.
16
+ * @param defaultValue - a default value
17
+ * @returns the string value of the parameter if it is defined, or else `defaultValue` if provided, or else `undefined`.
18
+ */
19
+ export const getParameter: GetWithDefault = (key: string, defaultValue?: string) =>
20
+ getOrElse(JvmSystem.getProperty(key), defaultValue) as any;
21
+
22
+ /**
23
+ * @deprecated Use {@link getParameter} instead.
24
+ */
25
+ export const getOption: GetWithDefault = getParameter;
26
+
27
+ /**
28
+ * Gets the environment variable indicated by the specified name.
29
+ *
30
+ * @param name - the name of the environment variable.
31
+ * @param defaultValue - a default value
32
+ * @returns the string value of the environment variable if it is defined, or else `defaultValue` if provided, or else `undefined`.
33
+ */
34
+ export const getEnvironmentVariable: GetWithDefault = (name: string, defaultValue?: string) =>
35
+ getOrElse(JvmSystem.getenv(name), defaultValue) as any;
36
+
37
+ const getOrElse = (value: string | null, defaultValue?: string): string | undefined =>
38
+ typeof value === "string" ? value : defaultValue;
@@ -0,0 +1,105 @@
1
+ import { Duration, toJvmDuration } from "./utils/duration";
2
+ import { PauseType, toJvmPauseType } from "./structure/pauses";
3
+ import { Wrapper } from "./common";
4
+ import { ProtocolBuilder } from "./protocol";
5
+ import { SessionTo, underlyingSessionTo } from "./session";
6
+ import { ThrottleStep } from "./throttling";
7
+
8
+ import JvmPopulationBuilder = io.gatling.javaapi.core.PopulationBuilder;
9
+
10
+ /**
11
+ * A builder for a Population = a Scenario + an injection profile.
12
+ *
13
+ * Immutable, meaning each method doesn't mutate the current instance but return a new one.
14
+ */
15
+ export interface PopulationBuilder extends Wrapper<JvmPopulationBuilder> {
16
+ /**
17
+ * Define the optional protocols for this PopulationBuilder
18
+ *
19
+ * @param protocols - the protocols
20
+ * @returns a new PopulationBuilder
21
+ */
22
+ protocols(...protocols: ProtocolBuilder[]): PopulationBuilder;
23
+
24
+ /**
25
+ * Define some other PopulationBuilder to be executed once all the users of this PopulationBuilder
26
+ * complete their Scenario.
27
+ *
28
+ * @param children - the children PopulationBuilder
29
+ * @returns a new PopulationBuilder
30
+ */
31
+ andThen(...children: PopulationBuilder[]): PopulationBuilder;
32
+
33
+ /**
34
+ * Disable the pauses
35
+ *
36
+ * @return a new PopulationBuilder
37
+ */
38
+ disablePauses(): PopulationBuilder;
39
+
40
+ /**
41
+ * Use constant pauses
42
+ *
43
+ * @return a new PopulationBuilder
44
+ */
45
+ constantPauses(): PopulationBuilder;
46
+
47
+ /**
48
+ * Use exponential pauses
49
+ *
50
+ * @return a new PopulationBuilder
51
+ */
52
+ exponentialPauses(): PopulationBuilder;
53
+
54
+ /**
55
+ * Use custom pauses
56
+ *
57
+ * @return a new PopulationBuilder
58
+ */
59
+ customPauses(f: SessionTo<number>): PopulationBuilder;
60
+
61
+ /**
62
+ * Use uniform pauses with a standard deviation percentage
63
+ *
64
+ * @return a new PopulationBuilder
65
+ */
66
+ uniformPauses(plusOrMinus: Duration): PopulationBuilder;
67
+
68
+ /**
69
+ * Use pauses configured with a given strategy
70
+ *
71
+ * @param pauseType the pause type
72
+ * @return a new PopulationBuilder
73
+ */
74
+ pauses(pauseType: PauseType): PopulationBuilder;
75
+
76
+ /**
77
+ * Define the optional throttling profile
78
+ *
79
+ * @param throttleSteps the throttling profile steps
80
+ * @return a new PopulationBuilder
81
+ */
82
+ throttle(...throttleSteps: ThrottleStep[]): PopulationBuilder;
83
+
84
+ /**
85
+ * Disable the injection profile sharding that happens normally when running with Gatling
86
+ * Enterprise. Only effective when the test is running with Gatling Enterprise, noop otherwise.
87
+ *
88
+ * @return a new PopulationBuilder
89
+ */
90
+ noShard(): PopulationBuilder;
91
+ }
92
+
93
+ export const wrapPopulationBuilder = (_underlying: JvmPopulationBuilder): PopulationBuilder => ({
94
+ _underlying,
95
+ protocols: (...protocols) => wrapPopulationBuilder(_underlying.protocols(protocols.map((p) => p._underlying))),
96
+ andThen: (...children) => wrapPopulationBuilder(_underlying.andThen(children.map((c) => c._underlying))),
97
+ disablePauses: () => wrapPopulationBuilder(_underlying.disablePauses()),
98
+ constantPauses: () => wrapPopulationBuilder(_underlying.constantPauses()),
99
+ exponentialPauses: () => wrapPopulationBuilder(_underlying.exponentialPauses()),
100
+ customPauses: (f) => wrapPopulationBuilder(_underlying.customPauses(underlyingSessionTo(f))),
101
+ uniformPauses: (plusOrMinus) => wrapPopulationBuilder(_underlying.uniformPauses(toJvmDuration(plusOrMinus))),
102
+ pauses: (pauseType) => wrapPopulationBuilder(_underlying.pauses(toJvmPauseType(pauseType))),
103
+ throttle: (...throttleSteps) => wrapPopulationBuilder(_underlying.throttle(throttleSteps.map((t) => t._underlying))),
104
+ noShard: () => wrapPopulationBuilder(_underlying.noShard())
105
+ });
@@ -0,0 +1,5 @@
1
+ import { Wrapper } from "./common";
2
+
3
+ import JvmProtocolBuilder = io.gatling.javaapi.core.ProtocolBuilder;
4
+
5
+ export interface ProtocolBuilder extends Wrapper<JvmProtocolBuilder> {}
@@ -0,0 +1,37 @@
1
+ import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";
2
+
3
+ import { ClosedInjectionStep } from "./closedInjection";
4
+ import { OpenInjectionStep } from "./openInjection";
5
+ import { PopulationBuilder, wrapPopulationBuilder } from "./population";
6
+ import { StructureBuilder, structureBuilderImpl } from "./structure";
7
+
8
+ import JvmScenarioBuilder = io.gatling.javaapi.core.ScenarioBuilder;
9
+
10
+ /**
11
+ * Javascript wrapper of a Java ScenarioBuilder.
12
+ *
13
+ * <p>Immutable, so all methods return a new occurrence and leave the original unmodified.
14
+ */
15
+ export interface ScenarioBuilder extends StructureBuilder<ScenarioBuilder> {
16
+ injectOpen(...steps: OpenInjectionStep[]): PopulationBuilder;
17
+ injectClosed(...steps: ClosedInjectionStep[]): PopulationBuilder;
18
+ }
19
+
20
+ const wrapScenarioBuilder = (jvmScenarioBuilder: JvmScenarioBuilder): ScenarioBuilder => ({
21
+ injectOpen: (...steps: OpenInjectionStep[]): PopulationBuilder =>
22
+ wrapPopulationBuilder(jvmScenarioBuilder.injectOpen(steps.map((s) => s._underlying))),
23
+ injectClosed: (...steps: ClosedInjectionStep[]): PopulationBuilder =>
24
+ wrapPopulationBuilder(jvmScenarioBuilder.injectClosed(steps.map((s) => s._underlying))),
25
+ ...structureBuilderImpl(jvmScenarioBuilder, wrapScenarioBuilder)
26
+ });
27
+
28
+ /**
29
+ * Create a new immutable Scenario builder
30
+ *
31
+ * @param name - the scenario name
32
+ * @returns a new Scenario builder
33
+ */
34
+ export const scenario = (name: string): ScenarioBuilder => {
35
+ const jvmScenarioBuilder = JvmCoreDsl.scenario(name);
36
+ return wrapScenarioBuilder(jvmScenarioBuilder);
37
+ };
package/src/session.ts ADDED
@@ -0,0 +1,182 @@
1
+ import { asByteArray } from "./gatlingJvm/byteArrays";
2
+ import { asJava } from "./gatlingJvm/collections";
3
+ import { Duration, toJvmDuration } from "./utils/duration";
4
+ import { Wrapper } from "./common";
5
+
6
+ import JvmSession = io.gatling.javaapi.core.Session;
7
+
8
+ /**
9
+ * The state of a given virtual user.
10
+ *
11
+ * <p>Immutable, so all methods return a new occurrence and leave the original unmodified.
12
+ */
13
+ export interface Session extends Wrapper<JvmSession> {
14
+ /**
15
+ * Get a stored value by its key
16
+ *
17
+ * @param key - the storage key
18
+ * @typeParam T - the type of the desired value
19
+ * @returns the value if it exists, null otherwise
20
+ */
21
+ get<T>(key: string): T;
22
+
23
+ /**
24
+ * Create a new instance updated with a given attribute, possibly overriding an existing one
25
+ *
26
+ * @param key - the attribute key
27
+ * @param value - the attribute value
28
+ * @returns a new instance with the new stored attribute
29
+ */
30
+ set(key: string, value: any): Session;
31
+
32
+ /**
33
+ * Create a new instance updated with a given byte array (number[]), possibly overriding an existing one
34
+ *
35
+ * @param key - the attribute key
36
+ * @param value - the attribute value
37
+ * @returns a new instance with the new stored attribute
38
+ */
39
+ setByteArray(key: string, value: number[]): Session;
40
+
41
+ /**
42
+ * Create a new instance updated with multiple attributes, possibly overriding existing ones
43
+ *
44
+ * @param newAttributes - the new attributes
45
+ * @returns a new instance with the new stored attributes
46
+ */
47
+ setAll(newAttributes: Record<string, any>): Session;
48
+
49
+ /**
50
+ * Create a new instance updated with an attribute removed
51
+ *
52
+ * @param key - the key of the attribute to remove
53
+ * @returns a new instance with the attribute removed
54
+ */
55
+ remove(key: string): Session;
56
+
57
+ /**
58
+ * Create a new instance updated with all attributes removed except Gatling internal ones
59
+ *
60
+ * @returns a new instance with a reset user state
61
+ */
62
+ reset(): Session;
63
+
64
+ /**
65
+ * Create a new instance updated with multiple attributes removed
66
+ *
67
+ * @param keys - the keys of the attributes to remove
68
+ * @returns a new instance with the attributes removed
69
+ */
70
+ removeAll(...keys: string[]): Session;
71
+
72
+ /**
73
+ * Check if the Session contains a given attribute key
74
+ *
75
+ * @param key - the attribute key
76
+ * @returns true is the key is defined
77
+ */
78
+ contains(key: string): boolean;
79
+
80
+ /**
81
+ * @returns if the Session's status is failure
82
+ */
83
+ isFailed(): boolean;
84
+
85
+ /**
86
+ * Create a new instance with the status forced to "succeeded"
87
+ *
88
+ * @returns a new instance with the new status
89
+ */
90
+ markAsSucceeded(): Session;
91
+
92
+ /**
93
+ * Create a new instance with the status forced to "failed"
94
+ *
95
+ * @returns a new instance with the new status
96
+ */
97
+ markAsFailed(): Session;
98
+
99
+ /**
100
+ * Provide the name of the scenario of the virtual user
101
+ *
102
+ * @returns the virtual user's scenario name
103
+ */
104
+ scenario(): string;
105
+
106
+ /**
107
+ * Provide the list of groups at the current position for the virtual user
108
+ *
109
+ * @returns the list of groups, from shallowest to deepest
110
+ */
111
+ groups(): string[];
112
+
113
+ /**
114
+ * Provide the unique (for this injector) id of the virtual user
115
+ *
116
+ * @returns the virtual user's id
117
+ */
118
+ userId(): number;
119
+
120
+ /**
121
+ * Provide a representation of the Session content
122
+ *
123
+ * @returns the Session content as a pretty printed string
124
+ */
125
+ toString(): string;
126
+ }
127
+
128
+ export const wrapSession = (_underlying: JvmSession): Session => ({
129
+ _underlying,
130
+ get: <T>(key: string): T => _underlying.get(key),
131
+ set: (key: string, value: any): Session => {
132
+ return wrapSession(_underlying.set(key, asJava(value)));
133
+ },
134
+ setByteArray: (key: string, value: number[]): Session => wrapSession(_underlying.set(key, asByteArray(value))),
135
+ setAll: (newAttributes: Record<string, any>): Session => {
136
+ let session = _underlying;
137
+ for (const key in newAttributes) {
138
+ session = session.set(key, asJava(newAttributes[key]));
139
+ }
140
+ return wrapSession(session);
141
+ },
142
+ remove: (key: string): Session => wrapSession(_underlying.remove(key)),
143
+ reset: (): Session => wrapSession(_underlying.reset()),
144
+ removeAll: (...keys: string[]): Session => wrapSession(_underlying.removeAll(...keys)),
145
+ contains: (key: string): boolean => _underlying.contains(key),
146
+ isFailed: (): boolean => _underlying.isFailed(),
147
+ markAsSucceeded: (): Session => wrapSession(_underlying.markAsSucceeded()),
148
+ markAsFailed: (): Session => wrapSession(_underlying.markAsFailed()),
149
+ scenario: (): string => _underlying.scenario(),
150
+ groups: (): string[] => _underlying.groups(),
151
+ userId: (): number => _underlying.userId(),
152
+ toString: (): string => _underlying.toString()
153
+ });
154
+
155
+ export type Expression<T> = T | ((session: Session) => T);
156
+
157
+ export type SessionTransform = (session: Session) => Session;
158
+ export const underlyingSessionTransform =
159
+ (f: SessionTransform): ((jvmSession: JvmSession) => JvmSession) =>
160
+ (jvmSession: JvmSession) =>
161
+ f(wrapSession(jvmSession))._underlying;
162
+
163
+ export type SessionTo<T> = (session: Session) => T;
164
+ export const underlyingSessionTo =
165
+ <T>(f: SessionTo<T>): ((jvmSession: JvmSession) => T) =>
166
+ (jvmSession: JvmSession) =>
167
+ f(wrapSession(jvmSession));
168
+
169
+ export const underlyingSessionToJava =
170
+ <T>(f: SessionTo<T>): ((jvmSession: JvmSession) => unknown) =>
171
+ (jvmSession: JvmSession) =>
172
+ asJava(f(wrapSession(jvmSession)));
173
+
174
+ export const underlyingSessionToDuration =
175
+ (f: SessionTo<Duration>): ((jvmSession: JvmSession) => java.time.Duration) =>
176
+ (jvmSession: JvmSession) =>
177
+ toJvmDuration(f(wrapSession(jvmSession)));
178
+
179
+ export const underlyingXWithSessionTo =
180
+ <X, X2>(f: (x: X, session: Session) => X2): ((x: X, jvmSession: JvmSession) => X2) =>
181
+ (x: X, jvmSession: JvmSession) =>
182
+ f(x, wrapSession(jvmSession));