Skip to content

Testing with Simulator

In the Kelvin SDK there is a kelvin-publisher test tool to help you ingest data to the inputs and debug the outputs to test the performance of your Kelvin SmartApp™.

It is a CLI utility for exercising your application during development. It is not imported into your code and is used only as a standalone testing tool.

Note

You must have installed the kelvin-python-sdk[publisher] library for this feature to work.

The Kelvin SDK simulator publisher tool is designed to allow testers to ingest messages from a random simulator for testing purposes. Here is the command:

Starting Test Tool
1
kelvin-publisher simulator

Simulator Tool Overview

The simulator publisher tool supports a variety of options to customize its behavior. Below is a list of the available options:

Test Parameters Required Description Note
--config TEXT optional Path to the app.yaml Default: Current directory
--random / --counter optional Random values / Incremental values Default: Random values
--min FLOAT optional Minimum value Default: 0
--max FLOAT optional Maximum value Default: 100
--period FLOAT optional Publishing period in seconds Default: 5
--asset-count INTEGER optional Number of Assets (test-asset-N) Default: 1
--asset-parameter TEXT optional Sets App Parameter Can be used multiple times

Test your SmartApp

Info

In order to show how to use the simulator, we will use it with the Event Detection sample app.

  1. Run the Simulator Test Tool:

    Starting Test Tool
    1
    kelvin-publisher simulator --counter --min 50 --max 60 --period 1 --asset-parameter temperature_max_threshold=55 --asset-parameter speed_decrease_set_point=1050 --asset-parameter closed_loop=true
    

    and you should see the following output:

    Test Tool Output
    1
    Publisher started.
    
  2. Open a NEW terminal window and run the SmartApp:

    Note

    Use the config.yaml file to override default configurations in app.yaml or inject sensitive information (API keys, credentials, etc.) that should not be embedded in your Kelvin SmartApp™.

    Click here to read more about this local testing feature.

    Running Kelvin SmartApp™ Python Example
    1
    python3 main.py
    

    and you should see the following output:

    Kelvin SmartApp™ Python Example Output
    1
    2
    3
    4
    5
    6
    7
    Received Motor Temperature | Asset: test-asset-1 | Value: 55.0
    
    Received Motor Temperature | Asset: test-asset-1 | Value: 56.0
    
    Published Motor Speed SetPoint Control Change: 1050
    
    (...)
    
  3. Go to the Simulator Tool terminal and check the logs:

    Test Tool Output
    1
    2
    3
    4
    5
    6
    7
    8
    Publisher started.
    Connected
    
    (...)
    
    Received Recommendation Message:
    RecommendationMsg(id=UUID('e5cc136a-5ae1-4014-a106-6699b6423e62'), type=KMessageTypeRecommendation('recommendation', ''), trace_id=None, source=None, timestamp=datetime.datetime(2024, 8, 9, 18, 10, 40, 231994, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'WEST')), resource=KRNAsset(asset='test-asset-1'), payload=RecommendationPayload(source=None, resource=KRNAsset(asset='test-asset-1'), type='decrease_speed', description=None, confidence=None, expiration_date=None, actions=RecommendationActions(control_changes=[RecommendationControlChange(timeout=None, retries=None, expiration_date=datetime.datetime(2024, 8, 9, 18, 20, 40, 231843, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600), 'WEST')), payload=1000.0, from_value=None, state=None, resource=KRNAssetDataStream(asset='test-asset-1', data_stream='motor_speed_set_point'), control_change_id=None)]), metadata={}, state=None))
    (...)