Search in sources :

Example 76 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class LogicalAbsentSequenceTestCase method testQueryAbsent45.

@Test(dependsOnMethods = { "testQueryAbsent44" })
public void testQueryAbsent45() throws InterruptedException {
    log.info("Test the query e1 or not e2 for 1 sec, e3 with 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] or not Stream2[price>20] for 1 sec, e3=Stream3[price>30] " + "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");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();
    Thread.sleep(100);
    stream3.send(new Object[] { "GOOGLE", 35.0f, 100 });
    Thread.sleep(100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 77 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class AbsentPatternTestCase method testQueryAbsent34.

@Test(dependsOnMethods = { "testQueryAbsent33" })
public void testQueryAbsent34() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec -> e3 or e4 with e2");
    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); " + "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] or " + "e3=Stream4[price>40]" + "select e1.symbol as symbol1, 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 stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "IBM", 18.7f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "ORACLE", 25.0f, 100 });
    Thread.sleep(100);
    stream3.send(new Object[] { "WSO2", 35.0f, 100 });
    Thread.sleep(100);
    stream4.send(new Object[] { "GOOGLE", 56.86f, 100 });
    Thread.sleep(100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 78 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class AbsentPatternTestCase method testQueryAbsent32.

@Test(dependsOnMethods = { "testQueryAbsent31" })
public void testQueryAbsent32() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec -> e3 or e4 without e2 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); " + "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] or " + "e3=Stream4[price>40]" + "select e1.symbol as symbol1, 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 stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "IBM", 18.7f, 100 });
    Thread.sleep(100);
    stream3.send(new Object[] { "WSO2", 35.0f, 100 });
    Thread.sleep(100);
    stream4.send(new Object[] { "GOOGLE", 56.86f, 100 });
    Thread.sleep(100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 79 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class AbsentPatternTestCase method testQueryAbsent30.

@Test(dependsOnMethods = { "testQueryAbsent29" })
public void testQueryAbsent30() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec -> e3 or e4 without e2");
    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); " + "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] or " + "e3=Stream4[price>40]" + "select e1.symbol as symbol1, 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", "WSO2", null });
    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "IBM", 18.7f, 100 });
    Thread.sleep(1100);
    stream3.send(new Object[] { "WSO2", 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 not arrived", callback.isEventArrived());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 80 with Or

use of org.wso2.siddhi.query.api.expression.condition.Or in project siddhi by wso2.

the class EveryAbsentPatternTestCase method testQueryAbsent40.

@Test(dependsOnMethods = { "testQueryAbsent39" })
public void testQueryAbsent40() throws InterruptedException {
    log.info("Test the query e1 -> every not e2 for 1 sec -> e3 or e4 with e2");
    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); " + "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10] -> every not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] or " + "e3=Stream4[price>40]" + "select e1.symbol as symbol1, 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 stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4");
    siddhiAppRuntime.start();
    stream1.send(new Object[] { "IBM", 18.7f, 100 });
    Thread.sleep(100);
    stream2.send(new Object[] { "ORACLE", 25.0f, 100 });
    Thread.sleep(100);
    stream3.send(new Object[] { "WSO2", 35.0f, 100 });
    Thread.sleep(100);
    stream4.send(new Object[] { "GOOGLE", 56.86f, 100 });
    Thread.sleep(100);
    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();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) TestUtil(org.wso2.siddhi.core.TestUtil) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)170 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)156 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)152 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)149 TestUtil (org.wso2.siddhi.core.TestUtil)76 Event (org.wso2.siddhi.core.event.Event)66 ArrayList (java.util.ArrayList)51 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)44 HashMap (java.util.HashMap)38 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)30 IOException (java.io.IOException)24 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)24 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)21 Map (java.util.Map)18 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)17 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)16 File (java.io.File)13 List (java.util.List)13 Response (feign.Response)11 Attribute (org.wso2.charon3.core.attributes.Attribute)10