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
| Field | Type | Default | Description |
|---|---|---|---|
data_type | DataType | Generic | Type of data to generate |
interval_ms | u64 | 5000 | Interval 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:
MockSource::inject_event()- Inject customSourceChangeevents (INSERT, UPDATE, DELETE) for deterministic testing scenariosMockSource::test_subscribe()- Subscribe to receive events directly from the source, bypassing DrasiLib’s subscription mechanism
Modules§
- descriptor
- Mock source plugin descriptor and configuration DTOs.
Structs§
- Mock
Source - Mock source that generates synthetic data for testing and development.
- Mock
Source Builder - Builder for
MockSourceinstances. - Mock
Source Config - Configuration for a
MockSourceinstance.
Enums§
- Data
Type - Specifies the type of synthetic data to generate.