Search in sources :

Example 1 with ConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneDay2.

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

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

the class Aggregation2TestCase method incrementalStreamProcessorTestInvalidTimeZone.

@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();
}
Also used : InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) 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 3 with ConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneYear.

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

use of io.siddhi.core.util.config.ConfigManager 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 5 with ConfigManager

use of io.siddhi.core.util.config.ConfigManager 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)

Aggregations

ConfigManager (io.siddhi.core.util.config.ConfigManager)11 HashMap (java.util.HashMap)11 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)10 SiddhiManager (io.siddhi.core.SiddhiManager)10 InMemoryConfigManager (io.siddhi.core.util.config.InMemoryConfigManager)10 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)10 Event (io.siddhi.core.event.Event)9 InputHandler (io.siddhi.core.stream.input.InputHandler)9 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 Executor (io.siddhi.core.aggregation.Executor)1 IncrementalAggregationProcessor (io.siddhi.core.aggregation.IncrementalAggregationProcessor)1 IncrementalDataPurger (io.siddhi.core.aggregation.IncrementalDataPurger)1 IncrementalExecutor (io.siddhi.core.aggregation.IncrementalExecutor)1 IncrementalExecutorsInitialiser (io.siddhi.core.aggregation.IncrementalExecutorsInitialiser)1 CudStreamProcessorQueueManager (io.siddhi.core.aggregation.persistedaggregation.CudStreamProcessorQueueManager)1 PersistedIncrementalExecutor (io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor)1 QueuedCudStreamProcessor (io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor)1 DBAggregationQueryConfigurationEntry (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationQueryConfigurationEntry)1 DBAggregationQueryUtil (io.siddhi.core.aggregation.persistedaggregation.config.DBAggregationQueryUtil)1