Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorExpressions
Logic
Use logic functions when a generated value depends on fields already present in the event. Synthtraffic has no inline operators such as >, &&, or ||.
The result
The order is paid and verified, and the first matching amount tier is standard:
{"amount":750,"paid":true,"verified":true,"readyToShip":true,"priority":"standard"}
Classify an order
generators:
- name: orders
config:
maxEvents: 1
value:
amount: 750
paid: true
verified: true
readyToShip: =and($paid, $verified)
priority:
=case:
- if: =gte($amount, 1000)
then: premium
- if: =gte($amount, 500)
then: standard
- else: basic
Comparisons and booleans
same: =eq($status, CREATED)
different: =neq($status, CANCELLED)
large: =gt($amount, 1000)
largeOrEqual: =gte($amount, 1000)
small: =lt($amount, 100)
smallOrEqual: =lte($amount, 100)
valid: =and($active, $verified)
allowed: =or($admin, $owner)
disabled: =not($active)
With status: CREATED, amount: 750, active/verified true, admin false, and owner true:
{"same":true,"different":true,"large":false,"largeOrEqual":false,"small":false,"smallOrEqual":false,"valid":true,"allowed":true,"disabled":false}
eq(left, right)andneq(left, right)compare values of any supported type.gt,gte,lt, andlterequire numeric values.andandorrequire at least two booleans.notrequires one boolean.
There is no truthy or falsy coercion: =and(true, 1) is an error.
case
case evaluates branches from top to bottom and returns the first then value whose if expression is true.
tier:
=case:
- if: =gte($amount, 1000)
then: gold
- if: =gte($amount, 500)
then: silver
- else: bronze
With amount: 750:
{"amount":750,"tier":"silver"}
Each normal branch must contain exactly if and then. An else branch, when present, must be the final branch and its only field. If no condition matches and there is no else, the result is null.
Only the selected result is evaluated. This allows a branch to contain a function or reference that is valid only when its condition matches.
Use Selection when the choice should be random or cyclic rather than condition-based. Lifecycle transitions can also use these boolean functions; see Lifecycle.