use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test9.
@Test
public void test9() throws InterruptedException {
log.info("Test9 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on volume > 10 " + "select symbol, price, volume " + "order by price " + "limit 2 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
AssertJUnit.assertEquals(55.6F, events[0].getData()[1]);
AssertJUnit.assertEquals(57.6f, events[1].getData()[1]);
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test5.
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test5() {
log.info("Test5 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
try {
siddhiAppRuntime.start();
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test12.
@Test
public void test12() {
log.info("Test12 - Test output attributes and its types for table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String storeQuery = "" + "from StockTable " + "select * ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.start();
Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute, volumeAttribute };
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
storeQuery = "" + "from StockTable " + "select symbol, sum(volume) as totalVolume ;";
actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
siddhiAppRuntime.shutdown();
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test4.
@Test(expectedExceptions = StoreQueryCreationException.class)
public void test4() throws InterruptedException {
log.info("Test4 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTabled " + "on price > 5 " + "select symbol1, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(400L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of io.siddhi.core.SiddhiManager in project siddhi by wso2.
the class QueryAPITestCaseForTableWithCache method test1.
@Test
public void test1() throws InterruptedException {
log.info("Test1 table with cache");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO3", 57.6f, 100L });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
EventPrinter.print(events);
AssertJUnit.assertEquals(3, events.length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 75 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > volume*3/4 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
siddhiAppRuntime.shutdown();
}
Aggregations