use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.
the class IncrementalPersistenceTestCase method incrementalPersistenceTest3.
@Test
public void incrementalPersistenceTest3() throws InterruptedException {
log.info("Incremental persistence test 3 - time window query");
final int inputEventCount = 10;
final int eventWindowSizeInSeconds = 2;
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
String siddhiApp = "" + "@app:name('incrementalPersistenceTest3') " + "@app:playback " + "" + "define stream StockStream ( symbol string, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.time(" + 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(i, 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(3000, new Object[] { "WSO2", 100.4f, 150 });
// Thread.sleep(100);
inputHandler.send(3010, new Object[] { "WSO2", 200.4f, 110 });
inputHandler.send(3020, new Object[] { "IBM", 300.4f, 100 });
// Thread.sleep(100);
inputHandler.send(3030, new Object[] { "WSO2", 400.4f, 300 });
inputHandler.send(3040, new Object[] { "IBM", 500.6f, 120 });
Thread.sleep(10);
inputHandler.send(3050, 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");
try {
// loading
siddhiAppRuntime.restoreLastRevision();
} catch (CannotRestoreSiddhiAppStateException e) {
Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
}
siddhiAppRuntime.start();
Thread.sleep(500);
inputHandler.send(3500, new Object[] { "IBM", 700.6f, 230 });
Thread.sleep(10);
inputHandler.send(3540, new Object[] { "WSO2", 800.6f, 125 });
inputHandler.send(3590, new Object[] { "IBM", 900.6f, 370 });
Thread.sleep(10);
inputHandler.send(3600, new Object[] { "WSO2", 1000.6f, 140 });
// shutdown Siddhi app
Thread.sleep(5000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertTrue(count <= (inputEventCount + 10));
AssertJUnit.assertEquals(new Long(2045), lastValue);
AssertJUnit.assertEquals(true, eventArrived);
}
use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.
the class IncrementalPersistenceTestCase method incrementalPersistenceTest4.
@Test
public void incrementalPersistenceTest4() throws InterruptedException {
log.info("Incremental persistence test 4 - 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(50);
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(2045), lastValue);
AssertJUnit.assertEquals(true, eventArrived);
}
use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.
the class IncrementalPersistenceTestCase method incrementalPersistenceTest10.
@Test
public void incrementalPersistenceTest10() throws InterruptedException {
log.info("Incremental persistence test 10 - partitioned sum with group-by on length windows.");
final int inputEventCount = 10;
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
String siddhiApp = "@app:name('incrementalPersistenceTest10') " + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "partition with (price>=100 as 'large' or price<100 as 'small' of cseEventStreamOne) " + "begin @info(name " + "= 'query1') from cseEventStreamOne#window.length(4) select symbol,sum(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);
eventArrived = true;
if (events != null) {
for (Event event : events) {
count++;
inEventsList.add(event.getData());
inEventCount.incrementAndGet();
lastValue = ((Double) event.getData(1)).longValue();
}
}
}
};
siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
siddhiAppRuntime.start();
for (int i = 0; i < inputEventCount; i++) {
inputHandler.send(new Object[] { "IBM", 95f + i, 100 });
Thread.sleep(500);
siddhiAppRuntime.persist();
}
siddhiAppRuntime.persist();
inputHandler.send(new Object[] { "IBM", 205f, 100 });
Thread.sleep(2000);
siddhiAppRuntime.shutdown();
siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
// siddhiAppRuntime.addCallback("query1", queryCallback);
siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
// loading
try {
siddhiAppRuntime.restoreLastRevision();
} catch (CannotRestoreSiddhiAppStateException e) {
Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed", e);
}
siddhiAppRuntime.start();
Thread.sleep(2000);
inputHandler.send(new Object[] { "IBM", 105f, 100 });
Thread.sleep(1000);
AssertJUnit.assertEquals(new Long(414), lastValue);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.
the class IncrementalPersistenceTestCase method incrementalPersistenceTest1.
@Test
public void incrementalPersistenceTest1() throws InterruptedException {
log.info("Incremental persistence test 1 - length window query");
final int inputEventCount = 10;
final int eventWindowSize = 4;
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));
String siddhiApp = "" + "@app:name('incrementalPersistenceTest1') " + "" + "define stream StockStream ( symbol string, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.length(" + eventWindowSize + ") " + "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);
}
}
};
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(100);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(new Long(400), lastValue);
// persisting
siddhiAppRuntime.persist();
Thread.sleep(5000);
inputHandler.send(new Object[] { "IBM", 100.4f, 100 });
// Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 200.4f, 100 });
inputHandler.send(new Object[] { "IBM", 300.4f, 100 });
// Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 400.4f, 200 });
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) {
log.error(e.getMessage(), e);
Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
}
siddhiAppRuntime.start();
Thread.sleep(5000);
inputHandler.send(new Object[] { "IBM", 500.6f, 300 });
inputHandler.send(new Object[] { "WSO2", 600.6f, 400 });
// shutdown Siddhi app
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertTrue(count <= (inputEventCount + 6));
AssertJUnit.assertEquals(new Long(1000), lastValue);
AssertJUnit.assertEquals(true, eventArrived);
}
use of io.siddhi.core.exception.CannotRestoreSiddhiAppStateException in project siddhi by wso2.
the class PersistenceTestCase method persistenceTest1.
@Test
public void persistenceTest1() throws InterruptedException {
log.info("persistence test 1 - 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 int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.length(10) " + "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);
}
}
};
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", queryCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(new Long(200), lastValue);
// persisting
Thread.sleep(500);
siddhiAppRuntime.persist();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(100);
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
// restarting siddhi app
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", e);
}
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
Thread.sleep(10);
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
// shutdown siddhi app
Thread.sleep(500);
siddhiAppRuntime.shutdown();
AssertJUnit.assertTrue(count <= 6);
AssertJUnit.assertEquals(new Long(400), lastValue);
AssertJUnit.assertEquals(true, eventArrived);
}
Aggregations