Search in sources :

Example 6 with InMemoryConfigManager

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

the class SingleClientDistributedTransportTestCases method singleClientBroadcastWithRef.

@Test
public void singleClientBroadcastWithRef() throws InterruptedException {
    log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params with ref");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

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

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

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

        @Override
        public String getTopic() {
            return "topic2";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(ref='test1', @map(type='passThrough'), " + "   @distribution(strategy='broadcast'," + "       @destination(ref = 'test2'), " + "       @destination(ref = 'test3'))) " + "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.type", "testInMemory");
    systemConfigs.put("test2.topic", "topic1");
    systemConfigs.put("test3.topic", "topic2");
    InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setConfigManager(inMemoryConfigManager);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "IBM", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    Thread.sleep(100);
    // assert event count
    AssertJUnit.assertEquals("Number of topic 1 events", 6, topic1Count.get());
    AssertJUnit.assertEquals("Number of topic 2 events", 6, topic2Count.get());
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(org.wso2.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) InMemoryBroker(org.wso2.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 7 with InMemoryConfigManager

use of org.wso2.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(org.wso2.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 8 with InMemoryConfigManager

use of org.wso2.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(org.wso2.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 9 with InMemoryConfigManager

use of org.wso2.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", StringConcatAggregatorString.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(org.wso2.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(org.wso2.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) StringConcatAggregatorString(org.wso2.siddhi.core.query.extension.util.StringConcatAggregatorString) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)9 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)9 InMemoryConfigManager (org.wso2.siddhi.core.util.config.InMemoryConfigManager)9 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)3 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)3 Event (org.wso2.siddhi.core.event.Event)2 StringConcatAggregatorString (org.wso2.siddhi.core.query.extension.util.StringConcatAggregatorString)1 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)1