use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class CountPatternTestCase method testQuery12.
@Test
public void testQuery12() throws InterruptedException {
log.info("testPatternCount12 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream EventStream (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1 = EventStream [price >= 50 and volume > 100] -> e2 = EventStream [price <= 40] <:5> " + " -> e3 = EventStream [volume <= 70] " + "select e1.symbol as symbol1, e2[last].symbol as symbol2, e3.symbol as symbol3 " + "insert into StockQuote;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", "FB", "WSO2" }, event.getData());
break;
default:
AssertJUnit.assertSame(1, inEventCount);
}
}
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler eventStream = siddhiAppRuntime.getInputHandler("EventStream");
siddhiAppRuntime.start();
eventStream.send(new Object[] { "IBM", 75.6f, 105 });
Thread.sleep(100);
eventStream.send(new Object[] { "GOOG", 21f, 91 });
eventStream.send(new Object[] { "FB", 21f, 81 });
eventStream.send(new Object[] { "WSO2", 21f, 61 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class EveryPatternTestCase method testQuery2.
@Test
public void testQuery2() throws InterruptedException {
log.info("testPatternEvery2 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price1 float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>20] -> e2=Stream2[price1>e1.price] " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount = inEventCount + inEvents.length;
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "IBM" }, inEvents[0].getData());
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 55.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class EveryPatternTestCase method testQuery3.
@Test
public void testQuery3() throws InterruptedException {
log.info("testPatternEvery3 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price1 float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from every e1=Stream1[price>20] -> e2=Stream2[price1>e1.price] " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", "IBM" }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "GOOG", "IBM" }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 55.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class EveryPatternTestCase method testQuery4.
@Test
public void testQuery4() throws InterruptedException {
log.info("testPatternEvery4 - OUT 1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from every ( e1=Stream1[price>20] -> e3=Stream1[price>20]) -> e2=Stream2[price>e1.price] " + "select e1.price as price1, e3.price as price3, e2.price as price2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, 54f, 57.7f }, event.getData());
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 54f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 57.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.humantask.core.engine.commands.Remove in project siddhi by wso2.
the class EveryPatternTestCase method testQuery7.
@Test
public void testQuery7() throws InterruptedException {
log.info("testPatternEvery7 - OUT 2");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from every ( e1=Stream1[price>20] -> e3=Stream1[price>20]) " + "select e1.price as price1, e3.price as price3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, 57.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { 54f, 53.6f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
siddhiAppRuntime.start();
stream1.send(new Object[] { "MSFT", 55.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 54f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "WSO2", 53.6f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations