Search in sources :

Example 6 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneDay5.

@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();
}
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 7 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest55.

@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();
}
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 8 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneMonth.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest5SGTTimeZoneDay5" })
public void incrementalStreamProcessorTest5SGTTimeZoneMonth() 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 month ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query);
    // siddhiAppRuntime.
    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 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 \"month\"");
    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[] { 1582992000000L, "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 9 with InMemoryConfigManager

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

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(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 10 with InMemoryConfigManager

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

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(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)

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