@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,23 @@
1
+ import JvmGroups = io.gatling.javaapi.core.group.Groups;
2
+
3
+ import { SessionTo, underlyingSessionTo } from "../session";
4
+ import { On, wrapOn } from "./on";
5
+
6
+ export interface GroupFunction<T extends Groups<T>> {
7
+ /**
8
+ * Define a group
9
+ *
10
+ * @param name - the name of the group, expressed as a Gatling Expression Language String or a function
11
+ * @returns a DSL component for defining the wrapped block
12
+ */
13
+ (name: string | SessionTo<string>): On<T>;
14
+ }
15
+
16
+ export interface Groups<T extends Groups<T>> {
17
+ group: GroupFunction<T>;
18
+ }
19
+
20
+ export const groupImpl =
21
+ <J2, J1 extends JvmGroups<J2, any>, T extends Groups<T>>(jvmGroups: J1, wrap: (wrapped: J2) => T): GroupFunction<T> =>
22
+ (group: string | SessionTo<string>) =>
23
+ wrapOn(typeof group === "function" ? jvmGroups.group(underlyingSessionTo(group)) : jvmGroups.group(group), wrap);
@@ -0,0 +1,130 @@
1
+ import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";
2
+
3
+ import JvmChainBuilder = io.gatling.javaapi.core.ChainBuilder;
4
+
5
+ import { JvmStructureBuilderLike } from "./jvmStructureBuilder";
6
+ import { ExecFunction, Execs, execImpl, Executable } from "./execs";
7
+ import { GroupFunction, Groups, groupImpl } from "./groups";
8
+ import { FeedFunction, Feeds, feedImpl } from "./feeds";
9
+ import { PauseFunction, Pauses, pauseImpl } from "./pauses";
10
+ import { Paces, paceImpl } from "./paces";
11
+ import { RendezVous, rendezVousImpl } from "./rendezVous";
12
+ import { Repeat, repeatImpl } from "./repeat";
13
+ import { ForEach, foreachImpl } from "./forEach";
14
+ import { During, duringImpl } from "./during";
15
+ import { Forever, foreverImpl } from "./forever";
16
+ import { AsLongAs, asLongAsImpl } from "./asLongAs";
17
+ import { DoWhile, doWhileImpl } from "./doWhile";
18
+ import { AsLongAsDuring, asLongAsDuringImpl } from "./asLongAsDuring";
19
+ import { DoWhileDuring, doWhileDuringImpl } from "./doWhileDuring";
20
+ import { DoIf, DoIfEquals, doIfImpl, doIfEqualsImpl } from "./doIf";
21
+ import { DoIfOrElse, DoIfEqualsOrElse, doIfOrElseImpl, doIfEqualsOrElseImpl } from "./doIfOrElse";
22
+ import { DoSwitch, doSwitchImpl } from "./doSwitch";
23
+ import { DoSwitchOrElse, doSwitchOrElseImpl } from "./doSwitchOrElse";
24
+ import { RandomSwitch, randomSwitchImpl } from "./randomSwitch";
25
+ import { RandomSwitchOrElse, randomSwitchOrElseImpl } from "./randomSwitchOrElse";
26
+ import { UniformRandomSwitch, uniformRandomSwitchImpl } from "./uniformRandomSwitch";
27
+ import { RoundRobinSwitch, roundRobinSwitchImpl } from "./roundRobinSwitch";
28
+ import { Errors, errorsImpl } from "./errors";
29
+
30
+ export interface StructureBuilder<T extends StructureBuilder<T>>
31
+ extends Execs<T>,
32
+ Groups<T>,
33
+ Feeds<T>,
34
+ Pauses<T>,
35
+ Paces<T>,
36
+ RendezVous<T>,
37
+ Repeat<T>,
38
+ ForEach<T>,
39
+ During<T>,
40
+ Forever<T>,
41
+ AsLongAs<T>,
42
+ DoWhile<T>,
43
+ AsLongAsDuring<T>,
44
+ DoWhileDuring<T>,
45
+ DoIf<T>,
46
+ DoIfOrElse<T>,
47
+ DoIfEquals<T>,
48
+ DoIfEqualsOrElse<T>,
49
+ DoSwitch<T>,
50
+ DoSwitchOrElse<T>,
51
+ RandomSwitch<T>,
52
+ RandomSwitchOrElse<T>,
53
+ UniformRandomSwitch<T>,
54
+ RoundRobinSwitch<T>,
55
+ Errors<T> {}
56
+
57
+ export const structureBuilderImpl = <J2, J1 extends JvmStructureBuilderLike<J2, any>, T extends StructureBuilder<T>>(
58
+ jvm: J1,
59
+ wrap: (wrapped: J2) => T
60
+ ): StructureBuilder<T> => ({
61
+ exec: execImpl(jvm, wrap),
62
+ group: groupImpl(jvm, wrap),
63
+ feed: feedImpl(jvm, wrap),
64
+ pause: pauseImpl(jvm, wrap),
65
+ pace: paceImpl(jvm, wrap),
66
+ rendezVous: rendezVousImpl(jvm, wrap),
67
+ repeat: repeatImpl(jvm, wrap),
68
+ foreach: foreachImpl(jvm, wrap),
69
+ during: duringImpl(jvm, wrap),
70
+ forever: foreverImpl(jvm, wrap),
71
+ asLongAs: asLongAsImpl(jvm, wrap),
72
+ doWhile: doWhileImpl(jvm, wrap),
73
+ asLongAsDuring: asLongAsDuringImpl(jvm, wrap),
74
+ doWhileDuring: doWhileDuringImpl(jvm, wrap),
75
+ doIf: doIfImpl(jvm, wrap),
76
+ doIfOrElse: doIfOrElseImpl(jvm, wrap),
77
+ doIfEquals: doIfEqualsImpl(jvm, wrap),
78
+ doIfEqualsOrElse: doIfEqualsOrElseImpl(jvm, wrap),
79
+ doSwitch: doSwitchImpl(jvm, wrap),
80
+ doSwitchOrElse: doSwitchOrElseImpl(jvm, wrap),
81
+ randomSwitch: randomSwitchImpl(jvm, wrap),
82
+ randomSwitchOrElse: randomSwitchOrElseImpl(jvm, wrap),
83
+ uniformRandomSwitch: uniformRandomSwitchImpl(jvm, wrap),
84
+ roundRobinSwitch: roundRobinSwitchImpl(jvm, wrap),
85
+ ...errorsImpl(jvm, wrap)
86
+ });
87
+
88
+ export interface ChainBuilder extends StructureBuilder<ChainBuilder>, Executable<JvmChainBuilder> {}
89
+
90
+ const wrapChainBuilder = (_underlying: JvmChainBuilder): ChainBuilder => ({
91
+ _underlying,
92
+ ...structureBuilderImpl(_underlying, wrapChainBuilder)
93
+ });
94
+
95
+ // CoreDsl elements
96
+ export { ActionBuilder, wrapActionBuilder } from "./execs";
97
+ export { onCase, percent } from "./choices";
98
+ export const exec: ExecFunction<ChainBuilder> = execImpl(JvmCoreDsl, wrapChainBuilder);
99
+ export const group: GroupFunction<ChainBuilder> = groupImpl(JvmCoreDsl, wrapChainBuilder);
100
+ export const feed: FeedFunction<ChainBuilder> = feedImpl(JvmCoreDsl, wrapChainBuilder);
101
+ export const pause: PauseFunction<ChainBuilder> = pauseImpl(JvmCoreDsl, wrapChainBuilder);
102
+ export const pace = paceImpl(JvmCoreDsl, wrapChainBuilder);
103
+ export const rendezVous = rendezVousImpl(JvmCoreDsl, wrapChainBuilder);
104
+ export const repeat = repeatImpl(JvmCoreDsl, wrapChainBuilder);
105
+ export const foreach = foreachImpl(JvmCoreDsl, wrapChainBuilder);
106
+ export const during = duringImpl(JvmCoreDsl, wrapChainBuilder);
107
+ export const forever = foreverImpl(JvmCoreDsl, wrapChainBuilder);
108
+ export const asLongAs = asLongAsImpl(JvmCoreDsl, wrapChainBuilder);
109
+ export const doWhile = doWhileImpl(JvmCoreDsl, wrapChainBuilder);
110
+ export const asLongAsDuring = asLongAsDuringImpl(JvmCoreDsl, wrapChainBuilder);
111
+ export const doWhileDuring = doWhileDuringImpl(JvmCoreDsl, wrapChainBuilder);
112
+ export const doIf = doIfImpl(JvmCoreDsl, wrapChainBuilder);
113
+ export const doIfOrElse = doIfOrElseImpl(JvmCoreDsl, wrapChainBuilder);
114
+ export const doIfEquals = doIfEqualsImpl(JvmCoreDsl, wrapChainBuilder);
115
+ export const doIfEqualsOrElse = doIfEqualsOrElseImpl(JvmCoreDsl, wrapChainBuilder);
116
+ export const doSwitch = doSwitchImpl(JvmCoreDsl, wrapChainBuilder);
117
+ export const doSwitchOrElse = doSwitchOrElseImpl(JvmCoreDsl, wrapChainBuilder);
118
+ export const randomSwitch = randomSwitchImpl(JvmCoreDsl, wrapChainBuilder);
119
+ export const randomSwitchOrElse = randomSwitchOrElseImpl(JvmCoreDsl, wrapChainBuilder);
120
+ export const uniformRandomSwitch = uniformRandomSwitchImpl(JvmCoreDsl, wrapChainBuilder);
121
+ export const roundRobinSwitch = roundRobinSwitchImpl(JvmCoreDsl, wrapChainBuilder);
122
+ export const exitBlockOnFail = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitBlockOnFail;
123
+ export const tryMax = errorsImpl(JvmCoreDsl, wrapChainBuilder).tryMax;
124
+ export const exitHereIf = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitHereIf;
125
+ export const exitHere = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitHere;
126
+ export const exitHereIfFailed = errorsImpl(JvmCoreDsl, wrapChainBuilder).exitHereIfFailed;
127
+ export const stopLoadGenerator = errorsImpl(JvmCoreDsl, wrapChainBuilder).stopLoadGenerator;
128
+ export const stopLoadGeneratorIf = errorsImpl(JvmCoreDsl, wrapChainBuilder).stopLoadGeneratorIf;
129
+ export const crashLoadGenerator = errorsImpl(JvmCoreDsl, wrapChainBuilder).crashLoadGenerator;
130
+ export const crashLoadGeneratorIf = errorsImpl(JvmCoreDsl, wrapChainBuilder).crashLoadGeneratorIf;
@@ -0,0 +1,52 @@
1
+ import JvmExecs = io.gatling.javaapi.core.exec.Execs;
2
+ import JvmGroups = io.gatling.javaapi.core.group.Groups;
3
+ import JvmFeeds = io.gatling.javaapi.core.feed.Feeds;
4
+ import JvmPauses = io.gatling.javaapi.core.pause.Pauses;
5
+ import JvmPaces = io.gatling.javaapi.core.pause.Paces;
6
+ import JvmRendezVous = io.gatling.javaapi.core.pause.RendezVous;
7
+ import JvmRepeat = io.gatling.javaapi.core.loop.Repeat;
8
+ import JvmForEach = io.gatling.javaapi.core.loop.ForEach;
9
+ import JvmDuring = io.gatling.javaapi.core.loop.During;
10
+ import JvmForever = io.gatling.javaapi.core.loop.Forever;
11
+ import JvmAsLongAs = io.gatling.javaapi.core.loop.AsLongAs;
12
+ import JvmDoWhile = io.gatling.javaapi.core.loop.DoWhile;
13
+ import JvmAsLongAsDuring = io.gatling.javaapi.core.loop.AsLongAsDuring;
14
+ import JvmDoWhileDuring = io.gatling.javaapi.core.loop.DoWhileDuring;
15
+ import JvmDoIf = io.gatling.javaapi.core.condition.DoIf;
16
+ import JvmDoIfOrElse = io.gatling.javaapi.core.condition.DoIfOrElse;
17
+ import JvmDoIfEquals = io.gatling.javaapi.core.condition.DoIfEquals;
18
+ import JvmDoIfEqualsOrElse = io.gatling.javaapi.core.condition.DoIfEqualsOrElse;
19
+ import JvmDoSwitch = io.gatling.javaapi.core.condition.DoSwitch;
20
+ import JvmDoSwitchOrElse = io.gatling.javaapi.core.condition.DoSwitchOrElse;
21
+ import JvmRandomSwitch = io.gatling.javaapi.core.condition.RandomSwitch;
22
+ import JvmRandomSwitchOrElse = io.gatling.javaapi.core.condition.RandomSwitchOrElse;
23
+ import JvmUniformRandomSwitch = io.gatling.javaapi.core.condition.UniformRandomSwitch;
24
+ import JvmRoundRobinSwitch = io.gatling.javaapi.core.condition.RoundRobinSwitch;
25
+ import JvmErrors = io.gatling.javaapi.core.error.Errors;
26
+
27
+ export interface JvmStructureBuilderLike<T, W>
28
+ extends JvmExecs<T, W>,
29
+ JvmGroups<T, W>,
30
+ JvmFeeds<T, W>,
31
+ JvmPauses<T, W>,
32
+ JvmPaces<T, W>,
33
+ JvmRendezVous<T, W>,
34
+ JvmRepeat<T, W>,
35
+ JvmForEach<T, W>,
36
+ JvmDuring<T, W>,
37
+ JvmForever<T, W>,
38
+ JvmAsLongAs<T, W>,
39
+ JvmDoWhile<T, W>,
40
+ JvmAsLongAsDuring<T, W>,
41
+ JvmDoWhileDuring<T, W>,
42
+ JvmDoIf<T, W>,
43
+ JvmDoIfOrElse<T, W>,
44
+ JvmDoIfEquals<T, W>,
45
+ JvmDoIfEqualsOrElse<T, W>,
46
+ JvmDoSwitch<T, W>,
47
+ JvmDoSwitchOrElse<T, W>,
48
+ JvmRandomSwitch<T, W>,
49
+ JvmRandomSwitchOrElse<T, W>,
50
+ JvmUniformRandomSwitch<T, W>,
51
+ JvmRoundRobinSwitch<T, W>,
52
+ JvmErrors<T, W> {}
@@ -0,0 +1,20 @@
1
+ import JvmExecutable = io.gatling.javaapi.core.exec.Executable;
2
+
3
+ import { Executable } from "./execs";
4
+
5
+ interface JvmOn<T> {
6
+ // In the Java DSL, there is a different On class for each type of condition/loop, but the signature of the on method
7
+ // remains the same.
8
+ on(arg0: JvmExecutable, ...arg1: JvmExecutable[]): T;
9
+ equals(arg0: any /*java.lang.Object*/): boolean;
10
+ toString(): string;
11
+ }
12
+
13
+ export interface On<T> {
14
+ on(executable: Executable<any>, ...executables: Executable<any>[]): T;
15
+ }
16
+
17
+ export const wrapOn = <J, T>(jvmOn: JvmOn<J>, wrap: (underlying: J) => T): On<T> => ({
18
+ on: (executable: Executable<any>, ...executables: Executable<any>[]): T =>
19
+ wrap(jvmOn.on(executable._underlying, ...executables.map((e) => e._underlying)))
20
+ });
@@ -0,0 +1,156 @@
1
+ import { Duration, isDuration, toJvmDuration } from "../utils/duration";
2
+ import { SessionTo, underlyingSessionToDuration } from "../session";
3
+
4
+ import JvmPaces = io.gatling.javaapi.core.pause.Paces;
5
+
6
+ export interface PaceFunction<T extends Paces<T>> {
7
+ /**
8
+ * Attach a pace action
9
+ *
10
+ * @param duration - the duration of the pace, in seconds or with an explicit time unit
11
+ * @returns a new StructureBuilder
12
+ */
13
+ (duration: Duration): T;
14
+
15
+ /**
16
+ * Attach a pace action where the duration is defined as a Gatling Expression Language string. This expression must
17
+ * resolve to either a number, then the unit will be seconds, or an object with an explicit time unit.
18
+ *
19
+ * @param duration - the duration of the pace
20
+ * @returns a new StructureBuilder
21
+ */
22
+ (duration: string): T;
23
+
24
+ /**
25
+ * Attach a pace action
26
+ *
27
+ * @param duration - the duration of the pace as a function
28
+ * @returns a new StructureBuilder
29
+ */
30
+ (duration: SessionTo<Duration>): T;
31
+
32
+ /**
33
+ * Attach a pace action
34
+ *
35
+ * @param duration - the duration of the pace, in seconds or with an explicit time unit
36
+ * @param counterName - the name of the loop counter, as stored in the Session
37
+ * @returns a new StructureBuilder
38
+ */
39
+ (duration: Duration, counterName: string): T;
40
+
41
+ /**
42
+ * Attach a pace action where the duration is defined as a Gatling Expression Language string. This expression must
43
+ * resolve to either a number, then the unit will be seconds, or an object with an explicit time unit.
44
+ *
45
+ * @param duration - the duration of the pace
46
+ * @param counterName - the name of the loop counter, as stored in the Session
47
+ * @returns a new StructureBuilder
48
+ */
49
+ (duration: string, counterName: string): T;
50
+
51
+ /**
52
+ * Attach a pace action
53
+ *
54
+ * @param duration - the duration of the pace as a function
55
+ * @param counterName - the name of the loop counter, as stored in the Session
56
+ * @returns a new StructureBuilder
57
+ */
58
+ (duration: SessionTo<Duration>, counterName: string): T;
59
+
60
+ /**
61
+ * Attach a pace action where the duration is random between 2 bounds
62
+ *
63
+ * @param min - the duration of the pace, in seconds or with an explicit time unit
64
+ * @param max - the duration of the pace, in seconds or with an explicit time unit
65
+ * @returns a new StructureBuilder
66
+ */
67
+ (min: Duration, max: Duration): T;
68
+
69
+ /**
70
+ * Attach a pace action where the duration is random between 2 bounds
71
+ *
72
+ * @param min - the duration of the pace as a function
73
+ * @param max - the duration of the pace as a function
74
+ * @returns a new StructureBuilder
75
+ */
76
+ (min: SessionTo<Duration>, max: SessionTo<Duration>): T;
77
+
78
+ /**
79
+ * Attach a pace action where the duration is random between 2 bounds
80
+ *
81
+ * @param min - the duration of the pace, in seconds or with an explicit time unit
82
+ * @param max - the duration of the pace, in seconds or with an explicit time unit
83
+ * @param counterName - the name of the loop counter, as stored in the Session
84
+ * @returns a new StructureBuilder
85
+ */
86
+ (min: Duration, max: Duration, counterName: string): T;
87
+
88
+ /**
89
+ * Attach a pace action where the duration is random between 2 bounds as Gatling Expression Language strings. These
90
+ * expressions must resolve to either a number, then the unit will be seconds, or an object with an explicit time unit.
91
+ *
92
+ * @param min - the duration of the pace
93
+ * @param max - the duration of the pace
94
+ * @param counterName - the name of the loop counter, as stored in the Session
95
+ * @returns a new StructureBuilder
96
+ */
97
+ (min: string, max: string, counterName: string): T;
98
+
99
+ /**
100
+ * Attach a pace action where the duration is random between 2 bounds
101
+ *
102
+ * @param min - the duration of the pace as a function
103
+ * @param max - the duration of the pace as a function
104
+ * @param counterName - the name of the loop counter, as stored in the Session
105
+ * @returns a new StructureBuilder
106
+ */
107
+ (min: SessionTo<Duration>, max: SessionTo<Duration>, counterName: string): T;
108
+ }
109
+
110
+ export interface Paces<T extends Paces<T>> {
111
+ pace: PaceFunction<T>;
112
+ }
113
+
114
+ export const paceImpl =
115
+ <J2, J1 extends JvmPaces<J2, any>, T extends Paces<T>>(jvmGroups: J1, wrap: (wrapped: J2) => T): PaceFunction<T> =>
116
+ (arg0: Duration | SessionTo<Duration> | string, arg1?: Duration | SessionTo<Duration> | string, arg2?: string) => {
117
+ if (arg2 !== undefined) {
118
+ // pace(min, max, counterName)
119
+ if (typeof arg0 === "string" && typeof arg1 === "string") {
120
+ return wrap(jvmGroups.pace(arg0, arg1, arg2));
121
+ } else if (typeof arg0 === "function" && typeof arg1 === "function") {
122
+ return wrap(jvmGroups.pace(underlyingSessionToDuration(arg0), underlyingSessionToDuration(arg1), arg2));
123
+ } else if (isDuration(arg0) && isDuration(arg1)) {
124
+ return wrap(jvmGroups.pace(toJvmDuration(arg0), toJvmDuration(arg1), arg2));
125
+ }
126
+ } else if (arg1 !== undefined) {
127
+ if (typeof arg1 === "string") {
128
+ // pace(duration, counterName)
129
+ if (typeof arg0 === "string") {
130
+ return wrap(jvmGroups.pace(arg0, arg1));
131
+ } else if (typeof arg0 === "function") {
132
+ return wrap(jvmGroups.pace(underlyingSessionToDuration(arg0), arg1));
133
+ } else if (isDuration(arg0)) {
134
+ return wrap(jvmGroups.pace(toJvmDuration(arg0), arg1));
135
+ }
136
+ } else {
137
+ // pace(min, max)
138
+ if (typeof arg0 === "function" && typeof arg1 === "function") {
139
+ return wrap(jvmGroups.pace(underlyingSessionToDuration(arg0), underlyingSessionToDuration(arg1)));
140
+ } else if (isDuration(arg0) && isDuration(arg1)) {
141
+ return wrap(jvmGroups.pace(toJvmDuration(arg0), toJvmDuration(arg1)));
142
+ }
143
+ }
144
+ } else {
145
+ // pace(duration)
146
+ if (typeof arg0 === "string") {
147
+ return wrap(jvmGroups.pace(arg0));
148
+ } else if (typeof arg0 === "function") {
149
+ return wrap(jvmGroups.pace(underlyingSessionToDuration(arg0)));
150
+ } else if (isDuration(arg0)) {
151
+ return wrap(jvmGroups.pace(toJvmDuration(arg0)));
152
+ }
153
+ }
154
+
155
+ throw Error(`pace() called with invalid arguments ${arg0}, ${arg1}, ${arg2}`);
156
+ };
@@ -0,0 +1,211 @@
1
+ import { CoreDsl as JvmCoreDsl } from "@gatling.io/jvm-types";
2
+ import JvmPauses = io.gatling.javaapi.core.pause.Pauses;
3
+ import JvmPauseType = io.gatling.javaapi.core.PauseType;
4
+
5
+ import { Duration, isDuration, toJvmDuration } from "../utils/duration";
6
+ import { SessionTo, underlyingSessionTo, underlyingSessionToDuration } from "../session";
7
+
8
+ export type PauseType =
9
+ | "Disabled"
10
+ | "Constant"
11
+ | "Exponential"
12
+ | { type: "NormalWithPercentageDuration"; stdDev: number }
13
+ | { type: "NormalWithStdDevDuration"; stdDev: Duration }
14
+ | { type: "Custom"; f: SessionTo<number> }
15
+ | { type: "UniformPercentage"; plusOrMinus: number }
16
+ | { type: "UniformDuration"; plusOrMinus: Duration };
17
+
18
+ const isPauseType = (x: unknown): x is PauseType =>
19
+ x === "Disabled" || x === "Constant" || x === "Exponential" || typeof (x as any).type === "string";
20
+
21
+ export const toJvmPauseType = (pauseType: PauseType): JvmPauseType => {
22
+ if (pauseType === "Disabled") {
23
+ // FIXME find better solution for generating static field definitions in java2typescript (without conflicting
24
+ // with methods of the same name, e.g. 'JvmHttpDsl.http' vs. 'JvmHttpDsl.http(String)')
25
+ return (JvmCoreDsl as any).disabledPauses;
26
+ } else if (pauseType === "Constant") {
27
+ return (JvmCoreDsl as any).constantPauses;
28
+ } else if (pauseType === "Exponential") {
29
+ return (JvmCoreDsl as any).exponentialPauses;
30
+ } else if (pauseType.type === "NormalWithPercentageDuration") {
31
+ return JvmCoreDsl.normalPausesWithPercentageDuration(pauseType.stdDev);
32
+ } else if (pauseType.type === "NormalWithStdDevDuration") {
33
+ return JvmCoreDsl.normalPausesWithStdDevDuration(toJvmDuration(pauseType.stdDev));
34
+ } else if (pauseType.type === "Custom") {
35
+ return JvmCoreDsl.customPauses(underlyingSessionTo(pauseType.f));
36
+ } else if (pauseType.type === "UniformPercentage") {
37
+ return JvmCoreDsl.uniformPausesPlusOrMinusPercentage(pauseType.plusOrMinus);
38
+ } else if (pauseType.type === "UniformDuration") {
39
+ return JvmCoreDsl.uniformPausesPlusOrMinusDuration(toJvmDuration(pauseType.plusOrMinus));
40
+ }
41
+ throw Error(`Unhandled pause type ${pauseType}`);
42
+ };
43
+
44
+ export interface PauseFunction<T extends Pauses<T>> {
45
+ /**
46
+ * Attach a pause
47
+ *
48
+ * @param duration - the pause duration, in seconds or with an explicit time unit
49
+ * @returns a new StructureBuilder
50
+ */
51
+ (duration: Duration): T;
52
+
53
+ /**
54
+ * Attach a pause as a Gatling Expression Language string. This expression must resolve to either a number, then the
55
+ * unit will be seconds, or an object with an explicit time unit.
56
+ *
57
+ * @param duration - the pause duration as a Gatling Expression Language string
58
+ * @returns a new StructureBuilder
59
+ */
60
+ (duration: string): T;
61
+
62
+ /**
63
+ * Attach a pause
64
+ *
65
+ * @param duration - the pause duration as a function
66
+ * @returns a new StructureBuilder
67
+ */
68
+ (duration: SessionTo<Duration>): T;
69
+
70
+ /**
71
+ * Attach a pause
72
+ *
73
+ * @param duration - the pause duration, in seconds or with an explicit time unit
74
+ * @param pauseType - the type of pause
75
+ * @returns a new StructureBuilder
76
+ */
77
+ (duration: Duration, pauseType: PauseType): T;
78
+
79
+ /**
80
+ * Attach a pause as a Gatling Expression Language string. This expression must resolve to either a number, then the
81
+ * unit will be seconds, or an object with an explicit time unit.
82
+ *
83
+ * @param duration - the pause duration as a Gatling Expression Language string
84
+ * @param pauseType - the type of pause
85
+ * @returns a new StructureBuilder
86
+ */
87
+ (duration: string, pauseType: PauseType): T;
88
+
89
+ /**
90
+ * Attach a pause
91
+ *
92
+ * @param duration - the pause duration as a function
93
+ * @param pauseType - the type of pause
94
+ * @returns a new StructureBuilder
95
+ */
96
+ (duration: SessionTo<Duration>, pauseType: PauseType): T;
97
+
98
+ /**
99
+ * Attach a pause computed randomly between 2 values
100
+ *
101
+ * @param min the pause minimum, in seconds or with an explicit time unit
102
+ * @param max the pause maximum, in seconds or with an explicit time unit
103
+ * @return a new StructureBuilder
104
+ */
105
+ (min: Duration, max: Duration): T;
106
+ /**
107
+ * Attach a pause computed randomly between 2 values as a Gatling Expression Language string. These expressions must
108
+ * resolve to either a number, then the unit will be seconds, or an object with an explicit time unit.
109
+ *
110
+ * @param min the pause minimum as a Gatling Expression Language string
111
+ * @param max the pause maximum as a Gatling Expression Language string
112
+ * @return a new StructureBuilder
113
+ */
114
+ (min: string, max: string): T;
115
+
116
+ /**
117
+ * Attach a pause computed randomly between 2 values
118
+ *
119
+ * @param min the pause minimum as a function
120
+ * @param max the pause maximum as a function
121
+ * @return a new StructureBuilder
122
+ */
123
+ (min: SessionTo<Duration>, max: SessionTo<Duration>): T;
124
+
125
+ /**
126
+ * Attach a pause computed randomly between 2 values
127
+ *
128
+ * @param min the pause minimum, in seconds or with an explicit time unit
129
+ * @param max the pause maximum, in seconds or with an explicit time unit
130
+ * @param pauseType - the type of pause
131
+ * @return a new StructureBuilder
132
+ */
133
+ (min: Duration, max: Duration, pauseType: PauseType): T;
134
+
135
+ /**
136
+ * Attach a pause computed randomly between 2 values as a Gatling Expression Language string. These expressions must
137
+ * resolve to either a number, then the unit will be seconds, or an object with an explicit time unit.
138
+ *
139
+ * @param min the pause minimum as a Gatling Expression Language string
140
+ * @param max the pause maximum as a Gatling Expression Language string
141
+ * @param pauseType - the type of pause
142
+ * @return a new StructureBuilder
143
+ */
144
+ (min: string, max: string, pauseType: PauseType): T;
145
+
146
+ /**
147
+ * Attach a pause computed randomly between 2 values
148
+ *
149
+ * @param min the pause minimum as a function
150
+ * @param max the pause maximum as a function
151
+ * @param pauseType - the type of pause
152
+ * @return a new StructureBuilder
153
+ */
154
+ (min: SessionTo<Duration>, max: SessionTo<Duration>, pauseType: PauseType): T;
155
+ }
156
+
157
+ export interface Pauses<T extends Pauses<T>> {
158
+ pause: PauseFunction<T>;
159
+ }
160
+
161
+ export const pauseImpl =
162
+ <J2, J1 extends JvmPauses<J2, any>, T extends Pauses<T>>(jvmGroups: J1, wrap: (wrapped: J2) => T): PauseFunction<T> =>
163
+ (
164
+ arg0: Duration | SessionTo<Duration> | string,
165
+ arg1?: Duration | SessionTo<Duration> | string | PauseType,
166
+ arg2?: PauseType
167
+ ) => {
168
+ if (arg2 !== undefined) {
169
+ // pause(min, max, pauseType)
170
+ if (typeof arg0 === "string" && typeof arg1 === "string") {
171
+ return wrap(jvmGroups.pause(arg0, arg1, toJvmPauseType(arg2)));
172
+ } else if (typeof arg0 === "function" && typeof arg1 === "function") {
173
+ return wrap(
174
+ jvmGroups.pause(underlyingSessionToDuration(arg0), underlyingSessionToDuration(arg1), toJvmPauseType(arg2))
175
+ );
176
+ } else if (isDuration(arg0) && isDuration(arg1)) {
177
+ return wrap(jvmGroups.pause(toJvmDuration(arg0), toJvmDuration(arg1), toJvmPauseType(arg2)));
178
+ }
179
+ } else if (arg1 !== undefined) {
180
+ if (isPauseType(arg1)) {
181
+ // pause(duration, pauseType)
182
+ if (typeof arg0 === "string") {
183
+ return wrap(jvmGroups.pause(arg0, toJvmPauseType(arg1)));
184
+ } else if (typeof arg0 === "function") {
185
+ return wrap(jvmGroups.pause(underlyingSessionToDuration(arg0), toJvmPauseType(arg1)));
186
+ } else if (isDuration(arg0)) {
187
+ return wrap(jvmGroups.pause(toJvmDuration(arg0), toJvmPauseType(arg1)));
188
+ }
189
+ } else {
190
+ // pause(min, max)
191
+ if (typeof arg0 === "string" && typeof arg1 === "string") {
192
+ return wrap(jvmGroups.pause(arg0, arg1));
193
+ } else if (typeof arg0 === "function" && typeof arg1 === "function") {
194
+ return wrap(jvmGroups.pause(underlyingSessionToDuration(arg0), underlyingSessionToDuration(arg1)));
195
+ } else if (isDuration(arg0) && isDuration(arg1)) {
196
+ return wrap(jvmGroups.pause(toJvmDuration(arg0), toJvmDuration(arg1)));
197
+ }
198
+ }
199
+ } else {
200
+ // pause(duration)
201
+ if (typeof arg0 === "string") {
202
+ return wrap(jvmGroups.pause(arg0));
203
+ } else if (typeof arg0 === "function") {
204
+ return wrap(jvmGroups.pause(underlyingSessionToDuration(arg0)));
205
+ } else if (isDuration(arg0)) {
206
+ return wrap(jvmGroups.pause(toJvmDuration(arg0)));
207
+ }
208
+ }
209
+
210
+ throw Error(`pause() called with invalid arguments ${arg0}, ${arg1}, ${arg2}`);
211
+ };
@@ -0,0 +1,34 @@
1
+ import { ChoiceWithWeight } from "./choices";
2
+
3
+ import JvmRandomSwitch = io.gatling.javaapi.core.condition.RandomSwitch;
4
+ import JvmOn = io.gatling.javaapi.core.condition.RandomSwitch$On;
5
+
6
+ export interface On<T> {
7
+ on(...choices: ChoiceWithWeight[]): T;
8
+ }
9
+
10
+ const wrapOn = <J, T>(jvmOn: JvmOn<J>, wrap: (underlying: J) => T): On<T> => ({
11
+ on: (...choices: ChoiceWithWeight[]): T => wrap(jvmOn.on(choices.map((c) => c._underlying)))
12
+ });
13
+
14
+ export interface RandomSwitchFunction<T extends RandomSwitch<T>> {
15
+ /**
16
+ * Execute one of the "choices" randomly based on their respective weight. Weights are expressed
17
+ * in percents so their sum must be <= 100%.
18
+ *
19
+ * @returns a DSL component for defining the "choices"
20
+ */
21
+ (): On<T>;
22
+ }
23
+
24
+ export interface RandomSwitch<T extends RandomSwitch<T>> {
25
+ randomSwitch: RandomSwitchFunction<T>;
26
+ }
27
+
28
+ export const randomSwitchImpl =
29
+ <J2, J1 extends JvmRandomSwitch<J2, any>, T extends RandomSwitch<T>>(
30
+ jvmRandomSwitch: J1,
31
+ wrap: (wrapped: J2) => T
32
+ ): RandomSwitchFunction<T> =>
33
+ () =>
34
+ wrapOn(jvmRandomSwitch.randomSwitch(), wrap);
@@ -0,0 +1,45 @@
1
+ import { ChoiceWithWeight } from "./choices";
2
+ import { Executable } from "./execs";
3
+
4
+ import JvmRandomSwitchOrElse = io.gatling.javaapi.core.condition.RandomSwitchOrElse;
5
+ import JvmOn = io.gatling.javaapi.core.condition.RandomSwitchOrElse$On;
6
+ import JvmOrElse = io.gatling.javaapi.core.condition.RandomSwitchOrElse$OrElse;
7
+
8
+ export interface On<T> {
9
+ on(...choices: ChoiceWithWeight[]): OrElse<T>;
10
+ }
11
+
12
+ const wrapOn = <J, T>(jvmOn: JvmOn<J>, wrap: (underlying: J) => T): On<T> => ({
13
+ on: (...choices: ChoiceWithWeight[]): OrElse<T> => wrapOrElse(jvmOn.on(choices.map((c) => c._underlying)), wrap)
14
+ });
15
+
16
+ export interface OrElse<T> {
17
+ orElse(executable: Executable<any>, ...executables: Executable<any>[]): T;
18
+ }
19
+
20
+ const wrapOrElse = <J, T>(jvmOrElse: JvmOrElse<J>, wrap: (underlying: J) => T): OrElse<T> => ({
21
+ orElse: (executable: Executable<any>, ...executables: Executable<any>[]): T =>
22
+ wrap(jvmOrElse.orElse(executable._underlying, ...executables.map((e) => e._underlying)))
23
+ });
24
+
25
+ export interface RandomSwitchOrElseFunction<T extends RandomSwitchOrElse<T>> {
26
+ /**
27
+ * Execute one of the "choices" randomly based on their respective weight. Weights are expressed
28
+ * in percents so their sum must be <= 100%.
29
+ *
30
+ * @returns the DSL component for defining the "else" block
31
+ */
32
+ (): On<T>;
33
+ }
34
+
35
+ export interface RandomSwitchOrElse<T extends RandomSwitchOrElse<T>> {
36
+ randomSwitchOrElse: RandomSwitchOrElseFunction<T>;
37
+ }
38
+
39
+ export const randomSwitchOrElseImpl =
40
+ <J2, J1 extends JvmRandomSwitchOrElse<J2, any>, T extends RandomSwitchOrElse<T>>(
41
+ jvmRandomSwitch: J1,
42
+ wrap: (wrapped: J2) => T
43
+ ): RandomSwitchOrElseFunction<T> =>
44
+ () =>
45
+ wrapOn(jvmRandomSwitch.randomSwitchOrElse(), wrap);