io.siddhi.core.SiddhiAppRuntime Java Examples
The following examples show how to use
io.siddhi.core.SiddhiAppRuntime.
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 = {"incrementalStreamProcessorTest5SGTTimeZoneYear"}, expectedExceptions = SiddhiAppCreationException.class) public void incrementalStreamProcessorTestInvalidTimeZone() throws InterruptedException { LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> configMap = new HashMap<>(); configMap.put("aggTimeZone", "Asia/Singapo"); ConfigManager configManager = new InMemoryConfigManager(null, null, configMap); 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 year ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); siddhiAppRuntime.shutdown(); }
Example #2
Source File: InMemoryTransportTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = {"inMemoryTestCase4"}) public void inMemoryTestCase5() throws InterruptedException { log.info("Test inMemory 5"); String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='inMemory', topic='Foo', @map(type='passThrough', @attributes(symbol='symbol'," + "volume='volume',price='price'))) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='inMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); }
Example #3
Source File: DefineTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testQuery18() { log.info("testTableDefinition18 - Table w/ ref and additional properties"); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("test1.type", "test"); systemConfigs.put("test1.uri", "http://localhost"); InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs); inMemoryConfigManager.extractSystemConfigs("test1"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(inMemoryConfigManager); siddhiManager.setExtension("store:test", TestStore.class); String siddhiApp = "" + "@store(ref='test1', uri='http://localhost:8080', table.name ='Foo')" + "define table testTable (symbol string, price int, volume float); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.shutdown(); Map<String, String> expectedSystemConfigs = new HashMap<>(); expectedSystemConfigs.put("type", "test"); expectedSystemConfigs.put("uri", "http://localhost:8080"); expectedSystemConfigs.put("table.name", "Foo"); AssertJUnit.assertEquals("Test store initialization failure", expectedSystemConfigs, TestStore.systemConfigs); }
Example #4
Source File: Aggregation1TestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest19"}, expectedExceptions = StoreQueryCreationException.class) public void incrementalStreamProcessorTest20() throws InterruptedException { LOG.info("incrementalStreamProcessorTest20"); SiddhiManager siddhiManager = new SiddhiManager(); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int, timestamp long);"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream); siddhiAppRuntime.start(); siddhiAppRuntime.query("from stockAggregation " + "on symbol == \"IBM\" " + "within \"2017-**-** **:**:** +05:30\" " + "per \"seconds\"; "); Thread.sleep(100); siddhiAppRuntime.shutdown(); }
Example #5
Source File: InMemoryTransportTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class, dependsOnMethods = {"inMemoryTestCase3"}) public void inMemoryTestCase4() throws InterruptedException { log.info("Test inMemory 4"); String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='inMemory', topic='Foo', @map(type='passThrough', @attributes('symbol','price'))) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='inMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); }
Example #6
Source File: JoinTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppValidationException.class) public void joinTest13() throws InterruptedException { log.info("Join test13"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, symbol string); "; String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.symbol " + "select * " + "insert into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); try { siddhiAppRuntime.start(); } finally { siddhiAppRuntime.shutdown(); } }
Example #7
Source File: LogicalAbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent37"}) public void testQueryAbsent38() throws InterruptedException { log.info("Test the query (not e1 for 1 sec and not e2 for 1 sec) -> e3 with e1 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 stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); Thread.sleep(500); stream1.send(new Object[]{"IBM", 15.0f, 100}); Thread.sleep(600); stream3.send(new Object[]{"WSO2", 35.0f, 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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example #8
Source File: Aggregation1TestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest27"}, expectedExceptions = StoreQueryCreationException.class) public void incrementalStreamProcessorTest28() throws InterruptedException { LOG.info("incrementalStreamProcessorTest28"); 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 \"2017-06-02 00:00:00\", \"2017-06-01 00:00:00\" " + "per \"hours\""); EventPrinter.print(events); Thread.sleep(100); siddhiAppRuntime.shutdown(); }
Example #9
Source File: UpdateTableWithCacheTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateFromTableTest1() throws InterruptedException, SQLException { log.info("updateFromTableTest1"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price double, volume long); " + "define stream UpdateStockStream (symbol string, price double, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price double, volume long); "; String query = "" + "@info(name = 'query1')\n" + "from StockStream\n" + "insert into StockTable;\n" + "@info(name = 'query2') " + "from UpdateStockStream\n" + "select symbol, price, volume\n" + "update StockTable\n" + "on (StockTable.symbol == symbol);"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6, 100L}); stockStream.send(new Object[]{"IBM", 75.6, 100L}); stockStream.send(new Object[]{"WSO2", 57.6, 100L}); updateStockStream.send(new Object[]{"IBM", 57.6, 100L}); Thread.sleep(1000); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); AssertJUnit.assertEquals(3, events.length); siddhiAppRuntime.shutdown(); }
Example #10
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 #11
Source File: LogicalAbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent17"}) public void testQueryAbsent18() throws InterruptedException { log.info("Test the query not e1 for 1 sec or e2 -> e3 with e3 after 1 sec"); 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 or e2=Stream2[price>20] -> 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[]{null, "GOOGLE"}); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); Thread.sleep(1100); stream3.send(new Object[]{"GOOGLE", 35.0f, 100}); Thread.sleep(100); 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 #12
Source File: LogicalAbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent1"}) public void testQueryAbsent2() throws InterruptedException { log.info("Test the query e1 -> not e2 and 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 e1=Stream1[price>10] -> not Stream2[price>20] and e3=Stream3[price>30] " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "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[]{"WSO2", 15.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 25.0f, 100}); Thread.sleep(100); stream3.send(new Object[]{"GOOGLE", 35.0f, 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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example #13
Source File: StreamFunctionTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void pol2CartFunctionTest() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String polarStream = "define stream PolarStream (theta double, rho double);"; String query = "@info(name = 'query1') " + "from PolarStream#pol2Cart(theta, rho) " + "select x, y " + "insert into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(polarStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { inEventCount = inEventCount + inEvents.length; AssertJUnit.assertEquals(12, Math.round((Double) inEvents[0].getData(0))); AssertJUnit.assertEquals(5, Math.round((Double) inEvents[0].getData(1))); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("PolarStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{22.6, 13.0}); Thread.sleep(100); AssertJUnit.assertEquals(1, inEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #14
Source File: MinimumFunctionExtensionTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testMinFunctionExtension2() throws InterruptedException { log.info("MinimumFunctionExecutor TestCase 2"); SiddhiManager siddhiManager = new SiddhiManager(); String inStreamDefinition = "define stream inputStream (price1 int,price2 double, price3 double);"; String query = ("@info(name = 'query1') from inputStream " + "select minimum(price1, price2, price3) as min " + "insert into outputStream;"); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query); siddhiAppRuntime.shutdown(); }
Example #15
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery99() throws InterruptedException { log.info("Filter test99"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(4L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); 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", 500f, 50d, 6}); inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2}); inputHandler.send(new Object[]{"WSO2", 50f, 300d, 4}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); AssertJUnit.assertEquals(2, count.get()); siddhiAppRuntime.shutdown(); }
Example #16
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery22() throws InterruptedException { log.info("Partition test22"); 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 > 10" + "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(75.0, event.getData()[1]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75f, 100}); inputHandler.send(new Object[]{"IBM", 75f, 100}); SiddhiTestHelper.waitForEvents(200, 1, count, 60000); AssertJUnit.assertTrue(1 <= count.get()); siddhiAppRuntime.shutdown(); }
Example #17
Source File: LogicalAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent32"}) public void testQueryAbsent33() throws InterruptedException { log.info("Test the query (not e1 for 1 sec or not e2 for 1 sec), e3 with e3 only"); 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 or 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", new Object[]{"WSO2"}); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); Thread.sleep(1100); stream3.send(new Object[]{"WSO2", 35.0f, 100}); Thread.sleep(1100); stream3.send(new Object[]{"WSO2", 35.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 #18
Source File: Aggregation1TestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest20"}, expectedExceptions = StoreQueryCreationException.class) public void incrementalStreamProcessorTest21() throws InterruptedException { LOG.info("incrementalStreamProcessorTest21"); 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 \"2017-06-** **:**:**\" " + "per \"days\""); EventPrinter.print(events); Thread.sleep(100); siddhiAppRuntime.shutdown(); }
Example #19
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 #20
Source File: SetUpdateInMemoryTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateFromTableTest2() throws InterruptedException, SQLException { log.info("SET-RDBMS-update test case 2: setting a subset of columns"); 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 StockTable " + "set StockTable.price = price, StockTable.symbol = symbol " + " on StockTable.symbol == symbol ;"; 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[]{"IBM", 100f, 100L}); Thread.sleep(1000); siddhiAppRuntime.shutdown(); }
Example #21
Source File: SetUpdateOrInsertInMemoryTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateFromTableTest3() throws InterruptedException, SQLException { log.info("SET-InMemory-update-or-insert test case 3: using a constant value as the assigment expression."); 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 " + "set StockTable.price = 10 " + " on StockTable.symbol == symbol ;"; 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[]{"IBM", 100f, 100L}); Thread.sleep(1000); siddhiAppRuntime.shutdown(); }
Example #22
Source File: DeleteFromTestStoreTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void deleteFromTestStoreTest5() throws InterruptedException, SQLException { log.info("deleteFromTestStoreTest5"); 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 and StockTable.price > price and StockTable.volume == volume ;"; 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[]{"IBM", 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 #23
Source File: EveryAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQueryAbsent3() throws InterruptedException { log.info("Test the query every not e1, e2 with e1 and e2 after 1 sec"); 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", new Object[]{"IBM"}); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 59.6f, 100}); Thread.sleep(2100); stream2.send(new Object[]{"IBM", 58.7f, 100}); Thread.sleep(100); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example #24
Source File: InsertIntoTestStoreTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void insertIntoTestStoreTest2() throws InterruptedException, SQLException { //Testing table creation with a compound primary key (normal insertion) log.info("insertIntoTestStoreTest2"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "@PrimaryKey(\"symbol\", \"price\")" + "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[]{"MSFT", 57.6F, 100L}); stockStream.send(new Object[]{"WSO2", 58.6F, 100L}); Thread.sleep(1000); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); AssertJUnit.assertEquals(4, events.length); siddhiAppRuntime.shutdown(); }
Example #25
Source File: AbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent4"}) public void testQueryAbsent5() throws InterruptedException { log.info("Test the query not e1, e2 without e1"); 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 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", new Object[]{"IBM"}); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); Thread.sleep(1100); stream2.send(new Object[]{"IBM", 58.7f, 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 not arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example #26
Source File: AbsentWithEveryPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQuery5() throws InterruptedException { log.info("Test the query not e1 for 1 sec -> every e2 with e1 and e2"); 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 not Stream1[price>10] for 1sec -> every e2=Stream2[price>20] " + "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[]{"IBM", 55.7f, 100}); Thread.sleep(100); stream2.send(new Object[]{"WSO2", 55.6f, 100}); Thread.sleep(100); stream2.send(new Object[]{"GOOG", 55.6f, 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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example #27
Source File: ExternalTimeBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void schedulerLastBatchTriggerTest() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String inputStream = "define stream inputStream(currentTime long,value int); "; String query = " " + "@info(name='query') " + "from inputStream#window.externalTimeBatch(currentTime,5 sec, 0, 6 sec) " + "select value, currentTime " + "insert current events into outputStream; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query); siddhiAppRuntime.addCallback("query", new QueryCallback() { int count = 0; @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { if (count == 0) { AssertJUnit.assertEquals(1, inEvents[0].getData(0)); } else if (count == 1) { AssertJUnit.assertEquals(6, inEvents[0].getData(0)); } else if (count == 2) { AssertJUnit.assertEquals(11, inEvents[0].getData(0)); } else if (count == 3) { AssertJUnit.assertEquals(14, inEvents[0].getData(0)); } else if (count == 4) { AssertJUnit.assertEquals(15, inEvents[0].getData(0)); } count += 1; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{10000L, 1}); Thread.sleep(100); inputHandler.send(new Object[]{11000L, 2}); Thread.sleep(100); inputHandler.send(new Object[]{12000L, 3}); Thread.sleep(100); inputHandler.send(new Object[]{13000L, 4}); Thread.sleep(100); inputHandler.send(new Object[]{14000L, 5}); Thread.sleep(100); inputHandler.send(new Object[]{15000L, 6}); Thread.sleep(100); inputHandler.send(new Object[]{16500L, 7}); Thread.sleep(100); inputHandler.send(new Object[]{17000L, 8}); Thread.sleep(100); inputHandler.send(new Object[]{18000L, 9}); Thread.sleep(100); inputHandler.send(new Object[]{19000L, 10}); Thread.sleep(100); inputHandler.send(new Object[]{20100L, 11}); Thread.sleep(100); inputHandler.send(new Object[]{20500L, 12}); Thread.sleep(100); inputHandler.send(new Object[]{22000L, 13}); Thread.sleep(100); inputHandler.send(new Object[]{25000L, 14}); Thread.sleep(100); inputHandler.send(new Object[]{32000L, 15}); Thread.sleep(100); inputHandler.send(new Object[]{33000L, 16}); Thread.sleep(6000); siddhiManager.shutdown(); }
Example #28
Source File: LogicalPatternTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testQuery15() throws InterruptedException { log.info("testQuery15 - 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 query = "" + "@info(name = 'query1') " + "from every (e1=Stream1[price > 20] and e2=Stream2[price >30]) " + "select e1.symbol as symbol1, e2.price as price2 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); if (inEvents != null) { inEventCount = inEventCount + inEvents.length; eventArrived = true; switch (inEventCount) { case 1: AssertJUnit.assertArrayEquals(new Object[]{"WSO2", 35.0f}, inEvents[0].getData()); break; case 2: AssertJUnit.assertArrayEquals(new Object[]{"GOOGLE", 55.0f}, inEvents[0].getData()); } } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 25.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 35.0f, 100}); Thread.sleep(100); stream1.send(new Object[]{"GOOGLE", 45.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"ORACLE", 55.0f, 100}); Thread.sleep(100); AssertJUnit.assertEquals("Number of success events", 2, inEventCount); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); siddhiAppRuntime.shutdown(); }
Example #29
Source File: TestDebugger.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testDebugger3() throws InterruptedException { log.info("Siddi Debugger Test 3: Test next traversal in a query with time batch window"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"; String query = "@info(name = 'query1')" + "from cseEventStream#window.timeBatch(3 sec) " + "select symbol, price, volume " + "insert into OutputStream; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() { @Override public void receive(Event[] events) { inEventCount.addAndGet(events.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug(); siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN); siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() { @Override public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) { log.info("Query: " + queryName + "\t" + System.currentTimeMillis()); log.info(event); int count = debugEventCount.addAndGet(getCount(event)); if (count == 1) { AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal); AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[]{"WSO2", 50f, 60}, event.getOutputData()); } else if (count == 2) { AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal); AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[]{"WSO2", 70f, 40}, event.getOutputData()); } else if (count == 3) { AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal); AssertJUnit.assertArrayEquals("Incorrect debug event received at IN", new Object[]{"WSO2", 60f, 50}, event.getOutputData()); } // next call will not reach OUT since there is a window debugger.next(); } }); inputHandler.send(new Object[]{"WSO2", 50f, 60}); inputHandler.send(new Object[]{"WSO2", 70f, 40}); inputHandler.send(new Object[]{"WSO2", 60f, 50}); Thread.sleep(3500); AssertJUnit.assertEquals("Invalid number of output events", 3, inEventCount.get()); AssertJUnit.assertEquals("Invalid number of debug events", 3, debugEventCount.get()); siddhiAppRuntime.shutdown(); }
Example #30
Source File: CastFunctionExecutorTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testCastFunctionExtension5() throws InterruptedException { log.info("CastFunctionExecutor TestCase 5"); SiddhiManager siddhiManager = new SiddhiManager(); String inStreamDefinition = "\ndefine stream inputStream (symbol string, price object, volume long);"; String query = ("@info(name = 'query1') from inputStream select symbol,price, " + "cast(price, 'float') as priceInFloat insert into outputStream;"); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); for (Event event : inEvents) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(100.3f, event.getData(2)); eventArrived = true; } if (count.get() == 2) { AssertJUnit.assertEquals(true, event.getData(2)); eventArrived = true; } if (count.get() == 3) { AssertJUnit.assertEquals(300f, event.getData(2)); eventArrived = true; } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 100.3f, 100L}); inputHandler.send(new Object[]{"WSO2", true, 200L}); inputHandler.send(new Object[]{"XYZ", 300f, 200L}); SiddhiTestHelper.waitForEvents(100, 3, count, 60000); AssertJUnit.assertEquals(3, count.get()); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }