Search in sources :

Example 81 with SiddhiManager

use of io.siddhi.core.SiddhiManager in project siddhi by wso2.

the class DeleteFromTestStoreTestCase method deleteFromTestStoreTest5.

@Test
public void deleteFromTestStoreTest5() throws InterruptedException, SQLException {
    log.info("deleteFromTestStoreTest5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream DeleteStockStream (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 DeleteStockStream " + "delete StockTable " + "   on StockTable.symbol==symbol and StockTable.price > price and  StockTable.volume == volume  ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6F, 100L });
    stockStream.send(new Object[] { "IBM", 75.6F, 100L });
    stockStream.send(new Object[] { "IBM", 57.6F, 100L });
    deleteStockStream.send(new Object[] { "IBM", 57.6F, 100L });
    Thread.sleep(1000);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    try {
        AssertJUnit.assertEquals(2, events.length);
    } catch (NullPointerException ignore) {
    }
    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 82 with SiddhiManager

use of io.siddhi.core.SiddhiManager in project siddhi by wso2.

the class DeleteFromTestStoreTestCase method deleteFromTestStoreTest1.

@Test(description = "deleteFromTestStoreTest1")
public void deleteFromTestStoreTest1() throws InterruptedException, SQLException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream DeleteStockStream (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 DeleteStockStream " + "delete StockTable " + "   on StockTable.symbol == symbol ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
    InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream");
    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 });
    deleteStockStream.send(new Object[] { "WSO2", 57.6F, 100L });
    Thread.sleep(1000);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    try {
        AssertJUnit.assertEquals(0, events.length);
    } catch (NullPointerException ignore) {
    }
    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 83 with SiddhiManager

use of io.siddhi.core.SiddhiManager in project siddhi by wso2.

the class QueryAPITestCaseForTestStore method test11.

@Test
public void test11() throws InterruptedException {
    log.info("Test10 table with cache");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (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 ;";
    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[] { "WSO2", 57.6f, 100L });
    Thread.sleep(500);
    String storeQuery = "" + "from StockTable " + "on price > 56 " + "select symbol, price, sum(volume) as totalVolume " + "group by symbol, price ";
    Event[] events = siddhiAppRuntime.query(storeQuery);
    EventPrinter.print(events);
    AssertJUnit.assertEquals(2, events.length);
    AssertJUnit.assertEquals(100L, events[0].getData()[2]);
    AssertJUnit.assertEquals(100L, events[1].getData()[2]);
    events = siddhiAppRuntime.query(storeQuery);
    EventPrinter.print(events);
    AssertJUnit.assertEquals(2, events.length);
    AssertJUnit.assertEquals(100L, events[0].getData()[2]);
    AssertJUnit.assertEquals(100L, events[1].getData()[2]);
}
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 84 with SiddhiManager

use of io.siddhi.core.SiddhiManager in project siddhi by wso2.

the class QueryAPITestCaseForTestStore method test0.

@Test
public void test0() throws InterruptedException {
    log.info("Test1 table with cache");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (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 ;";
    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[] { "WSO2", 57.6f, 200L });
    Thread.sleep(500);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(3, events.length);
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 75 ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, events.length);
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > volume*3/4  ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, 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 85 with SiddhiManager

use of io.siddhi.core.SiddhiManager in project siddhi by wso2.

the class QueryAPITestCaseForTestStore method test1.

@Test
public void test1() throws InterruptedException {
    log.info("Test1 table with cache");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream StockStream (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 ;";
    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[] { "WSO3", 57.6f, 100L });
    Thread.sleep(500);
    Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(3, events.length);
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 75 ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, events.length);
    events = siddhiAppRuntime.query("" + "from StockTable " + "on price > volume*3/4  ");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, 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

SiddhiManager (io.siddhi.core.SiddhiManager)1871 Test (org.testng.annotations.Test)1855 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)1756 InputHandler (io.siddhi.core.stream.input.InputHandler)1585 Event (io.siddhi.core.event.Event)1255 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)821 StreamCallback (io.siddhi.core.stream.output.StreamCallback)305 TestUtil (io.siddhi.core.TestUtil)304 SiddhiApp (io.siddhi.query.api.SiddhiApp)89 Query (io.siddhi.query.api.execution.query.Query)85 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)84 ArrayList (java.util.ArrayList)73 Logger (org.apache.logging.log4j.core.Logger)57 TestAppenderToValidateLogsForCachingTests (io.siddhi.core.query.table.util.TestAppenderToValidateLogsForCachingTests)34 InMemoryBroker (io.siddhi.core.util.transport.InMemoryBroker)32 CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)30 HashMap (java.util.HashMap)25 UnitTestAppender (io.siddhi.core.UnitTestAppender)23 InMemoryConfigManager (io.siddhi.core.util.config.InMemoryConfigManager)21 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)15