Java Code Examples for io.siddhi.core.SiddhiManager#createSiddhiAppRuntime()
The following examples show how to use
io.siddhi.core.SiddhiManager#createSiddhiAppRuntime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest49"}, expectedExceptions = StoreQueryCreationException.class) public void incrementalStreamProcessorTest50() { LOG.info("incrementalStreamProcessorTest50 - Retrieval query syntax validating "); SiddhiManager siddhiManager = new SiddhiManager(); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);"; String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue " + "group by symbol " + "aggregate by timestamp every sec...hour ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); siddhiAppRuntime.start(); try { siddhiAppRuntime.query("from stockAggregation select * "); } finally { siddhiAppRuntime.shutdown(); } }
Example 2
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery102() throws InterruptedException { log.info("Filter test102"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(55f)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example 3
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery57() throws InterruptedException { log.info("Filter test57"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.value(60L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 60d}); inputHandler.send(new Object[]{"WSO2", 60f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 4
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery2() throws InterruptedException { log.info("Partition test2"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest2') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream StockStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " + "from cseEventStream[700>price] select symbol,sum(price) as price,volume 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}); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example 5
Source File: EveryAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQueryAbsent4() throws InterruptedException { log.info("Test the query every not e1, e2 with e1 and e2 for 1 sec where e1 filter fails"); 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 not Stream1[price>20] for 1 sec, e2=Stream2[price>30] " + "select e2.symbol as symbol " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1"); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 25.6f, 100}); Thread.sleep(500); stream1.send(new Object[]{"WSO2", 25.6f, 100}); Thread.sleep(500); stream1.send(new Object[]{"WSO2", 25.6f, 100}); Thread.sleep(500); stream2.send(new Object[]{"IBM", 58.7f, 100}); Thread.sleep(100); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertFalse("Event not arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 6
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery35() throws InterruptedException { log.info("Filter test35"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume double);"; String query = "@info(name = 'query1') from cseEventStream[volume != 50L] select symbol,price,volume insert " + "into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 55.5f, 40d}); inputHandler.send(new Object[]{"WSO2", 53.5f, 50d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 7
Source File: SessionWindowTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(description = "This test checks if Siddhi App creation fails when more than three parameters are provided'", expectedExceptions = SiddhiAppCreationException.class) public void testSessionWindow1() { log.info("SessionWindow Test1: Testing session window with more than defined parameters"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = null; String purchaseEventStream = "" + "define stream purchaseEventStream (user string, item_number int, price float, quantity int);"; String query = "" + "@info(name = 'query0') " + "from purchaseEventStream#window.session(5 sec, user, 2 sec, 1) " + "select * " + "insert all events into outputStream ;"; try { siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(purchaseEventStream + query); } catch (SiddhiAppCreationException e) { AssertJUnit.assertEquals("There is no parameterOverload for 'session' that matches attribute types " + "'<LONG, STRING, LONG, INT>'. Supported parameter overloads are " + "(<INT|LONG|TIME> session.gap), " + "(<INT|LONG|TIME> session.gap, <STRING> session.key), (<INT|LONG|TIME> session.gap, " + "<STRING> session.key, <INT|LONG|TIME> allowed.latency).", e.getCause().getMessage()); throw e; } finally { if (siddhiAppRuntime != null) { siddhiAppRuntime.shutdown(); } } }
Example 8
Source File: LogicalAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent39"}) public void testQueryAbsent40() throws InterruptedException { log.info("Test the query (not e1 for 1 sec and not e2 for 1 sec), e3 with e1, e2 and e3"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from (not Stream1[price>10] for 1 sec and not Stream2[price>20] for 1 sec), e3=Stream3[price>30] " + "select e3.symbol as symbol " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1"); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); stream1.send(new Object[]{"ORACLE", 15.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 25.0f, 100}); Thread.sleep(100); stream3.send(new Object[]{"WSO2", 35.0f, 100}); TestUtil.waitForInEvents(100, callback, 5); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertFalse("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 9
Source File: UpdateOrInsertTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateOrInsertTableTest1() throws InterruptedException { log.info("updateOrInsertTableTest1"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update or insert into StockTable " + " on StockTable.symbol=='IBM' ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 75.6f, 100L}); stockStream.send(new Object[]{"WSO2", 57.6f, 100L}); updateStockStream.send(new Object[]{"GOOG", 10.6f, 100L}); Thread.sleep(500); siddhiAppRuntime.shutdown(); }
Example 10
Source File: AbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent40"}) public void testQueryAbsent41() throws InterruptedException { log.info("Test the query every not e1 with e1"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from every not Stream1[price>20] for 1 sec " + "select * " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1"); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 55.6f, 100}); TestUtil.waitForInEvents(100, callback, 5); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertFalse("Event not arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); Thread.sleep(3000); }
Example 11
Source File: DefineTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = DuplicateDefinitionException.class) public void testQuery4() throws InterruptedException { log.info("testTableDefinition4 - OUT 0"); SiddhiManager siddhiManager = new SiddhiManager(); String tables = "define table TestTable(symbol string, volume float); " + "define table TestTable(symbols string, price int, volume float); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables); siddhiAppRuntime.shutdown(); }
Example 12
Source File: ExternalTimeBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void externalTimeBatchWindowTest2() throws InterruptedException { log.info("externalTimeBatchWindow test2"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "" + "define stream LoginEvents (timestamp long, ip string) ;"; String query = "" + "@info(name = 'query1') " + "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec) " + "select timestamp, ip, count() as total " + "insert all events into uniqueIps ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"}); inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"}); inputHandler.send(new Object[]{1366335805340L, "192.10.1.4"}); inputHandler.send(new Object[]{1366335814341L, "192.10.1.5"}); inputHandler.send(new Object[]{1366335814345L, "192.10.1.6"}); inputHandler.send(new Object[]{1366335824341L, "192.10.1.7"}); Thread.sleep(1000); org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived); org.testng.AssertJUnit.assertEquals("In Events ", 2, inEventCount); org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount); siddhiManager.shutdown(); }
Example 13
Source File: TimeBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void timeWindowBatchTest16() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);"; String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(1 sec, true, 100) " + "select symbol, sum(price) as total " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 1}); Thread.sleep(1100); inputHandler.send(new Object[]{"WSO2", 60.5f, 2}); inputHandler.send(new Object[]{"IBM", 700f, 3}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); Thread.sleep(1100); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); Thread.sleep(1200); AssertJUnit.assertEquals(6, inEventCount); AssertJUnit.assertEquals(3, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 14
Source File: EventOutputRateLimitTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testEventOutputRateLimitQuery15() throws InterruptedException { log.info("EventOutputRateLimit test15"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "@app:name('EventOutputRateLimitTest15') " + "" + "define stream LoginEvents (timestamp long, ip string);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.lengthBatch(4) " + "select ip , count() as total " + "output all every 2 events " + "insert expired events into uniqueIps ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); log.info("Running : " + siddhiAppRuntime.getName()); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (removeEvents != null) { count += removeEvents.length; } else { AssertJUnit.fail("InEvents emitted"); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.9"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.30"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.31"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.32"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.33"}); Thread.sleep(1000); AssertJUnit.assertEquals("Event arrived", true, eventArrived); AssertJUnit.assertEquals("Number of output event value", 2, count); siddhiAppRuntime.shutdown(); }
Example 15
Source File: PrimaryKeyTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void primaryKeyTableTest3() throws InterruptedException { log.info("primaryKeyTableTest3"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long);" + "@PrimaryKey('volume') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream join StockTable " + " on CheckStockStream.volume > StockTable.volume " + "select CheckStockStream.symbol, StockTable.symbol as tableSymbol, StockTable.volume " + "insert into OutStream;"; 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) { for (Event event : inEvents) { inEventsList.add(event.getData()); inEventCount.incrementAndGet(); } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 200L}); stockStream.send(new Object[]{"GOOG", 50.6f, 50L}); stockStream.send(new Object[]{"ABC", 5.6f, 70L}); checkStockStream.send(new Object[]{"IBM", 100L}); checkStockStream.send(new Object[]{"FOO", 60L}); List<Object[]> expected1 = Arrays.asList( new Object[]{"IBM", "GOOG", 50L}, new Object[]{"IBM", "ABC", 70L} ); List<Object[]> expected2 = new ArrayList<Object[]>(); expected2.add(new Object[]{"FOO", "GOOG", 50L}); SiddhiTestHelper.waitForEvents(100, 3, inEventCount, 60000); AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList .subList(0, 2), expected1)); AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList .subList(2, 3), expected2)); AssertJUnit.assertEquals("Number of success events", 3, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); } finally { siddhiAppRuntime.shutdown(); } }
Example 16
Source File: LengthBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testLengthBatchWindow5() throws InterruptedException { final int length = 2; SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) lengthBatch(" + length + ") output " + "expired events; "; String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow " + "select symbol,price,volume " + "insert expired events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count++; AssertJUnit.assertEquals("Remove event order", count, event.getData(2)); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 1}); inputHandler.send(new Object[]{"WSO2", 60.5f, 2}); inputHandler.send(new Object[]{"IBM", 700f, 3}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); Thread.sleep(500); AssertJUnit.assertEquals("Remove event count", 4, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 17
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery18() throws InterruptedException { log.info("Partition test18"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest18') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "@info(name = 'query')from cseEventStreamOne select symbol,price,volume insert into cseEventStream;" + "partition with (price>=100 as 'large' or price<100 as 'small' of cseEventStream) begin @info(name " + "= 'query1') from cseEventStream#window.length(4) select symbol,sum(price) 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); for (Event event : events) { count.incrementAndGet(); eventArrived = true; if (count.get() == 1) { AssertJUnit.assertEquals(25.0, event.getData()[1]); } else if (count.get() == 2) { AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]); } else if (count.get() == 3) { AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0)); } else if (count.get() == 4) { AssertJUnit.assertEquals(100.0, event.getData()[1]); } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 25f, 100}); inputHandler.send(new Object[]{"WSO2", 7005.6f, 100}); inputHandler.send(new Object[]{"IBM", 50f, 100}); inputHandler.send(new Object[]{"ORACLE", 25f, 100}); SiddhiTestHelper.waitForEvents(100, 3, count, 60000); AssertJUnit.assertTrue(count.get() <= 4); siddhiAppRuntime.shutdown(); }
Example 18
Source File: UpdateOrInsertTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void updateOrInsertTableTest9() throws InterruptedException { log.info("updateOrInsertTableTest9"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream left outer join StockTable " + " on UpdateStockStream.comp == StockTable.symbol " + "select symbol, ifThenElse(price is null,0f,price) as price, vol as volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("query3", 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", 100L, 155.6f}, event.getData()); break; case 2: AssertJUnit.assertArrayEquals(new Object[]{"IBM", 200L, 155.6f}, event.getData()); break; default: AssertJUnit.assertSame(2, inEventCount); } } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 155.6f, 100L}); checkStockStream.send(new Object[]{"IBM", 100L, 155.6f}); checkStockStream.send(new Object[]{"WSO2", 100L, 155.6f}); updateStockStream.send(new Object[]{"IBM", 200L}); checkStockStream.send(new Object[]{"IBM", 200L, 155.6f}); checkStockStream.send(new Object[]{"WSO2", 100L, 155.6f}); Thread.sleep(500); AssertJUnit.assertEquals("Number of success events", 2, inEventCount); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); siddhiAppRuntime.shutdown(); }
Example 19
Source File: LogicalAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"testQueryAbsent61"}) public void testQueryAbsent62() throws InterruptedException { log.info("Test the query every (e1 and not e2 for 1 sec), e3 with e3, e3, e2, e3"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from every (e2=Stream2[price>20] and not Stream1[price>10] for 1 sec), " + "e3=Stream3[price>30] " + "select e2.symbol as symbol2, e3.symbol as symbol3 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"ORACLE", "GOOGLE"}); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); Thread.sleep(1200); stream3.send(new Object[]{"WSO2", 35.0f, 100}); Thread.sleep(1200); stream3.send(new Object[]{"IBM", 55.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"ORACLE", 65.0f, 100}); Thread.sleep(100); stream3.send(new Object[]{"GOOGLE", 75.0f, 100}); TestUtil.waitForInEvents(100, callback, 5); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertTrue("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 20
Source File: TimeBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void timeWindowBatchTest2() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);"; String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(1 sec) " + "select symbol, sum(price) as price " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + 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; } if (removeEvents != null) { AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount); removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 1}); Thread.sleep(1100); inputHandler.send(new Object[]{"WSO2", 60.5f, 2}); inputHandler.send(new Object[]{"IBM", 700f, 3}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); Thread.sleep(1100); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); Thread.sleep(2000); AssertJUnit.assertEquals(3, inEventCount); AssertJUnit.assertEquals(1, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }