Search in sources :

Example 21 with InMemoryConfigManager

use of io.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(io.siddhi.core.stream.input.InputHandler) InMemoryConfigManager(io.siddhi.core.util.config.InMemoryConfigManager) HashMap(java.util.HashMap) InMemoryBroker(io.siddhi.core.util.transport.InMemoryBroker) 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