Search in sources :

Example 21 with CannotRestoreSiddhiAppStateException

use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.

the class IncrementalPersistenceTestCase method incrementalPersistenceTest6.

@Test
public void incrementalPersistenceTest6() throws InterruptedException {
    log.info("Incremental persistence test 6 - in-memory table persistance test without primary key.");
    int inputEventCountPerCategory = 10;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String streams = "" + "@app:name('incrementalPersistenceTest6') " + "" + "define stream StockStream (symbol2 string, price float, volume long); " + "define stream CheckStockStream (symbol1 string); " + "define stream OutStream (symbol1 string, TB long); " + "define table StockTable (symbol2 string, price float, volume long); ";
    String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from StockTable join CheckStockStream " + " on symbol2 == symbol1 " + "select symbol2 as symbol1, sum(StockTable.volume) as TB " + "group by symbol2 " + "insert all events into OutStream;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                for (Event event : inEvents) {
                    inEventsList.add(event.getData());
                    inEventCount.incrementAndGet();
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }
    };
    try {
        siddhiAppRuntime.addCallback("query2", queryCallback);
        InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
        siddhiAppRuntime.start();
        for (int i = 0; i < inputEventCountPerCategory; i++) {
            stockStream.send(new Object[] { "WSO2", 55.6f + i, 180L + i });
        }
        for (int i = 0; i < inputEventCountPerCategory; i++) {
            stockStream.send(new Object[] { "IBM", 55.6f + i, 100L + i });
        }
        // persisting
        siddhiAppRuntime.persist();
        Thread.sleep(5000);
        siddhiAppRuntime.shutdown();
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
        siddhiAppRuntime.addCallback("query2", queryCallback);
        stockStream = siddhiAppRuntime.getInputHandler("StockStream");
        InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
        // loading
        try {
            siddhiAppRuntime.restoreLastRevision();
        } catch (CannotRestoreSiddhiAppStateException e) {
            Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
        }
        siddhiAppRuntime.start();
        Thread.sleep(2000);
        stockStream.send(new Object[] { "WSO2", 100.6f, 180L });
        stockStream.send(new Object[] { "IBM", 100.6f, 100L });
        stockStream.send(new Object[] { "WSO2", 8.6f, 13L });
        stockStream.send(new Object[] { "IBM", 7.6f, 14L });
        checkStockStream.send(new Object[] { "IBM" });
        checkStockStream.send(new Object[] { "WSO2" });
        List<Object[]> expected = Arrays.asList(new Object[] { "IBM", 1159L }, new Object[] { "WSO2", 2038L });
        Thread.sleep(1000);
        AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected));
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) IncrementalFileSystemPersistenceStore(io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 22 with CannotRestoreSiddhiAppStateException

use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.

the class IncrementalPersistenceTestCase method incrementalPersistenceTest9.

@Test
public void incrementalPersistenceTest9() throws InterruptedException {
    log.info("Incremental persistence test 9 - min-max counting with group-by.");
    final int inputEventCount = 10;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String streams = "" + "@app:name('incrementalPersistenceTest9') " + "define stream TempStream (roomNo long, temp long); " + "define stream MaxTempStream (roomNo long, maxTemp long); ";
    String query = "" + "@info(name = 'query1') " + "from TempStream#window.length(10) " + "select roomNo, max(temp) as maxTemp " + "group by roomNo " + "insert into MaxTempStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            if (inEvents != null) {
                for (Event event : inEvents) {
                    count++;
                    inEventsList.add(event.getData());
                    inEventCount.incrementAndGet();
                    lastValue = (Long) event.getData(1);
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
        }
    };
    try {
        siddhiAppRuntime.addCallback("query1", queryCallback);
        InputHandler stockStream = siddhiAppRuntime.getInputHandler("TempStream");
        siddhiAppRuntime.start();
        for (int i = 0; i < inputEventCount; i++) {
            stockStream.send(new Object[] { i, 55L + i });
        }
        // persisting
        siddhiAppRuntime.persist();
        Thread.sleep(5000);
        siddhiAppRuntime.shutdown();
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
        siddhiAppRuntime.addCallback("query1", queryCallback);
        stockStream = siddhiAppRuntime.getInputHandler("TempStream");
        // loading
        try {
            siddhiAppRuntime.restoreLastRevision();
        } catch (CannotRestoreSiddhiAppStateException e) {
            Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
        }
        siddhiAppRuntime.start();
        Thread.sleep(2000);
        stockStream.send(new Object[] { inputEventCount + 1, 1000L });
        // persisting
        siddhiAppRuntime.persist();
        Thread.sleep(2000);
        stockStream.send(new Object[] { inputEventCount + 2, 20L });
        siddhiAppRuntime.persist();
        Thread.sleep(2000);
        stockStream.send(new Object[] { 4, 50L });
        // AssertJUnit.assertTrue(count <= (inputEventCount + 3));
        AssertJUnit.assertEquals(new Long(59), lastValue);
        AssertJUnit.assertEquals(true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) IncrementalFileSystemPersistenceStore(io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 23 with CannotRestoreSiddhiAppStateException

use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.

the class IncrementalPersistenceTestCase method incrementalPersistenceTest8.

@Test
public void incrementalPersistenceTest8() throws InterruptedException {
    log.info("Incremental persistence test 8 - min-max counting.");
    final int inputEventCount = 10;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String streams = "" + "@app:name('incrementalPersistenceTest8') " + "define stream TempStream (roomNo long, temp long); " + "define stream MaxTempStream (roomNo long, maxTemp long); ";
    String query = "" + "@info(name = 'query1') " + "from TempStream#window.length(10) " + "select roomNo, max(temp) as maxTemp " + "insert into MaxTempStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            if (inEvents != null) {
                for (Event event : inEvents) {
                    count++;
                    inEventsList.add(event.getData());
                    inEventCount.incrementAndGet();
                    lastValue = (Long) event.getData(1);
                }
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
        }
    };
    try {
        siddhiAppRuntime.addCallback("query1", queryCallback);
        InputHandler stockStream = siddhiAppRuntime.getInputHandler("TempStream");
        siddhiAppRuntime.start();
        for (int i = 0; i < inputEventCount; i++) {
            stockStream.send(new Object[] { i, 55L + i });
        }
        // persisting
        siddhiAppRuntime.persist();
        Thread.sleep(5000);
        siddhiAppRuntime.shutdown();
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
        siddhiAppRuntime.addCallback("query1", queryCallback);
        stockStream = siddhiAppRuntime.getInputHandler("TempStream");
        // loading
        try {
            siddhiAppRuntime.restoreLastRevision();
        } catch (CannotRestoreSiddhiAppStateException e) {
            Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
        }
        siddhiAppRuntime.start();
        Thread.sleep(2000);
        stockStream.send(new Object[] { inputEventCount + 1, 1000L });
        // persisting
        siddhiAppRuntime.persist();
        Thread.sleep(2000);
        stockStream.send(new Object[] { inputEventCount + 2, 20L });
        siddhiAppRuntime.persist();
        Thread.sleep(2000);
        stockStream.send(new Object[] { inputEventCount + 3, 30L });
        AssertJUnit.assertTrue(count <= (inputEventCount + 3));
        AssertJUnit.assertEquals(new Long(1000), lastValue);
        AssertJUnit.assertEquals(true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) IncrementalFileSystemPersistenceStore(io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 24 with CannotRestoreSiddhiAppStateException

use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.

the class IncrementalPersistenceTestCase method incrementalPersistenceTest12.

@Test
public void incrementalPersistenceTest12() throws InterruptedException {
    log.info("Incremental file persistence test 12 - length window query with max attribute aggregator");
    final int eventWindowSize = 5;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String siddhiApp = "" + "@app:name('incrementalPersistenceTest12') " + "" + "define stream StockStream ( symbol string, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream#window.length(" + eventWindowSize + ") " + "select symbol, price, max(volume) as maxVol " + "insert into OutStream ";
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            for (Event inEvent : inEvents) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0)));
                lastValue = new Long((Integer) inEvent.getData(2));
            }
        }
    };
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 75.6f, 500 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 200 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 300 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 250 });
    inputHandler.send(new Object[] { "IBM", 75.6f, 150 });
    Thread.sleep(100);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(new Long(500L), lastValue);
    // persisting
    siddhiAppRuntime.persist();
    Thread.sleep(5000);
    // persisting for the second time to store the inc-snapshot
    siddhiAppRuntime.persist();
    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        log.error(e.getMessage(), e);
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    siddhiAppRuntime.start();
    Thread.sleep(5000);
    inputHandler.send(new Object[] { "IBM", 100.4f, 280 });
    AssertJUnit.assertEquals((Long) 300L, lastValue);
    inputHandler.send(new Object[] { "WSO2", 200.4f, 150 });
    AssertJUnit.assertEquals((Long) 300L, lastValue);
    inputHandler.send(new Object[] { "IBM", 300.4f, 200 });
    AssertJUnit.assertEquals((Long) 280L, lastValue);
    inputHandler.send(new Object[] { "WSO2", 400.4f, 270 });
    AssertJUnit.assertEquals((Long) 280L, lastValue);
    inputHandler.send(new Object[] { "WSO2", 400.4f, 280 });
    AssertJUnit.assertEquals((Long) 280L, lastValue);
    // shutdown Siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(true, eventArrived);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputHandler(io.siddhi.core.stream.input.InputHandler) IncrementalFileSystemPersistenceStore(io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) Event(io.siddhi.core.event.Event) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 25 with CannotRestoreSiddhiAppStateException

