Search in sources :

Example 16 with InMemoryConfigManager

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

the class Aggregation2TestCase method incrementalStreamProcessorTest5SGTTimeZoneDay4.

@Test(dependsOnMethods = { "incrementalStreamProcessorTest5SGTTimeZoneDay3" })
public void incrementalStreamProcessorTest5SGTTimeZoneDay4() throws InterruptedException {
    // jan 31
    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 January 31, 2019 00:00:01 (am) in time zone Asia/Singapore (+08)
    stockStreamInputHandler.send(new Object[] { "WSO2", 50f, 1548864001000L });
    // Saturday January 31, 2019 23:59:59 (pm) in time zone Asia/Singapore (+08)
    stockStreamInputHandler.send(new Object[] { "WSO2", 70f, 1548950399000L });
    // Sunday February 01, 2019 00:00:01 (am) in time zone Asia/Singapore (+08)
    stockStreamInputHandler.send(new Object[] { "WSO2", 80f, 1548950401000L });
    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[] { 1548864000000L, "WSO2", 60.0 }, new Object[] { 1548950400000L, "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 17 with InMemoryConfigManager

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

Example 18 with InMemoryConfigManager

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

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

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

the class DefineTableTestCase method testQuery20.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQuery20() {
    log.info("testTableDefinition20 - Table w/ ref to an undefined store");
    Map<String, String> systemConfigs = new HashMap<>();
    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)

Example 20 with InMemoryConfigManager

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

the class InMemoryTransportTestCase method inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef.

@Test(dependsOnMethods = { "inMemoryTestCase9" })
public void inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef() throws InterruptedException, SubscriberUnAvailableException {
    log.info("Test inMemory Source Sink And EventMapping With SiddhiQL and Ref");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            wso2Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "WSO2";
        }
    };
    InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            ibmCount.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "IBM";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "@source(ref='test1', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(ref='test2', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    Map<String, String> systemConfigs = new HashMap<>();
    systemConfigs.put("test1.topic", "Foo");
    systemConfigs.put("test1.type", "inMemory");
    systemConfigs.put("test2.type", "inMemory");
    systemConfigs.put("test2.topic", "{{symbol}}");
    InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setConfigManager(inMemoryConfigManager);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.start();
    InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
    InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
    InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of WSO2 events", 2, wso2Count.get());
    AssertJUnit.assertEquals("Number of IBM events", 1, ibmCount.get());
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) InMemoryBroker(io.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) 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