From de77cce102cc455728f1a037cbd91d3f60531ba1 Mon Sep 17 00:00:00 2001 From: dilini-muthumala Date: Thu, 22 Apr 2021 21:48:18 +0530 Subject: [PATCH 1/2] Add testcase for https://github.com/siddhi-io/siddhi/issues/1542 --- .../core/query/trigger/TriggerTestCase.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/modules/siddhi-core/src/test/java/io/siddhi/core/query/trigger/TriggerTestCase.java b/modules/siddhi-core/src/test/java/io/siddhi/core/query/trigger/TriggerTestCase.java index b7e68148fd..65d8ea9dd9 100644 --- a/modules/siddhi-core/src/test/java/io/siddhi/core/query/trigger/TriggerTestCase.java +++ b/modules/siddhi-core/src/test/java/io/siddhi/core/query/trigger/TriggerTestCase.java @@ -210,4 +210,40 @@ public void receive(Event[] events) { } + @Test(dependsOnMethods = "testQuery7") + public void testQuery8() throws InterruptedException { + //see https://github.com/siddhi-io/siddhi/issues/1542 + log.info("test case for https://github.com/siddhi-io/siddhi/issues/1542"); + + SiddhiManager siddhiManager = new SiddhiManager(); + + String plan = "" + + "define trigger AlertTypeReadTrigger at 'start';" + + "@sink(type='log')\n" + + "define stream logStream (foo string);\n" + + "\n" + + "from AlertTypeReadTrigger\n" + + "select \"hello\" as foo\n" + + "insert into logStream;"; + + SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan); + + siddhiAppRuntime.addCallback("logStream", new StreamCallback() { + + @Override + public void receive(Event[] events) { + EventPrinter.print(events); + count += events.length; + eventArrived = true; + } + }); + + siddhiAppRuntime.start(); + + Thread.sleep(1000); + siddhiAppRuntime.shutdown(); + AssertJUnit.assertEquals(1, count); + AssertJUnit.assertEquals(true, eventArrived); + } + } From 8bc53c2a0d71a42e4c09786f13f55ce3414166bb Mon Sep 17 00:00:00 2001 From: dilini-muthumala Date: Sat, 24 Apr 2021 00:25:17 +0530 Subject: [PATCH 2/2] Fix invalid json error given for a nested Json message See https://github.com/wso2/streaming-integrator/issues/228 for more details. --- .../java/io/siddhi/core/util/transport/TemplateBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/siddhi-core/src/main/java/io/siddhi/core/util/transport/TemplateBuilder.java b/modules/siddhi-core/src/main/java/io/siddhi/core/util/transport/TemplateBuilder.java index 7b568b6328..1c07949fd3 100644 --- a/modules/siddhi-core/src/main/java/io/siddhi/core/util/transport/TemplateBuilder.java +++ b/modules/siddhi-core/src/main/java/io/siddhi/core/util/transport/TemplateBuilder.java @@ -39,7 +39,7 @@ public class TemplateBuilder { private static final Pattern DYNAMIC_PATTERN = Pattern.compile("(\\{\\{[^{}]*\\}\\})|[{}]"); - private static final String SPLIT_PATTERN = "(\\{\\{|\\}\\})"; + private static final String SPLIT_PATTERN = "(\\{.\\{|\\}.\\})"; private int[] positionArray; private String[] splitTemplateArray; private boolean isObjectMessage = false; @@ -113,7 +113,7 @@ private String parseTextMessage(StreamDefinition streamDefinition, String templa if (m.group(1) != null) { int attrIndex = attributes.indexOf(m.group(1).replaceAll("\\p{Ps}", "").replaceAll("\\p{Pe}", "")); if (attrIndex >= 0) { - m.appendReplacement(result, String.format("{{%s}}", attrIndex)); + m.appendReplacement(result, String.format("{.{%s}.}", attrIndex)); } else { throw new NoSuchAttributeException(String.format("Attribute : %s does not exist in %s.", m.group(1), streamDefinition));