use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class MaxForeverAggregatorExtensionTestCase method testMaxForeverAggregatorExtension1.
@Test
public void testMaxForeverAggregatorExtension1() throws InterruptedException {
log.info("MaxForeverAggregator TestCase 1");
SiddhiManager siddhiManager = new SiddhiManager();
String inStreamDefinition = "define stream inputStream (price1 double,price2 double, price3 double);";
String query = ("@info(name = 'query1') " + "from inputStream " + "select maxForever(price1) as maxForeverValue " + "insert into outputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
for (Event event : inEvents) {
count++;
switch(count) {
case 1:
AssertJUnit.assertEquals(36.0, event.getData(0));
break;
case 2:
AssertJUnit.assertEquals(37.88, event.getData(0));
break;
case 3:
AssertJUnit.assertEquals(39.0, event.getData(0));
break;
case 4:
AssertJUnit.assertEquals(39.0, event.getData(0));
break;
case 5:
AssertJUnit.assertEquals(39.0, event.getData(0));
break;
case 6:
AssertJUnit.assertEquals(39.0, event.getData(0));
break;
default:
org.testng.AssertJUnit.fail();
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 36d, 36.75, 35.75 });
inputHandler.send(new Object[] { 37.88d, 38.12, 37.62 });
inputHandler.send(new Object[] { 39.00d, 39.25, 38.62 });
inputHandler.send(new Object[] { 36.88d, 37.75, 36.75 });
inputHandler.send(new Object[] { 38.12d, 38.12, 37.75 });
inputHandler.send(new Object[] { 38.12d, 40, 37.75 });
Thread.sleep(300);
AssertJUnit.assertEquals(6, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class MinForeverAggregatorExtensionTestCase method testMinForeverAggregatorExtension2.
@Test
public void testMinForeverAggregatorExtension2() throws InterruptedException {
log.info("minForeverAggregator TestCase 2");
SiddhiManager siddhiManager = new SiddhiManager();
String inStreamDefinition = "define stream inputStream (price1 int,price2 int, price3 int);";
String query = ("@info(name = 'query1') from inputStream " + "select minForever(price1) as minForeverValue " + "insert into outputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
for (Event event : inEvents) {
count++;
switch(count) {
case 1:
AssertJUnit.assertEquals(36, event.getData(0));
break;
case 2:
AssertJUnit.assertEquals(36, event.getData(0));
break;
case 3:
AssertJUnit.assertEquals(9, event.getData(0));
break;
default:
org.testng.AssertJUnit.fail();
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { 36, 38, 74 });
inputHandler.send(new Object[] { 78, 38, 37 });
inputHandler.send(new Object[] { 9, 39, 38 });
Thread.sleep(300);
AssertJUnit.assertEquals(3, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class CastFunctionExecutorTestCase method testCastFunctionExtension9.
@Test
public void testCastFunctionExtension9() throws InterruptedException {
log.info("CastFunctionExecutor TestCase 9");
SiddhiManager siddhiManager = new SiddhiManager();
String inStreamDefinition = "\ndefine stream inputStream (symbol string, price object, volume long);";
String query = ("@info(name = 'query1') from inputStream select symbol,price, " + "cast(price, 'int') as priceInInt insert into outputStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
count.incrementAndGet();
if (count.get() == 1) {
AssertJUnit.assertEquals(1003, event.getData(2));
eventArrived = true;
}
if (count.get() == 2) {
AssertJUnit.assertEquals(true, event.getData(2));
eventArrived = true;
}
if (count.get() == 3) {
AssertJUnit.assertEquals(300432, event.getData(2));
eventArrived = true;
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 1003, 100L });
inputHandler.send(new Object[] { "WSO2", true, 200L });
inputHandler.send(new Object[] { "XYZ", 300432, 200L });
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertEquals(3, count.get());
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class CastFunctionExecutorTestCase method testCastFunctionExtensionException4.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testCastFunctionExtensionException4() throws InterruptedException {
log.info("CastFunctionExecutor TestCase 4");
SiddhiManager siddhiManager = new SiddhiManager();
String inStreamDefinition = "\ndefine stream inputStream (symbol string, price object, volume long);";
String query = ("@info(name = 'query1') from inputStream select symbol,price, " + "cast(price, symbol) as priceInDouble insert into outputStream;");
siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
}
use of org.wso2.siddhi.query.api.execution.query.input.stream.InputStream in project siddhi by wso2.
the class CastFunctionExecutorTestCase method testCastFunctionExtensionException3.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testCastFunctionExtensionException3() throws InterruptedException {
log.info("CastFunctionExecutor TestCase 3");
SiddhiManager siddhiManager = new SiddhiManager();
String inStreamDefinition = "\ndefine stream inputStream (symbol string, price object, volume long);";
String query = ("@info(name = 'query1') from inputStream select symbol,price, " + "cast(price, 'newType') as priceInDouble insert into outputStream;");
siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
}
Aggregations