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();
}
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();
}
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);
}
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);
}
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();
}
Aggregations