Skip to content

Commit

Permalink
Merge pull request #1723 from dilini-muthumala/master
Browse files Browse the repository at this point in the history
Fix invalid json error given for a nested Json message
  • Loading branch information
dnwick authored Apr 24, 2021
2 parents 0bf06c1 + 8bc53c2 commit aa26d11
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit aa26d11

Please sign in to comment.