use of org.wso2.charon3.core.objects.User in project siddhi by wso2.
the class QuerySyncTestCase method querySyncTest3.
@Test
public void querySyncTest3() throws InterruptedException {
log.info("querySync test3");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "@synchronized('true') " + "from cseEventStream#window.time(1 sec) as a join twitterStream#window.time(1 sec) as b " + "on a.symbol== b.company " + "select a.symbol as symbol, b.tweet, a.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount.addAndGet(inEvents.length);
}
if (removeEvents != null) {
removeEventCount.addAndGet(removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(500);
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000);
SiddhiTestHelper.waitForEvents(100, 2, removeEventCount, 60000);
AssertJUnit.assertEquals(2, inEventCount.get());
AssertJUnit.assertEquals(2, removeEventCount.get());
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon3.core.objects.User in project siddhi by wso2.
the class ExternalTimeBatchWindowTestCase method testExternalTimeBatchWindow13.
@Test
public void testExternalTimeBatchWindow13() throws InterruptedException {
log.info("ExternalTimeBatchWindow test13");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); " + "define window cseEventWindow (timestamp long, symbol string, price float, volume int) " + "externalTimeBatch(timestamp, 1 sec, 0); " + "define window twitterWindow (timestamp long, user string, tweet string, company string) " + "externalTimeBatch(timestamp, 1 sec, 0); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from twitterStream " + "insert into twitterWindow; " + "" + "@info(name = 'query2') " + "from cseEventWindow join twitterWindow " + "on cseEventWindow.symbol== twitterWindow.company " + "select cseEventWindow.symbol as symbol, twitterWindow.tweet, cseEventWindow.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query2", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
Thread.sleep(1000);
assertEquals(2, inEventCount);
assertEquals(1, removeEventCount);
assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon3.core.objects.User in project siddhi by wso2.
the class LenghtBatchWindowTestCase method testLengthBatchWindow9.
@Test
public void testLengthBatchWindow9() throws InterruptedException {
log.info("LengthBatchWindow Test9");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); " + "define window cseEventWindow (symbol string, price float, volume int) lengthBatch(2); " + "define window twitterWindow (user string, tweet string, company string) lengthBatch(2); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from twitterStream " + "insert into twitterWindow; " + "" + "@info(name = 'query2') " + "from cseEventWindow join twitterWindow " + "on cseEventWindow.symbol == twitterWindow.company " + "select cseEventWindow.symbol as symbol, twitterWindow.tweet, cseEventWindow.price " + "insert into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query2", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
cseEventStreamHandler.send(new Object[] { "IBM", 59.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(500);
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertEquals(0, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon3.core.objects.User in project siddhi by wso2.
the class ExternalTimeBatchWindowTestCase method externalTimeBatchWindowTest13.
@Test
public void externalTimeBatchWindowTest13() throws InterruptedException {
log.info("externalTimeBatchWindow Test13");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " + "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" + ".externalTimeBatch(timestamp, 1 sec, 0) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { 1366335804341L, "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { 1366335804341L, "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { 1366335805301L, "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { 1366335805341L, "WSO2", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { 1366335806541L, "WSO2", 57.6f, 100 });
Thread.sleep(1000);
org.testng.AssertJUnit.assertEquals(2, inEventCount);
org.testng.AssertJUnit.assertEquals(1, removeEventCount);
org.testng.AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.charon3.core.objects.User in project siddhi by wso2.
the class LengthBatchWindowTestCase method lengthBatchWindowTest8.
@Test
public void lengthBatchWindowTest8() throws InterruptedException {
log.info("LengthBatchWindow Test8");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(2) join twitterStream#window.lengthBatch(2) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
inEventCount += (inEvents.length);
}
if (removeEvents != null) {
removeEventCount += (removeEvents.length);
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
cseEventStreamHandler.send(new Object[] { "IBM", 59.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User2", "Hello World2", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(500);
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertEquals(2, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
Aggregations