Testing with the Workbench
Prior to deploying a digital twin model to the ScaleOut Digital Twins™ service, you can deploy it in the self-contained, development environment called the Workbench. This gives you full control over its execution so that you can catch exceptions, examine instance state, and perform other debugging steps.
The Workbench
APIs are open source and available on GitHub. Prebuilt binaries can be downloaded from Maven Central, as explained in the previous section Prerequisites.
Note
For full Workbench API documentation, please see the JavaDocs API Reference.
Developers can add real-time and simulation models to the Workbench in their IDE or project of choice. Once the models are added, messages can be sent to both real-time and simulation models for testing message processing. Additionally, the Workbench can run time-ordered simulations step-by-step or from start-to-finish using the “step” debug loop or the run functions.
Following the thermostat and heater example, use the Workbench to run a simulation with the RealTimeThermostat and SimulatedHeater models. The following code snippet uses the step-by-step debug loop to introspect on the state of the digital twin after each simulation event.
Workbench workbench = new Workbench();
workbench.addRealTimeModel("Thermostat", new RealTimeThermostatMessageProcessor(), RealTimeThermostat.class, TemperatureChangeMessage.class);
workbench.addSimulationModel("SimHeater", new HeaterMessageProcessor(), new HeaterSimulationProcessor(), SimulatedHeater.class, TemperatureChangeMessage.class);
workbench.addInstance("SimHeater", "19", new SimulatedHeater(true));
SimulationStep step = workbench.initializeSimulation(System.currentTimeMillis(), System.currentTimeMillis()+60000, 1000);
while(step.getStatus() == SimulationStatus.Running) {
step = workbench.step();
HashMap<String, DigitalTwinBase> realTimeThermostats = workbench.getInstances("Thermostat");
RealTimeThermostat thermostat = (RealTimeThermostat) realTimeThermostats.get("19");
System.out.println("rtThermostat: " + thermostat.getTemperature());
}
In addition to the methods for adding real-time and simulation digital twin models, the Workbench
class defines special methods to assist in debugging and testing models. They are:
getLoggedMessages("modelName", timestamp)
: retrieves all log messages generated during message processing.getAlertMessages("modelName", "alertProviderName")
: retrieves all alert messages generated during message processing.getInstances("modelName")
: returns all instances for a specified modelgenerateModelSchema("modelName")
: returns a string representation of a model’s “model.json” model specification (schema), which is described in the section Packaging the Model abovegenerateModelSchema("modelName", "/Output/directory/")
: generates the “model.json” model specification (schema) file for a specified model in the directory of your choosing or to the working directory of the running JVM.