Search in sources :

Example 11 with InMemoryConfigManager

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

the class DefineTableTestCase method testQuery19.

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

Example 12 with InMemoryConfigManager

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

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", 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();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) 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 13 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneHour.

@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();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) ConfigManager(io.siddhi.core.util.config.ConfigManager) Test(org.testng.annotations.Test)

Example 14 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneDay.

@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();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) ConfigManager(io.siddhi.core.util.config.ConfigManager) Test(org.testng.annotations.Test)

Example 15 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneDay3.

@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();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) ConfigManager(io.siddhi.core.util.config.ConfigManager) Test(org.testng.annotations.Test)

Aggregations

SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)21 SiddhiManager (io.siddhi.core.SiddhiManager)21 InMemoryConfigManager (io.siddhi.core.util.config.InMemoryConfigManager)21 HashMap (java.util.HashMap)21 Test (org.testng.annotations.Test)21 InputHandler (io.siddhi.core.stream.input.InputHandler)12 Event (io.siddhi.core.event.Event)11 ConfigManager (io.siddhi.core.util.config.ConfigManager)10 ArrayList (java.util.ArrayList)9 InMemoryBroker (io.siddhi.core.util.transport.InMemoryBroker)3 StringConcatAggregatorExecutorString (io.siddhi.core.query.extension.util.StringConcatAggregatorExecutorString)1 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)1