use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery47.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery47() {
log.info("Partition test47");
SiddhiApp siddhiApp = new SiddhiApp("plan47");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
FunctionDefinition functionDefinition = new FunctionDefinition();
siddhiApp.defineFunction(functionDefinition.id(null));
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery42.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testPartitionQuery42() throws InterruptedException {
log.info("Partition test");
SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
Query query = Query.query();
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.from(InputStream.stream("streamA"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("StockQuote");
Partition partition = Partition.partition();
partition.addQuery(query);
siddhiApp.addPartition(partition);
SiddhiManager siddhiManager = new SiddhiManager();
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 }));
Thread.sleep(1000);
AssertJUnit.assertEquals(0, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery44.
@Test
public void testPartitionQuery44() throws InterruptedException {
log.info("Partition test44");
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiApp siddhiApp = new SiddhiApp("plan44");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
Partition partition = Partition.partition().with("cseEventStream", Expression.variable("symbol"));
Query query = Query.query();
query.from(InputStream.stream("e1", "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("e2", "StockStream"));
query1.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query1.insertInto("OutStockStream");
partition.addQuery(query);
partition.addQuery(query1);
siddhiApp.addPartition(partition);
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 });
inputHandler.send(new Object[] { "WSO2", 75.6f, 100 });
inputHandler.send(new Object[] { "IBM", 75.6f, 100 });
inputHandler.send(new Object[] { "ORACLE", 75.6f, 100 });
SiddhiTestHelper.waitForEvents(100, 4, count, 60000);
siddhiAppRuntime.shutdown();
AssertJUnit.assertEquals(4, count.get());
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery39.
@Test
public void testPartitionQuery39() throws InterruptedException {
log.info("Partition test");
SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test").defineStream(StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT));
Query query = Query.query();
query.from(InputStream.stream("streamA"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("StockQuote");
Partition partition = Partition.partition().annotation(Annotation.annotation("info").element("name", "partitionA")).with("streamA", Expression.variable("symbol")).addQuery(query);
siddhiApp.addPartition(partition);
SiddhiManager siddhiManager = new SiddhiManager();
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 }));
Thread.sleep(1000);
AssertJUnit.assertEquals(3, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.SiddhiApp in project siddhi by wso2.
the class FunctionTestCase method functionTest1.
// Coalesce
@Test
public void functionTest1() throws InterruptedException {
log.info("function test 1");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price1", Attribute.Type.FLOAT).attribute("price2", Attribute.Type.FLOAT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.function("coalesce", Expression.variable("price1"), Expression.variable("price2"))));
query.insertInto("StockQuote");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
for (Event inEvent : inEvents) {
count++;
if (count == 1) {
AssertJUnit.assertEquals(55.6f, inEvent.getData()[1]);
} else if (count == 2) {
AssertJUnit.assertEquals(65.7f, inEvent.getData()[1]);
} else if (count == 3) {
AssertJUnit.assertEquals(23.6f, inEvent.getData()[1]);
} else if (count == 4) {
AssertJUnit.assertEquals(34.6f, inEvent.getData()[1]);
} else if (count == 5) {
AssertJUnit.assertNull(inEvent.getData()[1]);
}
}
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 55.6f, 70.6f });
inputHandler.send(new Object[] { "WSO2", 65.7f, 12.8f });
inputHandler.send(new Object[] { "WSO2", 23.6f, null });
inputHandler.send(new Object[] { "WSO2", null, 34.6f });
inputHandler.send(new Object[] { "WSO2", null, null });
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations