use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class Window method init.
/**
* Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
*
* @param tableMap map of {@link Table}s
* @param eventWindowMap map of EventWindows
* @param queryName name of the query window belongs to.
*/
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String queryName) {
if (this.windowProcessor != null) {
return;
}
// Create and initialize MetaStreamEvent
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addInputDefinition(windowDefinition);
metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
metaStreamEvent.initializeAfterWindowData();
for (Attribute attribute : windowDefinition.getAttributeList()) {
metaStreamEvent.addOutputData(attribute);
}
this.streamEventPool = new StreamEventPool(metaStreamEvent, 5);
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventPool);
OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), this.siddhiAppContext, tableMap, false, outputExpectsExpiredEvents, queryName);
internalWindowProcessor.setStreamEventCloner(streamEventCloner);
internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
EntryValveProcessor entryValveProcessor = null;
if (internalWindowProcessor instanceof SchedulingProcessor) {
entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
Scheduler scheduler = SchedulerParser.parse(this.siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, this.siddhiAppContext);
scheduler.init(this.lockWrapper, queryName);
scheduler.setStreamEventPool(streamEventPool);
((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
}
if (entryValveProcessor != null) {
entryValveProcessor.setToLast(internalWindowProcessor);
this.windowProcessor = entryValveProcessor;
} else {
this.windowProcessor = internalWindowProcessor;
}
// StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
this.internalWindowProcessor = internalWindowProcessor;
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent8.
@Test(dependsOnMethods = { "testQueryAbsent7" })
public void testQueryAbsent8() throws InterruptedException {
log.info("Test the query not e1 for 1 sec and e2 -> e3 with e2 and e3 after 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from not Stream1[price>10] for 1 sec and e2=Stream2[price>20] -> e3=Stream3[price>30] " + "select e2.symbol as symbol2, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "IBM", "GOOGLE" });
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(1100);
stream2.send(new Object[] { "IBM", 25.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent9.
@Test(dependsOnMethods = { "testQueryAbsent8_2" })
public void testQueryAbsent9() throws InterruptedException {
log.info("Test the query not e1 for 1 sec and e2 -> e3 with e2 and e3 within 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from not Stream1[price>10] for 1 sec and e2=Stream2[price>20] -> e3=Stream3[price>30] " + "select e2.symbol as symbol2, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
stream2.send(new Object[] { "IBM", 25.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
Thread.sleep(1100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent20.
@Test(dependsOnMethods = { "testQueryAbsent19" })
public void testQueryAbsent20() throws InterruptedException {
log.info("Test the query e1 -> (not e2 and e3) within 1 sec with e1 and e3 within 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> (not Stream2[price>20] and e3=Stream3[price>30]) within 1 sec " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2", "GOOGLE" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.And in project siddhi by wso2.
the class LogicalAbsentPatternTestCase method testQueryAbsent41.
@Test(dependsOnMethods = { "testQueryAbsent40" })
public void testQueryAbsent41() throws InterruptedException {
log.info("Test the query e1 -> e2 or not e3 for 1 sec with e1 and e3 within 1 sec");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> e2=Stream2[price>20] or not Stream3[price>30] for 1 sec " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2", "GOOGLE" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 15.0f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "GOOGLE", 25.0f, 100 });
Thread.sleep(100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
Aggregations