Search in sources :

Example 31 with CannotRestoreSiddhiAppStateException

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

the class SessionWindowTestCase method testSessionWindow18.

@Test(description = "Check if events are persist when using session window")
public void testSessionWindow18() throws InterruptedException {
    log.info("SessionWindow Test18: Testing persistence ");
    PersistenceStore persistenceStore = new InMemoryPersistenceStore();
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setPersistenceStore(persistenceStore);
    String purchaseEventStream = "" + "define stream purchaseEventStream (user string, item_number int, price float, quantity int); ";
    String query = "" + "@info(name = 'query0') " + "from purchaseEventStream#window.session(2 sec, user) " + "select * " + "insert all events into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(purchaseEventStream + query);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            count.addAndGet(events.length);
            for (Event event : events) {
                innerAssertionsPassed = false;
                AssertJUnit.assertTrue(("101".equals(event.getData(1).toString()) || "102".equals(event.getData(1).toString())) || "103".equals(event.getData(1).toString()));
                innerAssertionsPassed = true;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("purchaseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "user0", 101, 34.4, 5 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { "user0", 102, 24.5, 2 });
    siddhiAppRuntime.persist();
    siddhiAppRuntime.shutdown();
    inputHandler = siddhiAppRuntime.getInputHandler("purchaseEventStream");
    siddhiAppRuntime.start();
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    inputHandler.send(new Object[] { "user0", 103, 24.5, 2 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 4200);
    AssertJUnit.assertTrue(innerAssertionsPassed);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) InMemoryPersistenceStore(io.siddhi.core.util.persistence.InMemoryPersistenceStore) PersistenceStore(io.siddhi.core.util.persistence.PersistenceStore) InMemoryPersistenceStore(io.siddhi.core.util.persistence.InMemoryPersistenceStore) SiddhiAppRuntime(io.siddhi.core.SiddhiAppRuntime) Event(io.siddhi.core.event.Event) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) StreamCallback(io.siddhi.core.stream.output.StreamCallback) 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