Search in sources :

Example 56 with Event

use of io.siddhi.core.event.Event in project siddhi by wso2.

the class UpdateTestStoreTestCase method updateFromTableTest4.

@Test
public void updateFromTableTest4() throws InterruptedException, SQLException {
    log.info("updateFromTableTest4");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume 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 CheckStockStream[(StockTable.symbol==symbol) in StockTable] " + "insert into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    siddhiAppRuntime.addCallback("query2", 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++;
                }
                eventArrived = true;
            }
        }
    });
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 55.6f, 100L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    checkStockStream.send(new Object[] { "WSO2", 100L });
    checkStockStream.send(new Object[] { "IBM", 100L });
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 57 with Event

use of io.siddhi.core.event.Event in project siddhi by wso2.

the class UpdateTestStoreTestCase method updateFromTableTest8.

@Test
public void updateFromTableTest8() throws InterruptedException, SQLException {
    log.info("updateFromTableTest8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume 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 " + "update StockTable " + "   on StockTable.volume == volume ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
    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 });
    updateStockStream.send(new Object[] { "IBM", 57.6f, 100L });
    Thread.sleep(1000);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(3, events.length);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 58 with Event

use of io.siddhi.core.event.Event in project siddhi by wso2.

the class TestStoreForCachePreLoading 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());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StateEvent(io.siddhi.core.event.state.StateEvent) LinkedList(java.util.LinkedList)

Example 59 with Event

use of io.siddhi.core.event.Event in project siddhi by wso2.

the class InsertIntoTableWithCacheTestCase method insertIntoTableWithCacheTest1.

@Test
public void insertIntoTableWithCacheTest1() throws InterruptedException, SQLException {
    // Configure siddhi to insert events data to table only from specific fields of the stream.
    log.info("insertIntoTableWithCacheTest1");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, volume long); ";
    String query1 = "" + "@info(name = 'query1') " + "from StockStream\n" + "select symbol, volume\n" + "insert into StockTable ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query1);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    Thread.sleep(1000);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(2, events.length);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 60 with Event

use of io.siddhi.core.event.Event in project siddhi by wso2.

the class InsertIntoTableWithCacheTestCase method insertIntoTableWithCacheTest2.

@Test
public void insertIntoTableWithCacheTest2() throws InterruptedException, SQLException {
    // Testing table creation with a compound primary key (normal insertion)
    log.info("insertIntoTableWithCacheTest2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "@PrimaryKey(\"symbol\", \"price\")" + "define table StockTable (symbol string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream   " + "insert into StockTable ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6F, 100L });
    stockStream.send(new Object[] { "IBM", 75.6F, 100L });
    stockStream.send(new Object[] { "MSFT", 57.6F, 100L });
    stockStream.send(new Object[] { "WSO2", 58.6F, 100L });
    Thread.sleep(1000);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(4, events.length);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) SiddhiManager(io.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Event (io.siddhi.core.event.Event)1298 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)1257 SiddhiManager (io.siddhi.core.SiddhiManager)1255 Test (org.testng.annotations.Test)1251 InputHandler (io.siddhi.core.stream.input.InputHandler)1216 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)818 StreamCallback (io.siddhi.core.stream.output.StreamCallback)303 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)86 SiddhiApp (io.siddhi.query.api.SiddhiApp)82 Query (io.siddhi.query.api.execution.query.Query)81 ArrayList (java.util.ArrayList)80 Logger (org.apache.logging.log4j.core.Logger)52 StreamEvent (io.siddhi.core.event.stream.StreamEvent)38 TestAppenderToValidateLogsForCachingTests (io.siddhi.core.query.table.util.TestAppenderToValidateLogsForCachingTests)34 ComplexEvent (io.siddhi.core.event.ComplexEvent)29 CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)29 UnitTestAppender (io.siddhi.core.UnitTestAppender)18 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)17 HashMap (java.util.HashMap)15 InMemoryPersistenceStore (io.siddhi.core.util.persistence.InMemoryPersistenceStore)14