use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase7.
@Test(dependsOnMethods = { "inMemoryTestCase6" })
public void inMemoryTestCase7() throws InterruptedException, SubscriberUnAvailableException {
log.info("Test inMemory 7");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='test', fail='true', " + " @map(type='passThrough', @attributes(symbol='trp:symbol'," + " volume='volume',price='trp:price'))) " + "define stream FooStream (symbol string, price string, volume long); " + "define stream BarStream (symbol string, price string, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
wso2Count.incrementAndGet();
for (Event event : events) {
AssertJUnit.assertArrayEquals(event.getData(), new Object[] { "hi", "test", 100L });
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "WSO2", "in", 100L }));
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of events", 0, wso2Count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase12.
@Test(dependsOnMethods = { "inMemoryTestCase11" })
public void inMemoryTestCase12() throws InterruptedException, SubscriberUnAvailableException {
log.info("Test inMemory 12");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testDepInMemory', topic='Foo', prop1='hi', prop2='test', dep:prop3='foo', " + " @map(type='testTrp', @attributes('trp:symbol'," + " 'trp:price', '2'))) " + "define stream FooStream (symbol string, price string, volume long); " + "define stream BarStream (symbol string, price string, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
ServiceDeploymentInfo serviceDeploymentInfo = siddhiAppRuntime.getSources().iterator().next().get(0).getServiceDeploymentInfo();
Assert.assertNotNull(serviceDeploymentInfo);
Assert.assertTrue(serviceDeploymentInfo.isSecured());
Assert.assertTrue(serviceDeploymentInfo.getServiceProtocol() == ServiceDeploymentInfo.ServiceProtocol.UDP);
Assert.assertTrue(serviceDeploymentInfo.getPort() == 9000);
Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("prop3").equals("foo"));
siddhiAppRuntime.addCallback("BarStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
wso2Count.incrementAndGet();
for (Event event : events) {
AssertJUnit.assertArrayEquals(event.getData(), new Object[] { "hi", "test", 100L });
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "WSO2", "in", 100L }));
InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "IBM", "in", 100L }));
InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[] { "WSO2", "in", 100L }));
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of events", 3, wso2Count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class CallbackTestCase method callbackTest4.
@Test
public void callbackTest4() throws InterruptedException {
log.info("callback test4");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from StockStream[70 > price] " + "select symbol, price " + "insert into OutputStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("StockStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
Map<String, Object>[] eventMap = toMap(events);
Assert.assertEquals(eventMap.length, events.length);
Assert.assertEquals(eventMap[0].get("_timestamp"), events[0].getTimestamp());
Assert.assertEquals(eventMap[1].get("_timestamp"), events[1].getTimestamp());
Assert.assertEquals(eventMap[1].get("volume"), events[1].getData(2));
count = count + events.length;
eventArrived = true;
}
});
siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
Map<String, Object>[] eventMap = toMap(events);
Assert.assertEquals(eventMap.length, events.length);
Assert.assertEquals(eventMap[0].get("_timestamp"), events[0].getTimestamp());
Assert.assertEquals(eventMap[0].get("price"), events[0].getData(1));
Assert.assertEquals(eventMap[0].get("symbol"), events[0].getData(0));
Assert.assertNull(eventMap[0].get("volume"));
count = count + events.length;
eventArrived2 = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Event[] { new Event(System.currentTimeMillis(), new Object[] { "IBM", 700f, 100L }), new Event(System.currentTimeMillis(), new Object[] { "WSO2", 60.5f, 200L }) });
Thread.sleep(100);
AssertJUnit.assertEquals(3, count);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertTrue(eventArrived2);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class CallbackTestCase method callbackTest1.
@Test
public void callbackTest1() throws InterruptedException {
log.info("callback test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from StockStream[70 > price] " + "select symbol, price " + "insert into outputStream;";
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);
count = count + inEvents.length;
eventArrived = true;
}
});
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
count = count + events.length;
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 100L });
inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of io.siddhi.core.stream.output.StreamCallback in project siddhi by wso2.
the class CallbackTestCase method callbackTest3.
@Test(expectedExceptions = DefinitionNotExistException.class)
public void callbackTest3() throws InterruptedException {
log.info("callback test3");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "@app:name('callbackTest1') " + "" + "define stream StockStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from StockStream[70 > price] " + "select symbol, price " + "insert into outputStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream2", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
}
});
siddhiAppRuntime.shutdown();
}
Aggregations