Skip to main content

Crate drasi_source_mock

Crate drasi_source_mock 

Source
Expand description

Mock Source Plugin for drasi-lib.

This plugin provides a mock data generator for testing and development purposes. It generates synthetic data at configurable intervals, allowing you to test query behavior and reaction processing without connecting to real data sources.

§Data Types

The mock source supports three data generation modes:

§Counter Mode (data_type: DataType::Counter)

Generates sequentially numbered nodes with the label Counter. Each event is always an INSERT with a unique element ID (counter_1, counter_2, etc.):

Element {
    id: "counter_1",
    labels: ["Counter"],
    properties: {
        value: 1,              // Sequential integer starting at 1
        timestamp: "2024-01-15T10:30:00.123Z"  // RFC 3339 string
    },
    effective_from: 1705318200123  // Milliseconds since Unix epoch
}

§Sensor Reading Mode (data_type: DataType::SensorReading { sensor_count })

Generates simulated IoT sensor readings with randomized temperature and humidity values from a configurable number of sensors (default: 5). Each node has the label SensorReading.

Key Behavior: The first reading for each sensor generates an INSERT event; subsequent readings for the same sensor generate UPDATE events. This simulates real sensor behavior where devices are discovered once then continuously report.

Element {
    id: "sensor_2",
    labels: ["SensorReading"],
    properties: {
        sensor_id: "sensor_2",
        temperature: 25.7,     // Random in range [20.0, 30.0)
        humidity: 48.3,        // Random in range [40.0, 60.0)
        timestamp: "2024-01-15T10:30:00.123Z"
    },
    effective_from: 1705318200123
}

§Generic Mode (data_type: DataType::Generic) - Default

Generates generic nodes with random values and the label Generic. Each event is always an INSERT with a unique element ID:

Element {
    id: "generic_1",
    labels: ["Generic"],
    properties: {
        value: 12345,          // Random i32
        message: "Generic mock data",
        timestamp: "2024-01-15T10:30:00.123Z"
    },
    effective_from: 1705318200123456789  // Nanoseconds since Unix epoch
}

§Configuration

FieldTypeDefaultDescription
data_typeDataTypeGenericType of data to generate
interval_msu645000Interval between events in milliseconds (must be > 0)

§Example Configuration (YAML)

source_type: mock
properties:
  data_type:
    type: sensor_reading
    sensor_count: 10
  interval_ms: 1000

§Usage Example

use drasi_source_mock::{MockSource, MockSourceConfig, DataType};

// Create configuration for sensor data at 1-second intervals
let config = MockSourceConfig {
    data_type: DataType::sensor_reading(10),
    interval_ms: 1000,
};

// Create the source
let source = MockSource::new("my-mock", config)?;

// Add to DrasiLib (ownership is transferred)
drasi.add_source(source).await?;

§Testing

The mock source provides methods for unit testing without a full DrasiLib setup:

Modules§

descriptor
Mock source plugin descriptor and configuration DTOs.

Structs§

MockSource
Mock source that generates synthetic data for testing and development.
MockSourceBuilder
Builder for MockSource instances.
MockSourceConfig
Configuration for a MockSource instance.

Enums§

DataType
Specifies the type of synthetic data to generate.