use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery4.
@Test
public void testPartitionQuery4() throws InterruptedException {
log.info("Partition test4");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan4");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition streamDefinition1 = StreamDefinition.id("cseEventStream1").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
siddhiApp.defineStream(streamDefinition1);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("cseEventStream"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.insertIntoInner("StockStream");
Query query1 = Query.query();
query1.from(InputStream.innerStream("StockStream"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream");
// //////////////////////////////////partition-2/////////////////
Partition partition1 = Partition.partition().with("cseEventStream1", Expression.variable("symbol"));
Query query2 = Query.query();
query2.from(InputStream.stream("cseEventStream1"));
query2.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query2.insertIntoInner("StockStream");
Query query3 = Query.query();
query3.from(InputStream.innerStream("StockStream"));
query3.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query3.insertInto("OutStockStream");
partition.addQuery(query);
partition.addQuery(query1);
partition1.addQuery(query2);
partition1.addQuery(query3);
siddhiApp.addPartition(partition);
siddhiApp.addPartition(partition1);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler inputHandler2 = siddhiAppRuntime.getInputHandler("cseEventStream1");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler2.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler2.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler2.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 8, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(8, count.get());
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery26.
@Test
public void testPartitionQuery26() throws InterruptedException {
log.info("Partition test");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) " + "begin " + "@info(name = 'query1') " + "from streamA " + "select symbol, price insert into StockQuote ; " + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("StockQuote", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
inputHandler.send(new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }));
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery24.
@Test
public void testPartitionQuery24() throws InterruptedException {
log.info("Partition test");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) " + "begin " + "@info(name = 'query1') " + "from streamA " + "select symbol, price insert into StockQuote ; " + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0)));
count.addAndGet(events.length);
eventArrived = true;
}
};
siddhiAppRuntime.addCallback("StockQuote", streamCallback);
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA");
siddhiAppRuntime.start();
Event[] events = { new Event(System.currentTimeMillis(), new Object[] { "IBM", 700 }), new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }), new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60 }) };
inputHandler.send(events);
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery29.
@Test
public void testPartitionQuery29() throws InterruptedException {
log.info("Partition test25");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest25') " + "define stream cseEventStream (symbol string, price float, volume int, threshold double, " + "maxPrice long);" + "partition with (symbol of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>price AND threshold != volume AND price != threshold AND maxPrice " + "!= threshold" + "] select " + "symbol, sum(price) as price, " + "volume , threshold" + " insert into " + "OutStockStream ; end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 100.0, 500L });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100, 52.0, 120L });
inputHandler.send(new Object[] { "IBM", 75.6f, 100, 50.0, 800L });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100, 200.0, 400L });
SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery19.
@Test
public void testPartitionQuery19() throws InterruptedException {
log.info("Partition test19");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "@app:name('PartitionTest19') " + "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 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();
}
Aggregations