Search in sources :

Example 11 with ConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneHour2.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest5SGTTimeZoneHour" })
public void incrementalStreamProcessorTest5SGTTimeZoneHour2() throws InterruptedException {
    // feb 29 leap end hour
    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();
    // Saturday February 29, 2020 23:00:01 (pm) in time zone Asia/Singapore (+08)
    stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 1582988401000L });
    // 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 \"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[] { 1582988400000L, "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