use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.

the class IncrementalPersistenceTestCase method incrementalPersistenceTest5.

@Test
public void incrementalPersistenceTest5() throws InterruptedException {
    log.info("Incremental persistence test 5 - external time window query");
    final int inputEventCount = 10;
    final int eventWindowSizeInSeconds = 2;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String siddhiApp = "" + "@app:name('incrementalPersistenceTest5') " + "" + "define stream StockStream ( iij_timestamp long, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.externalTime(iij_timestamp, " + eventWindowSizeInSeconds + " sec) " + "select iij_timestamp, price, sum(volume) as totalVol " + "insert into OutStream";
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            for (Event inEvent : inEvents) {
                count++;
                lastValue = (Long) inEvent.getData(2);
                log.info("last value: " + lastValue);
            }
        }
    };
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    for (int i = 0; i < inputEventCount; i++) {
        inputHandler.send(new Object[] { (long) i, 75.6f + i, 100 });
    }
    Thread.sleep(4000);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(new Long(1000), lastValue);
    // persisting
    siddhiAppRuntime.persist();
    Thread.sleep(5000);
    inputHandler.send(new Object[] { (1L + inputEventCount), 100.4f, 150 });
    // Thread.sleep(100);
    inputHandler.send(new Object[] { (2L + inputEventCount), 200.4f, 110 });
    inputHandler.send(new Object[] { (3L + inputEventCount), 300.4f, 100 });
    // Thread.sleep(100);
    inputHandler.send(new Object[] { (4L + inputEventCount), 400.4f, 300 });
    inputHandler.send(new Object[] { (5L + inputEventCount), 500.6f, 120 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { (6L + inputEventCount), 600.6f, 400 });
    Thread.sleep(100);
    siddhiAppRuntime.persist();
    Thread.sleep(5000);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { (7L + inputEventCount), 700.6f, 230 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { (8L + inputEventCount), 800.6f, 125 });
    inputHandler.send(new Object[] { (9L + inputEventCount), 900.6f, 370 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { (10L + inputEventCount), 1000.6f, 140 });
    // shutdown Siddhi app
    Thread.sleep(5000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(count <= (inputEventCount + 10));
    AssertJUnit.assertEquals(new Long(3045), lastValue);
    AssertJUnit.assertEquals(true, eventArrived);
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) IncrementalFileSystemPersistenceStore(io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore) AtomicLong(java.util.concurrent.atomic.AtomicLong) Event(io.siddhi.core.event.Event) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) QueryCallback(io.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

CannotRestoreSiddhiAppStateException (io.siddhi.core.exception.CannotRestoreSiddhiAppStateException)31 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)28 SiddhiManager (io.siddhi.core.SiddhiManager)28 InputHandler (io.siddhi.core.stream.input.InputHandler)28 Test (org.testng.annotations.Test)28 Event (io.siddhi.core.event.Event)27 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)21 PersistenceStore (io.siddhi.core.util.persistence.PersistenceStore)15 InMemoryPersistenceStore (io.siddhi.core.util.persistence.InMemoryPersistenceStore)14 IncrementalFileSystemPersistenceStore (io.siddhi.core.util.persistence.IncrementalFileSystemPersistenceStore)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 StreamCallback (io.siddhi.core.stream.output.StreamCallback)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 IncrementalSnapshotInfo (io.siddhi.core.util.persistence.util.IncrementalSnapshotInfo)2 Snapshot (io.siddhi.core.util.snapshot.state.Snapshot)2 SnapshotStateList (io.siddhi.core.util.snapshot.state.SnapshotStateList)2 State (io.siddhi.core.util.snapshot.state.State)2