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();
}
Aggregations