use of io.siddhi.core.event.Event in project siddhi by wso2.
the class UpdateOrInsertTestStoreTestCase method updateOrInsertTableTest10.
@Test
public void updateOrInsertTableTest10() throws InterruptedException, SQLException {
log.info("updateOrInsertTableTest10");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream left outer join StockTable " + " on UpdateStockStream.comp == StockTable.symbol " + "select comp as symbol, ifThenElse(price is nulL,5F,price) as price, vol as volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume == StockTable.volume and " + "price < StockTable.price) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 0f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 300L, 4.6f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6F, 100L });
checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
updateStockStream.send(new Object[] { "IBM", 200L });
updateStockStream.send(new Object[] { "WSO2", 300L });
checkStockStream.send(new Object[] { "IBM", 200L, 0f });
checkStockStream.send(new Object[] { "WSO2", 300L, 4.6f });
Thread.sleep(1000);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class UpdateOrInsertTestStoreTestCase method updateOrInsertTableTest7.
@Test
public void updateOrInsertTableTest7() throws InterruptedException, SQLException {
log.info("updateOrInsertTableTest7");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "@Store(type=\"testStoreContainingInMemoryTable\")\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select comp as symbol, 5f as price, vol as volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price " + "< StockTable.price) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 56.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 0f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6F, 100L });
stockStream.send(new Object[] { "IBM", 155.6F, 100L });
checkStockStream.send(new Object[] { "IBM", 100L, 56.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
updateStockStream.send(new Object[] { "IBM", 200L });
checkStockStream.send(new Object[] { "IBM", 200L, 0f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
Thread.sleep(2000);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class TestStoreContainingInMemoryTable method query.
@Override
protected RecordIterator<Object[]> query(Map<String, Object> parameterMap, CompiledCondition compiledCondition, CompiledSelection compiledSelection, Attribute[] outputAttributes) {
StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
List<Object[]> objects = new LinkedList<>();
CompiledSelectionWithCache compiledSelectionWithCache = null;
if (outEvent != null) {
compiledSelectionWithCache = (CompiledSelectionWithCache) compiledSelection;
StateEventFactory stateEventFactory = new StateEventFactory(compiledSelectionWithCache.getMetaStateEvent());
Event[] cacheResultsAfterSelection = executeSelector(stateEventFactory, null, outEvent, compiledSelectionWithCache.getStoreEventIndex(), compiledSelectionWithCache.getQuerySelector());
if (compiledSelectionWithCache.getQuerySelector() != null & compiledSelectionWithCache.getQuerySelector().getAttributeProcessorList().size() != 0) {
compiledSelectionWithCache.getQuerySelector().process(generateResetComplexEventChunk(outEvent.getOutputData().length, stateEventFactory));
}
if (cacheResultsAfterSelection != null) {
for (Event event : cacheResultsAfterSelection) {
objects.add(event.getData());
}
}
}
return new TestStoreWithCacheIterator(objects.iterator());
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class TestStoreForCacheMiss method query.
@Override
protected RecordIterator<Object[]> query(Map<String, Object> parameterMap, CompiledCondition compiledCondition, CompiledSelection compiledSelection, Attribute[] outputAttributes) {
StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
List<Object[]> objects = new LinkedList<>();
CompiledSelectionWithCache compiledSelectionWithCache = null;
if (outEvent != null) {
compiledSelectionWithCache = (CompiledSelectionWithCache) compiledSelection;
StateEventFactory stateEventFactory = new StateEventFactory(compiledSelectionWithCache.getMetaStateEvent());
Event[] cacheResultsAfterSelection = executeSelector(stateEventFactory, null, outEvent, compiledSelectionWithCache.getStoreEventIndex(), compiledSelectionWithCache.getQuerySelector());
if (compiledSelectionWithCache.getQuerySelector() != null & compiledSelectionWithCache.getQuerySelector().getAttributeProcessorList().size() != 0) {
compiledSelectionWithCache.getQuerySelector().process(generateResetComplexEventChunk(outEvent.getOutputData().length, stateEventFactory));
}
if (cacheResultsAfterSelection != null) {
for (Event event : cacheResultsAfterSelection) {
objects.add(event.getData());
}
}
}
return new TestStoreWithCacheIterator(objects.iterator());
}
use of io.siddhi.core.event.Event in project siddhi by wso2.
the class CronWindowTestCase method cronWindowTest2.
@Test
public void cronWindowTest2() throws InterruptedException {
log.info("Testing cron window for expired events");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);";
String query = "@info(name = 'query1') " + "from cseEventStream#window.cron('*/5 * * * * ?') " + "select symbol,price,volume " + "insert expired events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
for (Event event : events) {
removeEventCount++;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 0 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 1 });
Thread.sleep(7000);
inputHandler.send(new Object[] { "IBM1", 700f, 0 });
inputHandler.send(new Object[] { "WSO22", 60.5f, 1 });
Thread.sleep(7000);
inputHandler.send(new Object[] { "IBM43", 700f, 0 });
inputHandler.send(new Object[] { "WSO4343", 60.5f, 1 });
SiddhiTestHelper.waitForEvents(7000, 4, removeEventCount, 20000);
AssertJUnit.assertEquals(4, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations