Java Code Examples for io.siddhi.core.SiddhiManager#setConfigManager()
The following examples show how to use
io.siddhi.core.SiddhiManager#setConfigManager() .
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: DefineTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testQuery16() { log.info("testTableDefinition16 - Table w/ ref"); 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')" + "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"); AssertJUnit.assertEquals("Test store initialization failure", expectedSystemConfigs, TestStore.systemConfigs); }
Example 2
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 3
Source File: DefineTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testQuery19() { log.info("testTableDefinition19 - Table w/ ref w/o type"); Map<String, String> systemConfigs = new HashMap<>(); 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(); }
Example 4
Source File: DefineTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testQuery20() { log.info("testTableDefinition20 - Table w/ ref to an undefined store"); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("test1.uri", "http://localhost"); InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs); inMemoryConfigManager.extractSystemConfigs("test2"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(inMemoryConfigManager); siddhiManager.setExtension("store:test", TestStore.class); String siddhiApp = "" + "@store(ref='test2', uri='http://localhost:8080', table.name ='Foo')" + "define table testTable (symbol string, price int, volume float); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.shutdown(); }
Example 5
Source File: DefineTableTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testQuery21() { log.info("testTableDefinition21 - Table w/ ref to an undefined store type"); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("test1.type", "testdb"); systemConfigs.put("test1.uri", "http://localhost"); InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs); inMemoryConfigManager.extractSystemConfigs("test2"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(inMemoryConfigManager); siddhiManager.setExtension("store:test", TestStore.class); String siddhiApp = "" + "@store(ref='test2', uri='http://localhost:8080', table.name ='Foo')" + "define table testTable (symbol string, price int, volume float); "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.shutdown(); }
Example 6
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest54"}, expectedExceptions = SiddhiAppCreationException.class) public void incrementalStreamProcessorTest55() { Map<String, String> propertiesMap = new HashMap<>(); propertiesMap.put("partitionById", "true"); InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, null, propertiesMap); LOG.info("incrementalStreamProcessorTest55 - Checking @partitionbyid overriding"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(inMemoryConfigManager); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int);\n"; String query = "@PartitionById(enable='false') " + "define aggregation stockAggregation " + "from stockStream " + "select avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue " + "aggregate every sec...year; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); siddhiAppRuntime.start(); }
Example 7
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest55"}, expectedExceptions = SiddhiAppCreationException.class) public void incrementalStreamProcessorTest56() { Map<String, String> propertiesMap = new HashMap<>(); propertiesMap.put("partitionById", "true"); InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, null, propertiesMap); LOG.info("incrementalStreamProcessorTest55 - Checking partitionbyid system param overriding"); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(inMemoryConfigManager); String stockStream = "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " + "quantity int);\n"; String query = "" + "define aggregation stockAggregation " + "from stockStream " + "select avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " + "as lastTradeValue " + "aggregate every sec...year; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); siddhiAppRuntime.start(); }
Example 8
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 9
Source File: YAMLConfigManagerTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void yamlConfigManagerTest3() { log.info("YAMLConfigManagerTest2 - Undefined References test"); String baseDir = Paths.get(".").toString(); Path path = Paths.get(baseDir, "src", "test", "resources", "systemProperties.yaml"); String fileContent = FileReader.readYAMLConfigFile(path); YAMLConfigManager yamlConfigManager = new YAMLConfigManager(fileContent); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(yamlConfigManager); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(ref='ref2')\n" + "define table StockTable (symbol string, volume long); "; String query1 = "" + "@info(name = 'query1') " + "from StockStream\n" + "select symbol, volume\n" + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query1); siddhiAppRuntime.start(); }
Example 10
Source File: YAMLConfigManagerTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void yamlConfigManagerTest2() throws InterruptedException { log.info("YAMLConfigManagerTest2 - References test"); String baseDir = Paths.get(".").toString(); Path path = Paths.get(baseDir, "src", "test", "resources", "systemProperties.yaml"); String fileContent = FileReader.readYAMLConfigFile(path); YAMLConfigManager yamlConfigManager = new YAMLConfigManager(fileContent); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setConfigManager(yamlConfigManager); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(ref='ref1')\n" + "define table StockTable (symbol string, volume long); "; String query1 = "" + "@info(name = 'query1') " + "from StockStream\n" + "select symbol, volume\n" + "insert into StockTable ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query1); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 75.6f, 100L}); Thread.sleep(1000); Event[] events = siddhiAppRuntime.query("" + "from StockTable "); EventPrinter.print(events); AssertJUnit.assertEquals(2, events.length); siddhiAppRuntime.shutdown(); }
Example 11
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneHour2"}) public void incrementalStreamProcessorTest5SGTTimeZoneDay() throws InterruptedException { //normal day 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 01, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1580486401000L}); // Saturday February 01, 2020 23:59:59 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1580572799000L}); // Sunday February 02, 2020 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1580572801000L}); 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[]{1580486400000L, "WSO2", 60.0}, new Object[]{1580572800000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 12
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 13
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneDay2"}) public void incrementalStreamProcessorTest5SGTTimeZoneDay3() throws InterruptedException { //feb 28 non-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 28, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1551283201000L}); // Saturday February 28, 2019 23:59:59 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1551369599000L}); // Sunday March 01, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1551369601000L}); 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[]{1551283200000L, "WSO2", 60.0}, new Object[]{1551369600000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 14
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneDay3"}) public void incrementalStreamProcessorTest5SGTTimeZoneDay4() throws InterruptedException { //jan 31 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 January 31, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1548864001000L}); // Saturday January 31, 2019 23:59:59 (pm) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1548950399000L}); // Sunday February 01, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1548950401000L}); 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[]{1548864000000L, "WSO2", 60.0}, new Object[]{1548950400000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 15
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 16
Source File: YAMLConfigManagerTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void yamlConfigManagerTest4() throws InterruptedException { log.info("yamlConfigManagerTest4"); String baseDir = Paths.get(".").toString(); Path path = Paths.get(baseDir, "src", "test", "resources", "systemProperties.yaml"); String fileContent = FileReader.readYAMLConfigFile(path); YAMLConfigManager yamlConfigManager = new YAMLConfigManager(fileContent); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setExtension("email:getAllNew", StringConcatAggregatorExecutorString.class); siddhiManager.setConfigManager(yamlConfigManager); String cseEventStream = "" + "" + "define stream cseEventStream (symbol string, price float, volume long);"; String query = ("" + "@info(name = 'query1') " + "from cseEventStream " + "select price , email:getAllNew(symbol,'') as toConcat " + "group by volume " + "insert into mailOutput;"); 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 = count + inEvents.length; if (count == 3) { AssertJUnit.assertEquals("WSO2ABC-abc", inEvents[inEvents.length - 1].getData(1)); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 100L}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 60.5f, 200L}); Thread.sleep(100); inputHandler.send(new Object[]{"ABC", 60.5f, 200L}); Thread.sleep(100); AssertJUnit.assertEquals(3, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 17
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest5SGTTimeZoneMonth"}) public void incrementalStreamProcessorTest5SGTTimeZoneYear() throws InterruptedException { LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> configMap = new HashMap<>(); configMap.put("aggTimeZone", "Asia/Singapore"); 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. InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Tuesday January 01, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1546272001000L}); // 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 \"2018-**-** **:**:**\" " + "per \"year\""); EventPrinter.print(events); Assert.assertNotNull(events, "Queried results cannot be null."); AssertJUnit.assertEquals(1, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = new ArrayList<>(); expected.add(new Object[]{1546272000000L, "WSO2", 60.0}); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 18
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 19
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest57"}) public void incrementalStreamProcessorTest5SGTTimeZoneHour() throws InterruptedException { 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(); // 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 00:59:59 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1577725199000L}); // Tuesday December 31, 2019 01:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1577725201000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2019-**-** **:**:**\" " + "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[]{1577721600000L, "WSO2", 60.0}, new Object[]{1577725200000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 20
Source File: ExtensionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void extensionTest5() throws InterruptedException, ClassNotFoundException { log.info("extension test5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> configMap = new HashMap<>(); configMap.put("email.getAllNew.append.abc", "true"); siddhiManager.setConfigManager(new InMemoryConfigManager(configMap, null)); siddhiManager.setExtension("custom:plus", CustomFunctionExtension.class); siddhiManager.setExtension("email:getAllNew", StringConcatAggregatorExecutorString.class); String cseEventStream = "" + "" + "define stream cseEventStream (symbol string, price float, volume long);"; String query = ("" + "@info(name = 'query1') " + "from cseEventStream " + "select price , email:getAllNew(symbol,'') as toConcat " + "group by volume " + "insert into mailOutput;"); 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 = count + inEvents.length; if (count == 3) { AssertJUnit.assertEquals("WSO2ABC-abc", inEvents[inEvents.length - 1].getData(1)); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 100L}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 60.5f, 200L}); Thread.sleep(100); inputHandler.send(new Object[]{"ABC", 60.5f, 200L}); Thread.sleep(100); AssertJUnit.assertEquals(3, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }