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);
}
Aggregations