use of org.wso2.siddhi.core.util.config.InMemoryConfigManager in project siddhi by wso2.
the class DefineTableTestCase method testQuery18.
@Test
public void testQuery18() {
log.info("testTableDefinition18 - Table w/ ref and additional properties");
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', uri='http://localhost:8080', table.name ='Foo')" + "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:8080");
expectedSystemConfigs.put("table.name", "Foo");
AssertJUnit.assertEquals("Test store initialization failure", expectedSystemConfigs, TestStore.systemConfigs);
}
use of org.wso2.siddhi.core.util.config.InMemoryConfigManager in project siddhi by wso2.
the class DefineTableTestCase method testQuery21.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQuery21() {
log.info("testTableDefinition21 - Table w/ ref to an undefined store type");
Map<String, String> systemConfigs = new HashMap<>();
systemConfigs.put("test1.type", "testdb");
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();
}
use of org.wso2.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);
}
use of org.wso2.siddhi.core.util.config.InMemoryConfigManager in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef.
@Test
public void inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef() throws InterruptedException {
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);
}
use of org.wso2.siddhi.core.util.config.InMemoryConfigManager in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase 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