use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project siddhi by wso2.
the class AbsentLogicalPreStateProcessor method processAndReturn.
@Override
public ComplexEventChunk<StateEvent> processAndReturn(ComplexEventChunk complexEventChunk) {
ComplexEventChunk<StateEvent> returnEventChunk = new ComplexEventChunk<>(false);
if (!this.active) {
return returnEventChunk;
}
complexEventChunk.reset();
// Sure only one will be sent
StreamEvent streamEvent = (StreamEvent) complexEventChunk.next();
this.lock.lock();
try {
for (Iterator<StateEvent> iterator = pendingStateEventList.iterator(); iterator.hasNext(); ) {
StateEvent stateEvent = iterator.next();
if (withinStates.size() > 0) {
if (isExpired(stateEvent, streamEvent.getTimestamp())) {
iterator.remove();
continue;
}
}
if (logicalType == LogicalStateElement.Type.OR && stateEvent.getStreamEvent(partnerStatePreProcessor.getStateId()) != null) {
iterator.remove();
continue;
}
StreamEvent currentStreamEvent = stateEvent.getStreamEvent(stateId);
stateEvent.setEvent(stateId, streamEventCloner.copyStreamEvent(streamEvent));
process(stateEvent);
if (waitingTime != -1 || (stateType == StateInputStream.Type.SEQUENCE && logicalType == LogicalStateElement.Type.AND && thisStatePostProcessor.nextEveryStatePerProcessor != null)) {
// Reset to the original state after processing
stateEvent.setEvent(stateId, currentStreamEvent);
}
if (this.thisLastProcessor.isEventReturned()) {
this.thisLastProcessor.clearProcessedEvent();
// The event has passed the filter condition. So remove from being an absent candidate.
iterator.remove();
if (stateType == StateInputStream.Type.SEQUENCE) {
partnerStatePreProcessor.pendingStateEventList.remove(stateEvent);
}
}
if (!stateChanged) {
switch(stateType) {
case PATTERN:
stateEvent.setEvent(stateId, currentStreamEvent);
break;
case SEQUENCE:
stateEvent.setEvent(stateId, currentStreamEvent);
iterator.remove();
break;
}
}
}
} finally {
this.lock.unlock();
}
return returnEventChunk;
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project siddhi by wso2.
the class AbsentSequenceTestCase method testQueryAbsent17.
@Test
public void testQueryAbsent17() throws InterruptedException {
log.info("Test the query not e1 for 1 sec, e2, e3 with e1 that fails to satisfy the condition, e2 and " + "e3");
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, 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 stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(500);
stream1.send(new Object[] { "WSO2", 5.6f, 100 });
Thread.sleep(600);
stream2.send(new Object[] { "IBM", 28.7f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 55.7f, 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.carbon.identity.configuration.mgt.core.search.Condition in project siddhi by wso2.
the class AbsentSequenceTestCase method testQueryAbsent4.
@Test
public void testQueryAbsent4() throws InterruptedException {
log.info("Test the query e1, not e2 sending e2 for 1 sec but without satisfying the filter condition");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>20], not Stream2[price>e1.price] for 1 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 50.7f, 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 not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.Condition in project siddhi by wso2.
the class EveryAbsentSequenceTestCase method testQueryAbsent9.
@Test
public void testQueryAbsent9() throws InterruptedException {
log.info("Test the query every not e1 for 1 sec, e2, e3 with e1 that fails to satisfy the condition, e2 " + "and e3");
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 every not Stream1[price>10] for 1 sec, 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 stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
siddhiAppRuntime.start();
Thread.sleep(500);
stream1.send(new Object[] { "WSO2", 5.6f, 100 });
Thread.sleep(600);
stream2.send(new Object[] { "IBM", 28.7f, 100 });
Thread.sleep(100);
stream3.send(new Object[] { "GOOGLE", 55.7f, 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.carbon.identity.configuration.mgt.core.search.Condition in project siddhi by wso2.
the class AbsentPatternTestCase method testQueryAbsent4.
@Test(dependsOnMethods = { "testQueryAbsent3" })
public void testQueryAbsent4() throws InterruptedException {
log.info("Test the query e1 -> not e2 sending e2 for 1 sec but without satisfying the filter condition");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); ";
String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>20] -> not Stream2[price>e1.price] for 1 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[] { "WSO2" });
InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
siddhiAppRuntime.start();
stream1.send(new Object[] { "WSO2", 55.6f, 100 });
Thread.sleep(100);
stream2.send(new Object[] { "IBM", 50.7f, 100 });
Thread.sleep(1100);
callback.throwAssertionErrors();
AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived());
siddhiAppRuntime.shutdown();
}
Aggregations