Search in sources :

Example 6 with InMemoryConfigManager

use of org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager in project ballerina by ballerina-lang.

the class DefineTableTestCase method testQuery16.

@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);
}
Also used : InMemoryConfigManager(org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 7 with InMemoryConfigManager

use of org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager in project ballerina by ballerina-lang.

the class DefineTableTestCase method testQuery18.

@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);
}
Also used : InMemoryConfigManager(org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 8 with InMemoryConfigManager

use of org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager in project ballerina by ballerina-lang.

the class DefineTableTestCase method testQuery21.

@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();
}
Also used : InMemoryConfigManager(org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 9 with InMemoryConfigManager

use of org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager in project ballerina by ballerina-lang.

the class ExtensionTestCase method extensionTest5.

@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", StringConcatAggregatorString.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();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) StringConcatAggregatorString(org.ballerinalang.siddhi.core.query.extension.util.StringConcatAggregatorString) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)9 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)9 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)9 InMemoryConfigManager (org.ballerinalang.siddhi.core.util.config.InMemoryConfigManager)9 Test (org.testng.annotations.Test)9 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)3 InMemoryBroker (org.ballerinalang.siddhi.core.util.transport.InMemoryBroker)3 Event (org.ballerinalang.siddhi.core.event.Event)2 StringConcatAggregatorString (org.ballerinalang.siddhi.core.query.extension.util.StringConcatAggregatorString)1 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)1