use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.
the class SequencePartitionTestCase method testSequencePartitionQuery7.
@Test
public void testSequencePartitionQuery7() throws InterruptedException {
log.info("Pattern -testSequence7 - OUT 2");
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 partitionStart = "partition with (volume of Stream1 , volume of Stream2) begin ";
String query = "" + "@info(name = 'query1') " + "from every e1=Stream2[price>20], e2=Stream2[price>e1.price] or e3=Stream2[symbol=='IBM'] " + "select e1.price as price1, e2.price as price2, e3.price as price3 " + "insert into OutputStream ;";
String partitionEnd = "end";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd);
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
if (event.isExpired()) {
removeEventCount++;
} else {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, 55.7f, null }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { 55.7f, 57.6f, null }, event.getData());
break;
case 3:
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, 155.7f, null }, event.getData());
break;
case 4:
AssertJUnit.assertArrayEquals(new Object[] { 155.7f, 457.6f, null }, event.getData());
break;
default:
AssertJUnit.assertSame(4, inEventCount);
}
}
eventArrived = true;
}
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream2.send(new Object[] { "WSO2", 59.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 55.7f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 599.6f, 4100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 55.6f, 4100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 155.7f, 4100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 457.6f, 4100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 4, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.
the class SequencePartitionTestCase method testSequencePartitionQuery8.
@Test
public void testSequencePartitionQuery8() throws InterruptedException {
log.info("Pattern -testSequence8 - OUT 2");
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 partitionStart = "partition with (volume of Stream1 , volume of Stream2) begin ";
String query = "" + "@info(name = 'query1') " + "from every e1=Stream2[price>20], e2=Stream2[price>e1.price] or e3=Stream2[symbol=='IBM'] " + "select e1.price as price1, e2.price as price2, e3.price as price3 " + "insert into OutputStream ;";
String partitionEnd = "end";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd);
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
if (event.isExpired()) {
removeEventCount++;
} else {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { 55.6f, null, 55.0f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { 155.6f, null, 95.0f }, event.getData());
break;
case 3:
AssertJUnit.assertArrayEquals(new Object[] { 55.0f, 57.6f, null }, event.getData());
break;
case 4:
AssertJUnit.assertArrayEquals(new Object[] { 95.0f, 207.6f, null }, event.getData());
break;
default:
AssertJUnit.assertSame(4, inEventCount);
}
}
eventArrived = true;
}
}
});
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream2.send(new Object[] { "WSO2", 59.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 259.6f, 200 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 155.6f, 200 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 55.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 95.0f, 200 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "WSO2", 207.6f, 200 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 4, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition7.
@Test
public void testJoinPartition7() throws InterruptedException {
log.info("Join partition test7");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string, volume int);" + "partition with (volume>=100 as 'large' or volume<100 as 'small' of cseEventStream, volume>=100 as " + "'large' or volume<100 as 'small' of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.user== twitterStream.user " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume,twitterStream.company " + "insert all events into outputStream;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 200 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 200 });
twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2", 200 });
cseEventStreamHandler.send(new Object[] { "IBM", "User1", 10 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 10 });
twitterStreamHandler.send(new Object[] { "User1", "World", "IBM", 10 });
SiddhiTestHelper.waitForEvents(100, 8, count, 6000);
AssertJUnit.assertEquals(8, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery35.
@Test
public void testPartitionQuery35() throws InterruptedException {
log.info("Partition test34");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest34') " + "define stream cseEventStream (atr1 string, atr2 float, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>atr5 OR atr8 > atr3 OR atr6 > atr2 OR atr4 " + "> atr6 OR atr2 > atr7 OR atr3 > atr4 OR atr4 > atr3 OR atr6 > atr3 OR atr3" + "> atr2 OR atr8 > atr5 OR atr6 > atr4 OR atr3 > atr6 OR atr7 > atr8 OR atr7 " + "> atr4 OR atr6 > atr5 OR atr11 > atr3 OR atr8 > atr2] select" + " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 108 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery23.
@Test
public void testPartitionQuery23() throws InterruptedException {
log.info("Partition test23");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice >= 0 or avgPrice is null " + "insert expired events into OutStockStream ;" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
count.incrementAndGet();
if (count.get() == 1) {
AssertJUnit.assertEquals(null, event.getData()[1]);
}
eventArrived = true;
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75f, 100 });
SiddhiTestHelper.waitForEvents(200, 1, count, 60000);
AssertJUnit.assertEquals(1, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations