Data

These data surfaces help a scenario keep track of state while it runs. Use them when payloads, resources, or partitions need to stay organized.

What this page helps you do

What this page helps you do

These data surfaces help a scenario keep track of state while it runs. Use them when payloads, resources, or partitions need to stay organized.

Who this is for

Engineers writing or reviewing scenario code in one of the supported SDKs.

Prerequisites

  • A scenario or runtime surface you want to wire correctly in code

By the end

The exact SDK surface you need for this part of the runtime.

Use this page when

Use this reference when you already know the workflow and need the exact Data API surface in code.

Visual guide

Sequence diagram showing how a LoadStrike workflow moves from setup to report output.
This page fits into the same setup, run, correlate, and report flow as the rest of the public LoadStrike runtime.

Guide

Invocation Data

LoadStrikeScenarioContext.Data is the per-invocation dictionary. Use it when one execution of the scenario needs to pass state from one part of the workflow to another.

Scenario Instance Data

LoadStrikeScenarioContext.ScenarioInstanceData stores shared objects for one scenario instance. It is the right place for resources that need to be reused across multiple invocations of the same scenario copy.

Random Helper

LoadStrikeScenarioContext.Random exposes Next, NextDouble, NextBytes, and Sample helpers when the workload needs controlled variation or deterministic sharding. TypeScript and JavaScript expose the same helper names in PascalCase on the public docs surface.

Cancellation Token

LoadStrikeScenarioContext.ScenarioCancellationToken exposes a named cancellation token wrapper. In Go that wrapper still supports Done, Err, Deadline, and Value so long-running work can honor scenario shutdown without the public API leaking raw context.Context.

Partition Data

LoadStrikeScenarioInitContext.ScenarioPartition exposes Number and Count so datasets can be split deterministically across clustered runs or multiple copies of the same scenario.

Init Configuration

LoadStrikeScenarioInitContext.CustomSettings and GlobalCustomSettings expose the named IConfiguration wrapper. In Go, use Get, Lookup, Len, or Values when an init hook needs runtime configuration without depending on a raw map shape.

Init Metrics

LoadStrikeScenarioInitContext.RegisterMetric(IMetric) lets you register custom counters and gauges during scenario initialization so thresholds, reports, and sinks all see the same metric set across supported SDKs.

SDK reference samples

Use these SDK samples to compare how Data is exposed across the supported languages before you wire it into a full scenario.

If you run these examples locally, add a valid runner key before execution starts. Set it with WithRunnerKey("...") or the config key LoadStrike:RunnerKey.

Context Data

using LoadStrike;

private static readonly HttpClient SharedHttpClient = CreateHttpClient();

private static HttpClient CreateHttpClient()
{
    var handler = new SocketsHttpHandler
    {
        PooledConnectionLifetime = TimeSpan.FromMinutes(5),
        PooledConnectionIdleTimeout = TimeSpan.FromMinutes(2),
        MaxConnectionsPerServer = 1000,
        AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
    };

    return new HttpClient(handler)
    {
        BaseAddress = new Uri("https://api.example.com"),
        Timeout = TimeSpan.FromSeconds(15)
    };
}

var scenario = LoadStrikeScenario.Create("submit-orders", async context =>
{
    context.ScenarioInstanceData["tenantId"] ??= "tenant-a";
    context.Data["orderId"] = $"ord-{context.InvocationNumber}";

    var step = await LoadStrikeStep.Run<string>("POST /orders", context, async () =>
    {
        var payload = new
        {
            orderId = (string)context.Data["orderId"],
            tenantId = (string)context.ScenarioInstanceData["tenantId"],
            amount = 49.95m
        };

        using var response = await SharedHttpClient.PostAsJsonAsync("/orders", payload);
        return response.IsSuccessStatusCode
            ? LoadStrikeResponse.Ok<string>(statusCode: ((int)response.StatusCode).ToString())
            : LoadStrikeResponse.Fail<string>(statusCode: ((int)response.StatusCode).ToString());
    });

    return step.AsReply();
})
.WithLoadSimulations(LoadStrikeSimulation.Inject(10, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(20)));

LoadStrikeRunner.RegisterScenarios(scenario)
    .WithRunnerKey("rkl_your_local_runner_key")
    .Run();

SharedHttpClient.Dispose();

Context fields a basic user should know

context.Data

Invocation-scoped dictionary. Use it for values that only need to live for the current execution of the scenario.

context.ScenarioInstanceData

Per-scenario-instance dictionary. Use it for shared clients, seeded data, or caches that must survive across multiple invocations of the same scenario copy. For HTTP load steps, keep one shared client, session, or dispatcher here instead of constructing a fresh transport per request.

context.InvocationNumber

Monotonic invocation counter for the current scenario. It is a simple way to generate unique ids or branching behavior.

context.Random

Random generator provided by the runtime for payload variation or deterministic sharding.

Shared HTTP cleanup

Dispose or close the shared HTTP client, session, executor, or dispatcher when the run ends so pooled sockets are released cleanly.

context.NodeInfo / context.TestInfo / context.ScenarioInfo

Read-only metadata objects that describe where the scenario is running and what run it belongs to.

context.ScenarioCancellationToken

Cancellation token that becomes signaled when the scenario is stopping and long-running work should exit.

context.GetScenarioTimerTime()

Returns the elapsed scenario time seen by the current invocation.

context.StopScenario(...) / context.StopCurrentTest(...)

Use these helpers when runtime conditions should end a single scenario or the entire test early.

initContext.CustomSettings / GlobalCustomSettings

Configuration surfaces available during initialization. Use them when a scenario needs per-run settings.

initContext.ScenarioPartition

Partition metadata for deterministic dataset sharding across copies or nodes.