@Test public void multipleRoutesAreAllowed() throws TbNodeException, ScriptException { initWithScript(); TbMsgMetaData metaData = new TbMsgMetaData(); metaData.putValue("temp", "10"); metaData.putValue("humidity", "99"); String rawJson = "{\"name\": \"Vit\", \"passed\": 5}"; TbMsg msg = TbMsg.newMsg( "USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId); mockJsExecutor(); when(scriptEngine.executeSwitch(msg)).thenReturn(Sets.newHashSet("one", "three")); node.onMsg(ctx, msg); verify(ctx).getJsExecutor(); verify(ctx).tellNext(msg, Sets.newHashSet("one", "three")); }
@Override public void onMsg(TbContext ctx, TbMsg msg) { ListeningExecutor jsExecutor = ctx.getJsExecutor(); ctx.logJsEvalRequest(); withCallback(jsExecutor.executeAsync(() -> jsEngine.executeSwitch(msg)), result -> { ctx.logJsEvalResponse(); processSwitch(ctx, msg, result); }, t -> { ctx.logJsEvalFailure(); ctx.tellFailure(msg, t); }, ctx.getDbCallbackExecutor()); }
TbJsSwitchNode implements TbNode { @Override public void onMsg(TbContext ctx, TbMsg msg) { ListeningExecutor jsExecutor = ctx.getJsExecutor(); ctx.logJsEvalRequest(); withCallback(jsExecutor.executeAsync(() -> jsEngine.executeSwitch(msg)), result -> { ctx.logJsEvalResponse(); processSwitch(ctx, msg, result); }, t -> { ctx.logJsEvalFailure(); ctx.tellFailure(msg, t); }, ctx.getDbCallbackExecutor()); } }
TbJsSwitchNode implements TbNode { @Override public void onMsg(TbContext ctx, TbMsg msg) { ListeningExecutor jsExecutor = ctx.getJsExecutor(); ctx.logJsEvalRequest(); withCallback(jsExecutor.executeAsync(() -> jsEngine.executeSwitch(msg)), result -> { ctx.logJsEvalResponse(); processSwitch(ctx, msg, result); }, t -> { ctx.logJsEvalFailure(); ctx.tellFailure(msg, t); }, ctx.getDbCallbackExecutor()); }  }
TbJsSwitchNode implements TbNode { @Override public void onMsg(TbContext ctx, TbMsg msg) { ListeningExecutor jsExecutor = ctx.getJsExecutor(); ctx.logJsEvalRequest(); withCallback(jsExecutor.executeAsync(() -> jsEngine.executeSwitch(msg)), result -> { ctx.logJsEvalResponse(); processSwitch(ctx, msg, result); }, t -> { ctx.logJsEvalFailure(); ctx.tellFailure(msg, t); }, ctx.getDbCallbackExecutor()); }  @Override void init(TbContext ctx, TbNodeConfiguration configuration); @Override void onMsg(TbContext ctx, TbMsg msg); @Override void destroy(); }
TbJsSwitchNode implements TbNode { @Override public void onMsg(TbContext ctx, TbMsg msg) { ListeningExecutor jsExecutor = ctx.getJsExecutor(); ctx.logJsEvalRequest(); withCallback(jsExecutor.executeAsync(() -> jsEngine.executeSwitch(msg)), result -> { ctx.logJsEvalResponse(); processSwitch(ctx, msg, result); }, t -> { ctx.logJsEvalFailure(); ctx.tellFailure(msg, t); }, ctx.getDbCallbackExecutor()); }  @Override void init(TbContext ctx, TbNodeConfiguration configuration); @Override void onMsg(TbContext ctx, TbMsg msg); @Override void destroy();  }