Search in sources :

Example 26 with Or

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

the class PartitionTestCase1 method testPartitionQuery18.

@Test
public void testPartitionQuery18() throws InterruptedException {
    log.info("Partition test18");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "@app:name('PartitionTest18') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "@info(name = 'query')from cseEventStreamOne select symbol,price,volume insert into cseEventStream;" + "partition with (price>=100 as 'large' or price<100 as 'small' of cseEventStream) begin @info(name " + "= 'query1') from cseEventStream#window.length(4) select symbol,sum(price) as price insert into " + "OutStockStream ;  end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
                eventArrived = true;
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(25.0, event.getData()[1]);
                } else if (count.get() == 2) {
                    AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 4) {
                    AssertJUnit.assertEquals(100.0, event.getData()[1]);
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 25f, 100 });
    inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 50f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertTrue(count.get() <= 4);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 27 with Or

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

the class PartitionTestCase1 method testPartitionQuery20.

@Test
public void testPartitionQuery20() throws InterruptedException {
    log.info("Partition test20");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest20') " + "" + "" + "define stream cseEventStream (symbol string, price float,volume int); " + "" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "" + "@info(name = 'query')" + "from cseEventStreamOne " + "select symbol, price, volume " + "insert into cseEventStream;" + " " + "partition with (price>=100 as 'large' or price<100 as 'medium' or price<50 as 'small' of " + "cseEventStream) " + "   begin" + "   @info(name = 'query1') " + "   from cseEventStream " + "   select symbol, sum(price) as price " + "   insert into #OutStockStream1 ; " + " " + "   @info(name = 'query2') " + "   from #OutStockStream1 " + "   insert into #OutStockStream2 ;" + " " + "   @info(name = 'query3') " + "   from #OutStockStream2 " + "   insert into OutStockStream ;" + " " + "   end ; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
                eventArrived = true;
                if (count.get() == 1) {
                    AssertJUnit.assertEquals(25.0, event.getData()[1]);
                } else if (count.get() == 2) {
                    AssertJUnit.assertEquals(25.0, event.getData()[1]);
                } else if (count.get() == 3) {
                    AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]);
                } else if (count.get() == 4) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 5) {
                    AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0));
                } else if (count.get() == 6) {
                    AssertJUnit.assertEquals(50.0, event.getData()[1]);
                }
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 25f, 100 });
    inputHandler.send(new Object[] { "WSO2", 7005.6f, 100 });
    inputHandler.send(new Object[] { "IBM", 50f, 100 });
    inputHandler.send(new Object[] { "ORACLE", 25f, 100 });
    SiddhiTestHelper.waitForEvents(100, 5, count, 60000);
    AssertJUnit.assertTrue(6 >= count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 28 with Or

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

the class StringCompareTestCase method test11.

// Greater than or equal comparison
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void test11() {
    String executionPlan = generateExecutionPlan(X_GREATER_THAN_EQUAL_Y_CONDITION, X_STRING_Y_INT_DEF);
    new SiddhiManager().createSiddhiAppRuntime(executionPlan);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 29 with Or

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

the class StringCompareTestCase method test16.

// Less than or equal comparison
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void test16() {
    String executionPlan = generateExecutionPlan(X_LESS_THAN_EQUAL_Y_CONDITION, X_STRING_Y_INT_DEF);
    new SiddhiManager().createSiddhiAppRuntime(executionPlan);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 30 with Or

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

the class PersistenceTestCase method persistenceTest13.

@Test
public void persistenceTest13() throws InterruptedException {
    log.info("Persistence test 13 - partitioned sum with group-by on length windows.");
    final int inputEventCount = 10;
    PersistenceStore persistenceStore = new InMemoryPersistenceStore();
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setPersistenceStore(persistenceStore);
    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++;
                    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(100);
        siddhiAppRuntime.persist();
    }
    inputHandler.send(new Object[] { "IBM", 205f, 100 });
    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("OutStockStream", streamCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne");
    siddhiAppRuntime.start();
    Thread.sleep(1000);
    // loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "IBM", 105f, 100 });
    Thread.sleep(1000);
    AssertJUnit.assertEquals(new Long(414), lastValue);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) PersistenceStore(org.wso2.siddhi.core.util.persistence.PersistenceStore) InMemoryPersistenceStore(org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore) InMemoryPersistenceStore(org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) CannotRestoreSiddhiAppStateException(org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) 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