use of io.siddhi.core.util.snapshot.PersistenceReference in project siddhi by wso2.
the class PersistenceTestCase method persistenceTest3.
@Test(expectedExceptions = NoPersistenceStoreException.class, dependsOnMethods = "persistenceTest2")
public void persistenceTest3() throws Exception {
log.info("persistence test 3 - no store defined");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('Test') " + "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "" + "@info(name = 'query1') " + "from e1=Stream1[price>20] <2:5> -> e2=Stream2[price>20] " + "select e1[0].price as price1_0, e1[1].price as price1_1, e1[2].price as price1_2, " + " e1[3].price as price1_3, e2.price as price2 " + "insert into OutputStream ;";
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.assertArrayEquals(new Object[] { 25.6f, 47.6f, null, null, 45.7f }, inEvent.getData());
}
}
};
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", queryCallback);
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 25.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 47.6f, 100 });
Thread.sleep(100);
stream1.send(new Object[] { "GOOG", 13.7f, 100 });
Thread.sleep(100);
AssertJUnit.assertEquals("Number of success events", 0, count);
AssertJUnit.assertEquals("Event arrived", false, eventArrived);
// persisting
Thread.sleep(500);
PersistenceReference persistenceReference = siddhiAppRuntime.persist();
try {
persistenceReference.getFuture().get();
} catch (ExecutionException e) {
throw e.getCause() instanceof NoPersistenceStoreException ? new NoPersistenceStoreException() : e;
}
// restarting siddhi app
Thread.sleep(500);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.util.snapshot.PersistenceReference in project siddhi by wso2.
the class PersistenceHelper method persist.
public static PersistenceReference persist(byte[] serializeObj, SiddhiAppContext siddhiAppContext) {
long revisionTime = System.currentTimeMillis();
// start the snapshot persisting task asynchronously
AsyncSnapshotPersistor asyncSnapshotPersistor = new AsyncSnapshotPersistor(serializeObj, siddhiAppContext.getSiddhiContext().getPersistenceStore(), siddhiAppContext.getName(), revisionTime);
Future future = siddhiAppContext.getExecutorService().submit(asyncSnapshotPersistor);
return new PersistenceReference(future, asyncSnapshotPersistor.getRevision());
}
use of io.siddhi.core.util.snapshot.PersistenceReference in project siddhi by wso2.
the class PersistenceHelper method persist.
public static PersistenceReference persist(IncrementalSnapshot serializeObj, SiddhiAppContext siddhiAppContext) {
long revisionTime = System.currentTimeMillis();
List<Future> incrementalFutures = new ArrayList<>();
// Periodic state
Map<String, Map<String, byte[]>> periodicStateBase = serializeObj.getPeriodicState();
if (periodicStateBase != null) {
periodicStateBase.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.PERIODIC, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
// Incremental base state
Map<String, Map<String, byte[]>> incrementalStateBase = serializeObj.getIncrementalStateBase();
if (incrementalStateBase != null) {
incrementalStateBase.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.BASE, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
// Next, handle the increment persistence scenarios
// Incremental state
Map<String, Map<String, byte[]>> incrementalState = serializeObj.getIncrementalState();
if (incrementalState != null) {
incrementalState.forEach((partitionId, value) -> {
value.forEach((id, value1) -> {
String[] items = id.split(PersistenceConstants.REVISION_SEPARATOR);
AsyncIncrementalSnapshotPersistor asyncIncrementSnapshotPersistor = new AsyncIncrementalSnapshotPersistor(value1, siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore(), new IncrementalSnapshotInfo(siddhiAppContext.getName(), partitionId, items[1], items[2], revisionTime, IncrementalSnapshotInfo.SnapshotType.INCREMENT, items[0]));
Future future = siddhiAppContext.getExecutorService().submit(asyncIncrementSnapshotPersistor);
incrementalFutures.add(future);
});
});
}
return new PersistenceReference(incrementalFutures, revisionTime + PersistenceConstants.REVISION_SEPARATOR + siddhiAppContext.getName());
}
Aggregations