Search in sources :

Example 16 with CannotRestoreSiddhiAppStateException

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

the class PartitionTestCase1 method testPartitionQuery38.

@Test
public void testPartitionQuery38() throws InterruptedException {
    log.info("Partition test");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest') " + "define stream streamA (symbol string,  price int); " + "define stream streamB (symbol string,  price int); " + "partition with (symbol of streamA,  symbol of streamB) " + "begin " + "@info(name = 'query1') " + "from streamA " + "select symbol, price " + "insert into StockQuote ;  " + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            // AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("StockQuote", streamCallback);
    SiddhiAppRuntime siddhiAppRuntime2 = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback2 = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            eventArrived = true;
        }
    };
    siddhiAppRuntime2.addCallback("StockQuote", streamCallback2);
    InputHandler inputHandlerA = siddhiAppRuntime.getInputHandler("streamA");
    InputHandler inputHandlerB = siddhiAppRuntime2.getInputHandler("streamA");
    siddhiAppRuntime.start();
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandlerA.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    byte[] snapshot = siddhiAppRuntime.snapshot();
    siddhiAppRuntime.shutdown();
    Thread.sleep(1000);
    try {
        siddhiAppRuntime2.restore(snapshot);
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    siddhiAppRuntime2.start();
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    inputHandlerB.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
    AssertJUnit.assertEquals(6, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) 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)

Example 17 with CannotRestoreSiddhiAppStateException

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

the class PersistenceTestCase method persistenceTest11.

@Test(dependsOnMethods = "persistenceTest10")
public void persistenceTest11() throws InterruptedException {
    log.info("persistence test 11 - batch window query");
    PersistenceStore persistenceStore = new InMemoryPersistenceStore();
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setPersistenceStore(persistenceStore);
    String siddhiApp = "" + "@app:name('Test') " + "" + "define stream StockStream ( symbol string, price float, volume long );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.lengthBatch(2) " + "select *" + "insert all events into OutStream ";
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            eventArrived = true;
            atomicCount.incrementAndGet();
            for (Event inEvent : inEvents) {
                AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0)));
            }
            if (removeEvents != null) {
                for (Event removeEvent : removeEvents) {
                    lastValue = (Long) removeEvent.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, 100L });
    inputHandler.send(new Object[] { "WSO2", 75.6f, 101L });
    inputHandler.send(new Object[] { "IBM", 75.6f, 102L });
    inputHandler.send(new Object[] { "IBM", 75.6f, 103L });
    SiddhiTestHelper.waitForEvents(100, 2, atomicCount, 10000);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(new Long(101), lastValue);
    // persisting
    siddhiAppRuntime.persist();
    Thread.sleep(500);
    inputHandler.send(new Object[] { "WSO2", 75.6f, 50L });
    inputHandler.send(new Object[] { "IBM", 75.6f, 50L });
    inputHandler.send(new Object[] { "IBM", 75.6f, 50L });
    // restarting execution plan
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    siddhiAppRuntime.start();
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    inputHandler.send(new Object[] { "IBM", 75.6f, 100L });
    // shutdown siddhi app
    Thread.sleep(500);
    SiddhiTestHelper.waitForEvents(100, 3, atomicCount, 10000);
    AssertJUnit.assertEquals(new Long(103), lastValue);
    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) 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 18 with CannotRestoreSiddhiAppStateException

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

the class PersistenceTestCase method persistenceTest12.

