Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NotoriousBIT/6ff6edcb5b9b4d2fe5e035a633a534e1 to your computer and use it in GitHub Desktop.

Select an option

Save NotoriousBIT/6ff6edcb5b9b4d2fe5e035a633a534e1 to your computer and use it in GitHub Desktop.
var Thread = Java.type("java.lang.Thread");
var System = Java.type("java.lang.System");
var String = Java.type("java.lang.String");
var topic = "service/ping";
function execute(action) {
out("Test Script: " + action.getName());
for (var i = 0; i < 1000; i++) {
randomTimeSeriesPing();
Thread.sleep(2000);
}
action.setExitCode(0);
action.setResultText("done.");
out("Test Script: Done");
return action;
}
function randomTimeSeriesPing() {
var millis = System.currentTimeMillis();
out("time published: " + millis);
var message = String.format("{ \"timestamp\": %d, \"value\": %f }", millis, Math.random()*100);
mqttManager.publish(topic, message);
}
function out(message){
output.print(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment