use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.
the class TestStoreForCacheMiss method init.
@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
inMemoryTable = new InMemoryTable();
MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
cacheTableMetaStreamEvent.addOutputData(attribute);
}
StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
for (Attribute attribute : tableDefinition.getAttributeList()) {
testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
}
for (Annotation annotation : tableDefinition.getAnnotations()) {
if (!annotation.getName().equalsIgnoreCase("Store")) {
testStoreContainingIMTableDefinition.annotation(annotation);
}
}
inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.
the class TestStoreForCachePreLoading method init.
@Override
protected void init(TableDefinition tableDefinition, ConfigReader configReader) {
inMemoryTable = new InMemoryTable();
MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
cacheTableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
cacheTableMetaStreamEvent.addOutputData(attribute);
}
StreamEventCloner testTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, storeEventPool);
TableDefinition testStoreContainingIMTableDefinition = TableDefinition.id(tableDefinition.getId());
for (Attribute attribute : tableDefinition.getAttributeList()) {
testStoreContainingIMTableDefinition.attribute(attribute.getName(), attribute.getType());
}
for (Annotation annotation : tableDefinition.getAnnotations()) {
if (!annotation.getName().equalsIgnoreCase("Store")) {
testStoreContainingIMTableDefinition.annotation(annotation);
}
}
inMemoryTable.init(testStoreContainingIMTableDefinition, storeEventPool, testTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
ComplexEventChunk<StreamEvent> originalData = new ComplexEventChunk<>();
StreamEvent data1 = new StreamEvent(0, 0, 3);
data1.setOutputData(new Object[] { "WSO2", 55.6f, 100L });
originalData.add(data1);
StreamEvent data2 = new StreamEvent(0, 0, 3);
data2.setOutputData(new Object[] { "IBM", 75.6f, 100L });
originalData.add(data2);
inMemoryTable.add(originalData);
}
use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.
the class SandboxTestCase method sandboxTest2.
@Test
public void sandboxTest2() throws InterruptedException {
log.info("sandbox test2");
SiddhiManager siddhiManager = new SiddhiManager();
String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + " on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
SiddhiApp siddhiApp = SiddhiCompiler.parse(app);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(siddhiApp);
Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
for (List<Source> sources : siddhiAppRuntime.getSources()) {
for (Source source : sources) {
Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
}
}
for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
for (Sink sink : sinks) {
Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
}
}
for (Table table : siddhiAppRuntime.getTables()) {
Assert.assertTrue(table instanceof InMemoryTable);
}
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
}
});
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 });
deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
countStockStream.send(new Object[] { "WSO2" });
Thread.sleep(500);
Assert.assertEquals(count.get(), 2);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.
the class DefinitionParserHelper method addTable.
public static void addTable(TableDefinition tableDefinition, ConcurrentMap<String, Table> tableMap, SiddhiAppContext siddhiAppContext) {
if (!tableMap.containsKey(tableDefinition.getId())) {
MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.addInputDefinition(tableDefinition);
for (Attribute attribute : tableDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
}
StreamEventFactory tableStreamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
StreamEventCloner tableStreamEventCloner = new StreamEventCloner(tableMetaStreamEvent, tableStreamEventFactory);
Annotation annotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_STORE, tableDefinition.getAnnotations());
Table table;
ConfigReader configReader = null;
RecordTableHandlerManager recordTableHandlerManager = null;
RecordTableHandler recordTableHandler = null;
if (annotation != null) {
annotation = updateAnnotationRef(annotation, SiddhiConstants.NAMESPACE_STORE, siddhiAppContext);
String tableType = annotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
if (tableType == null) {
throw new SiddhiAppCreationException("Attribute 'type' does not exist for annotation '" + annotation + "'", annotation, siddhiAppContext);
}
Extension extension = new Extension() {
@Override
public String getNamespace() {
return SiddhiConstants.NAMESPACE_STORE;
}
@Override
public String getName() {
return tableType;
}
};
recordTableHandlerManager = siddhiAppContext.getSiddhiContext().getRecordTableHandlerManager();
if (recordTableHandlerManager != null) {
recordTableHandler = recordTableHandlerManager.generateRecordTableHandler();
}
table = (Table) SiddhiClassLoader.loadExtensionImplementation(extension, TableExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(extension.getNamespace(), extension.getName());
} else {
table = new InMemoryTable();
}
table.initTable(tableDefinition, tableStreamEventFactory, tableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
if (recordTableHandler != null) {
recordTableHandlerManager.registerRecordTableHandler(recordTableHandler.getId(), recordTableHandler);
}
tableMap.putIfAbsent(tableDefinition.getId(), table);
}
}
use of io.siddhi.core.table.InMemoryTable in project siddhi by wso2.
the class SandboxTestCase method sandboxTest1.
@Test
public void sandboxTest1() throws InterruptedException {
log.info("sandbox test1");
SiddhiManager siddhiManager = new SiddhiManager();
String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + " on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(app);
Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1);
Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1);
for (List<Source> sources : siddhiAppRuntime.getSources()) {
for (Source source : sources) {
Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory"));
}
}
for (List<Sink> sinks : siddhiAppRuntime.getSinks()) {
for (Sink sink : sinks) {
Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory"));
}
}
for (Table table : siddhiAppRuntime.getTables()) {
Assert.assertTrue(table instanceof InMemoryTable);
}
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream");
siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
}
});
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 });
deleteStockStream.send(new Object[] { "IBM", 57.6f, 100L });
countStockStream.send(new Object[] { "WSO2" });
Thread.sleep(500);
Assert.assertEquals(count.get(), 2);
siddhiAppRuntime.shutdown();
}
Aggregations