@Test(dependsOnMethods = "persistenceTest11")
public void persistenceTest12() throws InterruptedException {
    log.info("persistence test 12 - partition query");
    PersistenceStore persistenceStore = new InMemoryPersistenceStore();
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setPersistenceStore(persistenceStore);
    String siddhiApp = "@App:name('TestPlan1')\n" + "define stream TempStream(deviceID long);\n" + "\n" + "define stream DeviceTempStream (deviceID long, count long);\n" + "\n" + "from TempStream\n" + "select * insert into TempInternalStream;\n" + "\n" + "partition with ( deviceID of TempInternalStream )\n" + "begin\n" + "from TempInternalStream\n" + "select deviceID, count() as count\n" + "insert into DeviceTempStream\n" + "end;";
    StreamCallback queryCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            eventArrived = true;
            count++;
            lastValue = (Long) events[0].getData(1);
        }
    };
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("DeviceTempStream", queryCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("TempStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { 1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 1 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 2 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 2 });
    Thread.sleep(600);
    // persisting
    siddhiAppRuntime.persist();
    inputHandler.send(new Object[] { 2 });
    Thread.sleep(100);
    inputHandler.send(new Object[] { 2 });
    // restarting siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("DeviceTempStream", queryCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("TempStream");
    siddhiAppRuntime.start();
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    inputHandler.send(new Object[] { 1 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { 1 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { 2 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { 2 });
    // shutdown siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(count == 11);
    AssertJUnit.assertEquals(new Long(4), lastValue);
    AssertJUnit.assertEquals(true, eventArrived);
}
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) CannotRestoreSiddhiAppStateException(io.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(io.siddhi.core.SiddhiManager) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 19 with CannotRestoreSiddhiAppStateException

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

the class IncrementalPersistenceTestCase method incrementalPersistenceTest11.

@Test
public void incrementalPersistenceTest11() throws InterruptedException {
    log.info("Incremental persistence test 11");
    AtomicInteger count = new AtomicInteger();
    AtomicLong ibmCount = new AtomicLong();
    AtomicLong wso2Count = new AtomicLong();
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String siddhiApp = "@app:name('incrementalPersistenceTest11') " + "define stream StockQuote (symbol string, price float, volume int);" + "partition with (symbol of StockQuote) " + "begin " + "@info(name = 'query1') " + "from StockQuote#window.length(4)  " + "select symbol, count(price) as price " + "group by symbol insert into " + "OutStockStream ;  end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    StreamCallback streamCallback = new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
            count.addAndGet(events.length);
            for (Event event : events) {
                if ("IBM".equals(event.getData(0))) {
                    ibmCount.set((Long) event.getData(1));
                } else {
                    wso2Count.set((Long) event.getData(1));
                }
            }
            eventArrived = true;
        }
    };
    siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockQuote");
    siddhiAppRuntime.start();
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700f, 100 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60f, 50 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 50f, 60 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 40f, 60 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 30f, 60 }));
    siddhiAppRuntime.persist();
    Thread.sleep(2000);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("StockQuote");
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    siddhiAppRuntime.start();
    Thread.sleep(2000);
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 800f, 100 }));
    inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 20f, 60 }));
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(7, count.get());
    AssertJUnit.assertEquals(2, ibmCount.get());
    AssertJUnit.assertEquals(4, wso2Count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(io.siddhi.core.stream.input.InputHandler) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) StreamCallback(io.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 20 with CannotRestoreSiddhiAppStateException

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

the class IncrementalPersistenceTestCase method incrementalPersistenceTest4_1.

@Test
public void incrementalPersistenceTest4_1() throws InterruptedException {
    log.info("Incremental persistence test 4_1 - time batch window query");
    final int inputEventCount = 10;
    final int eventWindowSizeInSeconds = 2;
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
    String siddhiApp = "" + "@app:name('incrementalPersistenceTest4') " + "" + "define stream StockStream ( symbol string, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.timeBatch(" + eventWindowSizeInSeconds + " sec) " + "select symbol, 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++;
                AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0)));
                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[] { "IBM", 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[] { "WSO2", 100.4f, 150 });
    // Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 200.4f, 110 });
    inputHandler.send(new Object[] { "IBM", 300.4f, 100 });
    // Thread.sleep(100);
    inputHandler.send(new Object[] { "WSO2", 400.4f, 300 });
    inputHandler.send(new Object[] { "IBM", 500.6f, 120 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { "WSO2", 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();
    Thread.sleep(5000);
    inputHandler.send(new Object[] { "IBM", 700.6f, 230 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { "WSO2", 800.6f, 125 });
    inputHandler.send(new Object[] { "IBM", 900.6f, 370 });
    Thread.sleep(10);
    inputHandler.send(new Object[] { "WSO2", 1000.6f, 140 });
    // shutdown Siddhi app
    Thread.sleep(5000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertTrue(count <= (inputEventCount + 10));
    AssertJUnit.assertEquals(new Long(865), 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