Java Code Examples for io.siddhi.core.SiddhiAppRuntime#query()
The following examples show how to use
io.siddhi.core.SiddhiAppRuntime#query() .
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: OnDemandQueryTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = OnDemandQueryCreationException.class) public void test5() throws InterruptedException { log.info("Test5 table"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams); try { siddhiAppRuntime.start(); Event[] events = siddhiAppRuntime.query("" + "from StockTable1 " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals(200L, events[0].getData(1)); } finally { siddhiAppRuntime.shutdown(); } }
Example 2
Source File: UpdateOrInsertTableWithCacheTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateOrInsertTableTest11() throws InterruptedException, SQLException { log.info("updateOrInsertTableTest11"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\", @Cache(size=\"10\"))\n" + "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.volume==volume ;"; 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); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); AssertJUnit.assertEquals(3, events.length); siddhiAppRuntime.shutdown(); }
Example 3
Source File: Aggregation1TestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest35"}, expectedExceptions = StoreQueryCreationException.class) public void incrementalStreamProcessorTest36() throws InterruptedException { LOG.info("incrementalStreamProcessorTest36"); 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(); Thread.sleep(100); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within 1513578087000L " + "per \"hours\""); EventPrinter.print(events); Thread.sleep(100); siddhiAppRuntime.shutdown(); }
Example 4
Source File: OnDemandQueryTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test21() throws InterruptedException { log.info("Testing update on-demand query parser failure"); 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, sum(price) as totalPrice, avg(price) as avgPrice " + "group by symbol " + "aggregate by timestamp every sec...year ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); siddhiAppRuntime.start(); try { siddhiAppRuntime.query("from stockAggregation within 0L, 1543664151000L per " + "'minutes' select AGG_TIMESTAMP2, symbol, totalPrice, avgPrice "); Thread.sleep(100); Assert.fail("Expected OnDemandQueryCreationException exception"); } catch (OnDemandQueryCreationException e) { String expectedCauseBy = "@ Line: 1. Position: 83, near 'AGG_TIMESTAMP2'. " + "No matching stream reference found for attribute 'AGG_TIMESTAMP2'"; Assert.assertTrue(e.getCause().getMessage().endsWith(expectedCauseBy)); } siddhiAppRuntime.shutdown(); }
Example 5
Source File: QueryAPITestCaseForTableWithCache.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test10() throws InterruptedException { log.info("Test10 table with cache"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); 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}); Thread.sleep(500); String storeQuery = "" + "from StockTable " + "on volume > 10 " + "select symbol, sum(volume) as totalVolume " + "group by symbol " + "having symbol == 'WSO2'"; Event[] events = siddhiAppRuntime.query(storeQuery); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals(200L, events[0].getData()[1]); events = siddhiAppRuntime.query(storeQuery); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals(200L, events[0].getData()[1]); }
Example 6
Source File: QueryAPITestCaseForTableWithCache.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = StoreQueryCreationException.class) public void test5() { log.info("Test5 table with cache"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams); try { siddhiAppRuntime.start(); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals(200L, events[0].getData(1)); } finally { siddhiAppRuntime.shutdown(); } }
Example 7
Source File: OnDemandQueryTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test7() throws InterruptedException { log.info("Test7 table"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); 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}); Thread.sleep(500); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on symbol == 'IBM' " + "select symbol, volume "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals("IBM", events[0].getData()[0]); }
Example 8
Source File: SelectOptimisationAggregationTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"aggregationFunctionTestcase13"}) public void aggregationFunctionTestcase15() throws InterruptedException { LOG.info("aggregationFunctionTestcase15 - Group by AGG_TIMESTAMP"); SiddhiManager siddhiManager = new SiddhiManager(); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);"; String query = "@purge(enable='false')" + " define aggregation stockAggregation " + "from stockStream " + "select symbol, sum(price) as totalPrice " + "group by symbol " + "aggregate by timestamp every sec...hour ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // 1 June 2017 04:05:50 stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L}); stockStreamInputHandler.send(new Object[]{"IBM", 70f, null, 40L, 10, 1496289950000L}); // 1 June 2017 04:05:52 stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L}); stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 16, 1496289952500L}); // 1 June 2017 04:05:54 stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L}); stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 96, 1496289954500L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query( "from stockAggregation " + "within \"2017-06-** **:**:**\" " + "per \"seconds\" " + "select AGG_TIMESTAMP, sum(totalPrice) as totalPrice " + "group by AGG_TIMESTAMP;"); EventPrinter.print(events); Assert.assertNotNull(events); AssertJUnit.assertEquals(3, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1496289950000L, 120.0}, new Object[]{1496289952000L, 160.0}, new Object[]{1496289954000L, 200.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 9
Source File: DeleteFromTestStoreTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void deleteFromTestStoreTest7() throws InterruptedException, SQLException { log.info("deleteFromTestStoreTest7"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream DeleteStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream " + "delete StockTable " + " on StockTable.symbol == symbol ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream"); 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}); deleteStockStream.send(new Object[]{"IBM", 57.6F, 100L}); Thread.sleep(1000); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); try { AssertJUnit.assertEquals(2, events.length); } catch (NullPointerException ignore) { } siddhiAppRuntime.shutdown(); }
Example 10
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneHour"}) public void incrementalStreamProcessorTest5SGTTimeZoneHour2() throws InterruptedException { //feb 29 leap end hour LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("aggTimeZone", "Asia/Singapore"); ConfigManager configManager = new InMemoryConfigManager(null, null, systemConfigs); siddhiManager.setConfigManager(configManager); String stockStream = "define stream stockStream (symbol string, price float, timestamp long);"; String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "aggregate by timestamp every hour ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Saturday February 29, 2020 23:00:01 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1582988401000L}); // Saturday February 29, 2020 23:59:59 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1582991999000L}); // Sunday March 01, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1582992001000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2020-**-** **:**:**\" " + "per \"hour\""); EventPrinter.print(events); Assert.assertNotNull(events, "Queried results cannot be null."); AssertJUnit.assertEquals(2, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1582988400000L, "WSO2", 60.0}, new Object[]{1582992000000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 11
Source File: PurgingTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void incrementalPurgingTestCase3() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, " + "volume long , quantity int, timestamp long); "; String query = " @purge(enable='true',interval='10 sec',@retentionPeriod(sec='120 sec',min='all',hours='all'," + "days='all',months='all',years='all')) " + "define aggregation stockAggregation " + "from stockStream " + "select symbol, sum(price) as totalPrice " + "group by symbol " + "aggregate by timestamp every sec...year ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); try { InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Thursday, June 1, 2017 4:05:50 AM stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L}); Thread.sleep(1000); // Thursday, June 1, 2017 4:05:51 AM stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 16, 1496289951011L}); Thread.sleep(1000); // Thursday, June 1, 2017 4:05:52 AM stockStreamInputHandler.send(new Object[]{"IBM", 400f, null, 200L, 9, 1496289952000L}); Thread.sleep(1000); // Thursday, June 1, 2017 4:05:50 AM stockStreamInputHandler.send(new Object[]{"IBM", 900f, null, 200L, 60, 1496289950000L}); Thread.sleep(1000); stockStreamInputHandler.send(new Object[]{"WSO2", 500f, null, 200L, 7, 1496289951011L}); Thread.sleep(1000); // Thursday, June 1, 2017 4:05:53 AM stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289953000L}); Thread.sleep(1000); stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 96, 1496289953000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation within 0L, 1543664151000L per " + "'seconds' select AGG_TIMESTAMP, symbol, totalPrice "); EventPrinter.print(events); AssertJUnit.assertEquals("Check time windows", 7, events.length); List<Object[]> eventsList = new ArrayList<>(); for (Event event : events) { eventsList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1496289950000L, "WSO2", 50.0}, new Object[]{1496289950000L, "IBM", 900.0}, new Object[]{1496289951000L, "IBM", 100.0}, new Object[]{1496289951000L, "WSO2", 500.0}, new Object[]{1496289952000L, "IBM", 400.0}, new Object[]{1496289953000L, "IBM", 100.0}, new Object[]{1496289953000L, "WSO2", 100.0} ); AssertJUnit.assertTrue("Data Matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsList, expected)); Thread.sleep(80000); events = siddhiAppRuntime.query("from stockAggregation within 0L, 1543664151000L per " + "'seconds' select AGG_TIMESTAMP, symbol, totalPrice "); EventPrinter.print(events); Assert.assertNull(events); } finally { siddhiAppRuntime.shutdown(); } }
Example 12
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneDay4"}) public void incrementalStreamProcessorTest5SGTTimeZoneDay5() throws InterruptedException { //dec 31 2019 LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("aggTimeZone", "Asia/Singapore"); ConfigManager configManager = new InMemoryConfigManager(null, null, systemConfigs); siddhiManager.setConfigManager(configManager); String stockStream = "define stream stockStream (symbol string, price float, timestamp long);"; String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "aggregate by timestamp every day ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Monday December 31, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1577721601000L}); // Tuesday December 31, 2019 23:59:59 (pm in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1577807999000L}); // Wednesday January 01, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1577808001000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2019-**-** **:**:**\" " + "per \"day\""); EventPrinter.print(events); Assert.assertNotNull(events, "Queried results cannot be null."); AssertJUnit.assertEquals(2, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1577721600000L, "WSO2", 60.0}, new Object[]{1577808000000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 13
Source File: SelectOptimisationAggregationTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "aggregationFunctionTestcase7") public void aggregationFunctionTestcase8() throws InterruptedException { LOG.info("aggregationFunctionTestcase8 - count w/o group by on-demand query"); 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 count() as count " + "aggregate by timestamp every sec, min ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); try { InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Thursday, June 1, 2017 4:05:50 AM stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L}); stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L}); // Thursday, June 1, 2017 4:05:52 AM stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L}); stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L}); // Thursday, June 1, 2017 4:05:54 AM stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L}); stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L}); // Thursday, June 1, 2017 4:05:56 AM stockStreamInputHandler.send(new Object[]{"IBM", 900f, null, 200L, 60, 1496289956000L}); stockStreamInputHandler.send(new Object[]{"IBM", 500f, null, 200L, 7, 1496289956000L}); // Thursday, June 1, 2017 4:06:56 AM stockStreamInputHandler.send(new Object[]{"IBM", 400f, null, 200L, 9, 1496290016000L}); // Thursday, June 1, 2017 4:07:56 AM stockStreamInputHandler.send(new Object[]{"IBM", 600f, null, 200L, 6, 1496290076000L}); // Thursday, June 1, 2017 5:07:56 AM stockStreamInputHandler.send(new Object[]{"CISCO", 700f, null, 200L, 20, 1496293676000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("" + "from stockAggregation " + "within 1496200000000L, 1596434876000L " + "per \"seconds\" " + "select AGG_TIMESTAMP, count " + "order by AGG_TIMESTAMP;"); AssertJUnit.assertNotNull("Event arrived", events); AssertJUnit.assertEquals("Number of success events", 7, events.length); List<Object[]> actual = new ArrayList<>(); for (Event event : events) { actual.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1496289950000L, 2L}, new Object[]{1496289952000L, 2L}, new Object[]{1496289954000L, 2L}, new Object[]{1496289956000L, 2L}, new Object[]{1496290016000L, 1L}, new Object[]{1496290076000L, 1L}, new Object[]{1496293676000L, 1L} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isEventsMatch(actual, expected)); } finally { siddhiAppRuntime.shutdown(); } }
Example 14
Source File: UpdateOrInsertTestStoreTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void updateOrInsertTableTest13() throws InterruptedException, SQLException { log.info("updateOrInsertTableTest12"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "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.volume == volume ;"; 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 Event[]{ new Event(System.currentTimeMillis(), new Object[]{"GOOG", 10.6F, 200L}), new Event(System.currentTimeMillis(), new Object[]{"FB", 11.6F, 200L}), } ); Thread.sleep(500); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); AssertJUnit.assertEquals(4, events.length); siddhiAppRuntime.shutdown(); }
Example 15
Source File: CacheLFUTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(description = "cacheLFUTestCase3") // 2 primary keys & LFU & cointains api (in) public void cacheLFUTestCase3() throws InterruptedException, SQLException { final TestAppenderToValidateLogsForCachingTests appender = new TestAppenderToValidateLogsForCachingTests(); final Logger logger = Logger.getRootLogger(); logger.setLevel(Level.DEBUG); logger.addAppender(appender); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream DeleteStockStream (symbol string, price float, volume long); " + "define stream CheckInStockStream (symbol string, price float); " + "@Store(type=\"testStoreForCacheMiss\", @Cache(size=\"2\", cache.policy=\"LFU\"))\n" + "@PrimaryKey(\'symbol\', \'price\') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream " + "delete StockTable " + " on StockTable.symbol == symbol AND StockTable.price == price AND StockTable.volume == volume;" + "" + "@info(name = 'query3') " + "from CheckInStockStream[(StockTable.symbol == symbol AND StockTable.price == price) in StockTable]\n" + "insert into OutputStream ;"; 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: Assert.assertEquals(event.getData(), new Object[]{"WSO2", 55.6f}); break; } } eventArrived = true; } } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream"); InputHandler checkInStockStream = siddhiAppRuntime.getInputHandler("CheckInStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 1L}); Thread.sleep(10); stockStream.send(new Object[]{"APPLE", 75.6f, 4L}); Thread.sleep(10); checkInStockStream.send(new Object[]{"WSO2", 55.6f}); Thread.sleep(10); stockStream.send(new Object[]{"CISCO", 86.6f, 5L}); Thread.sleep(10); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on symbol == \"APPLE\" AND price == 75.6f "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); final List<LoggingEvent> log = appender.getLog(); List<String> logMessages = new ArrayList<>(); for (LoggingEvent logEvent : log) { String message = String.valueOf(logEvent.getMessage()); if (message.contains(":")) { message = message.split(": ")[1]; } logMessages.add(message); } Assert.assertEquals(logMessages. contains("store table size is smaller than max cache. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("store table size is bigger than cache."), true); Assert.assertEquals(Collections.frequency(logMessages, "store table size is bigger than cache."), 1); Assert.assertEquals(logMessages.contains("cache constraints satisfied. Checking cache"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache constraints satisfied. Checking cache"), 1); Assert.assertEquals(logMessages.contains("cache hit. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("cache miss. Loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache miss. Loading from store"), 1); Assert.assertEquals(logMessages.contains("store also miss. sending null"), false); Assert.assertEquals(logMessages.contains("sending results from cache after loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "sending results from cache after loading from store"), 1); Assert.assertEquals(logMessages.contains("sending results from store"), false); siddhiAppRuntime.shutdown(); }
Example 16
Source File: QueryAPITestCaseForTestStore.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test3() throws InterruptedException { log.info("Test3 table with cache"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); 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}); Thread.sleep(500); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol " + "having symbol == 'WSO2' "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); AssertJUnit.assertEquals(200L, events[0].getData(1)); events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol "); EventPrinter.print(events); AssertJUnit.assertEquals(2, events.length); events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol,price "); EventPrinter.print(events); AssertJUnit.assertEquals(3, events.length); siddhiAppRuntime.shutdown(); }
Example 17
Source File: CacheLFUTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(description = "cacheLFUTestCase4") // 1 primary key & LFU & update func public void cacheLFUTestCase4() throws InterruptedException, SQLException { final TestAppenderToValidateLogsForCachingTests appender = new TestAppenderToValidateLogsForCachingTests(); final Logger logger = Logger.getRootLogger(); logger.setLevel(Level.DEBUG); logger.addAppender(appender); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreForCacheMiss\", @Cache(size=\"2\", cache.policy=\"LFU\"))\n" + "@PrimaryKey(\'symbol\') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream\n" + "select symbol, price, volume\n" + "update StockTable\n" + "on (StockTable.symbol == symbol);"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); 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) { inEventCount++; switch (inEventCount) { case 1: Assert.assertEquals(event.getData(), new Object[]{"WSO2", 66.5f, 3L}); break; } } eventArrived = true; } } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 1L}); Thread.sleep(10); stockStream.send(new Object[]{"APPLE", 75.6f, 2L}); Thread.sleep(10); updateStockStream.send(new Object[]{"WSO2", 66.5f, 3L}); Thread.sleep(10); stockStream.send(new Object[]{"CISCO", 86.6f, 5L}); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on symbol == \"APPLE\" "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); final List<LoggingEvent> log = appender.getLog(); List<String> logMessages = new ArrayList<>(); for (LoggingEvent logEvent : log) { String message = String.valueOf(logEvent.getMessage()); if (message.contains(":")) { message = message.split(": ")[1]; } logMessages.add(message); } Assert.assertEquals(logMessages. contains("store table size is smaller than max cache. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("store table size is bigger than cache."), true); Assert.assertEquals(Collections.frequency(logMessages, "store table size is bigger than cache."), 1); Assert.assertEquals(logMessages.contains("cache constraints satisfied. Checking cache"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache constraints satisfied. Checking cache"), 1); Assert.assertEquals(logMessages.contains("cache hit. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("cache miss. Loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache miss. Loading from store"), 1); Assert.assertEquals(logMessages.contains("store also miss. sending null"), false); Assert.assertEquals(logMessages.contains("sending results from cache after loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "sending results from cache after loading from store"), 1); Assert.assertEquals(logMessages.contains("sending results from store"), false); siddhiAppRuntime.shutdown(); }
Example 18
Source File: QueryAPITestCaseForTableWithCache.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test11() throws InterruptedException { log.info("Test10 table with cache"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); 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}); Thread.sleep(500); String storeQuery = "" + "from StockTable " + "on price > 56 " + "select symbol, price, sum(volume) as totalVolume " + "group by symbol, price "; Event[] events = siddhiAppRuntime.query(storeQuery); EventPrinter.print(events); AssertJUnit.assertEquals(2, events.length); AssertJUnit.assertEquals(100L, events[0].getData()[2]); AssertJUnit.assertEquals(100L, events[1].getData()[2]); events = siddhiAppRuntime.query(storeQuery); EventPrinter.print(events); AssertJUnit.assertEquals(2, events.length); AssertJUnit.assertEquals(100L, events[0].getData()[2]); AssertJUnit.assertEquals(100L, events[1].getData()[2]); }
Example 19
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneDay"}) public void incrementalStreamProcessorTest5SGTTimeZoneDay2() throws InterruptedException { //feb 29 leap LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("aggTimeZone", "Asia/Singapore"); ConfigManager configManager = new InMemoryConfigManager(null, null, systemConfigs); siddhiManager.setConfigManager(configManager); String stockStream = "define stream stockStream (symbol string, price float, timestamp long);"; String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "aggregate by timestamp every day ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Saturday February 29, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1582905601000L}); // Saturday February 29, 2020 23:59:59 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1582991999000L}); // Sunday March 01, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1582992001000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2020-**-** **:**:**\" " + "per \"day\""); EventPrinter.print(events); Assert.assertNotNull(events, "Queried results cannot be null."); AssertJUnit.assertEquals(2, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1582905600000L, "WSO2", 60.0}, new Object[]{1582992000000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 20
Source File: CacheMissTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(description = "cacheMissTestCase1") public void cacheMissTestCase1() throws InterruptedException, SQLException { final TestAppenderToValidateLogsForCachingTests appender = new TestAppenderToValidateLogsForCachingTests(); final Logger logger = Logger.getRootLogger(); logger.setLevel(Level.DEBUG); logger.addAppender(appender); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream DeleteStockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreForCacheMiss\", @Cache(size=\"1\", cache.policy=\"FIFO\"))\n" + "@PrimaryKey('symbol') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream " + "delete StockTable " + " on StockTable.symbol == symbol AND StockTable.price == price AND StockTable.volume == volume;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream"); siddhiAppRuntime.start(); deleteStockStream.send(new Object[]{"WSO2", 55.6f, 100L}); deleteStockStream.send(new Object[]{"IBM", 75.6f, 100L}); Thread.sleep(1000); Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on symbol == \"WSO2\" "); EventPrinter.print(events); AssertJUnit.assertEquals(1, events.length); final List<LoggingEvent> log = appender.getLog(); List<String> logMessages = new ArrayList<>(); for (LoggingEvent logEvent : log) { String message = String.valueOf(logEvent.getMessage()); if (message.contains(":")) { message = message.split(": ")[1]; } logMessages.add(message); } Assert.assertEquals(logMessages. contains("store table size is smaller than max cache. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("store table size is bigger than cache."), true); Assert.assertEquals(Collections.frequency(logMessages, "store table size is bigger than cache."), 1); Assert.assertEquals(logMessages.contains("cache constraints satisfied. Checking cache"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache constraints satisfied. Checking cache"), 1); Assert.assertEquals(logMessages.contains("cache hit. Sending results from cache"), false); Assert.assertEquals(logMessages.contains("cache miss. Loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "cache miss. Loading from store"), 1); Assert.assertEquals(logMessages.contains("store also miss. sending null"), false); Assert.assertEquals(logMessages.contains("sending results from cache after loading from store"), true); Assert.assertEquals(Collections.frequency(logMessages, "sending results from cache after loading from store"), 1); Assert.assertEquals(logMessages.contains("sending results from store"), false); siddhiAppRuntime.shutdown(); }