Search in sources :

Example 1 with YAMLConfigManager

use of io.siddhi.core.util.config.YAMLConfigManager in project siddhi by wso2.

the class YAMLConfigManagerTestCase method yamlConfigManagerTest2.

@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();
}
Also used : Path(java.nio.file.Path) InputHandler(io.siddhi.core.stream.input.InputHandler) YAMLConfigManager(io.siddhi.core.util.config.YAMLConfigManager) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) StringConcatAggregatorExecutorString(io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 2 with YAMLConfigManager

use of io.siddhi.core.util.config.YAMLConfigManager in project siddhi by wso2.

the class YAMLConfigManagerTestCase method yamlConfigManagerTest1.

@Test
public void yamlConfigManagerTest1() {
    log.info("YAMLConfigManagerTest1");
    String baseDir = Paths.get(".").toString();
    Path filePath = Paths.get(baseDir, "src", "test", "resources", "systemProperties.yaml");
    String fileContent = FileReader.readYAMLConfigFile(filePath);
    YAMLConfigManager yamlConfigManager = new YAMLConfigManager(fileContent);
    Map<String, String> testConfigs = yamlConfigManager.extractSystemConfigs("test");
    Assert.assertEquals(testConfigs.size(), 0);
    Map<String, String> source1Ref = yamlConfigManager.extractSystemConfigs("ref1");
    Assert.assertEquals(source1Ref.size(), 3);
    Assert.assertEquals(source1Ref.get("type"), "testStoreContainingInMemoryTable");
    Assert.assertEquals(source1Ref.get("property1"), "value1");
    Assert.assertEquals(source1Ref.get("property2"), "value2");
    Assert.assertNull(source1Ref.get("property3"));
    String partitionById = yamlConfigManager.extractProperty("partitionById");
    Assert.assertEquals(partitionById, "TRUE");
    String shardID1 = yamlConfigManager.extractProperty("shardId1");
    Assert.assertNull(shardID1);
    ConfigReader testConfigReader = yamlConfigManager.generateConfigReader("test", "test");
    Assert.assertEquals(testConfigReader.getAllConfigs().size(), 0);
    ConfigReader configReader = yamlConfigManager.generateConfigReader("store", "rdbms");
    Assert.assertEquals(configReader.getAllConfigs().size(), 5);
    Assert.assertEquals(configReader.readConfig("mysql.batchEnable", "test"), "true");
    Assert.assertEquals(configReader.readConfig("test", "test"), "test");
}
Also used : Path(java.nio.file.Path) YAMLConfigManager(io.siddhi.core.util.config.YAMLConfigManager) ConfigReader(io.siddhi.core.util.config.ConfigReader) StringConcatAggregatorExecutorString(io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString) Test(org.testng.annotations.Test)

Example 3 with YAMLConfigManager

use of io.siddhi.core.util.config.YAMLConfigManager in project siddhi by wso2.

the class YAMLConfigManagerTestCase method yamlConfigManagerTest4.

@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();
}
Also used : Path(java.nio.file.Path) InputHandler(io.siddhi.core.stream.input.InputHandler) YAMLConfigManager(io.siddhi.core.util.config.YAMLConfigManager) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) StringConcatAggregatorExecutorString(io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 4 with YAMLConfigManager

use of io.siddhi.core.util.config.YAMLConfigManager in project siddhi by wso2.

the class YAMLConfigManagerTestCase method yamlConfigManagerTest3.

@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();
}
Also used : Path(java.nio.file.Path) YAMLConfigManager(io.siddhi.core.util.config.YAMLConfigManager) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) StringConcatAggregatorExecutorString(io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

StringConcatAggregatorExecutorString (io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString)4 YAMLConfigManager (io.siddhi.core.util.config.YAMLConfigManager)4 Path (java.nio.file.Path)4 Test (org.testng.annotations.Test)4 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)3 SiddhiManager (io.siddhi.core.SiddhiManager)3 Event (io.siddhi.core.event.Event)2 InputHandler (io.siddhi.core.stream.input.InputHandler)2 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)1 ConfigReader (io.siddhi.core.util.config.ConfigReader)1