use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySourceAndEventMappingWithSiddhiQL.
@Test
public void inMemorySourceAndEventMappingWithSiddhiQL() throws InterruptedException {
log.info("Test inMemorySource And EventMapping With SiddhiQL");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='inMemory', topic='WSO2', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "define stream BarStream (symbol string, price float, 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);
for (Event event : events) {
switch(wso2Count.incrementAndGet()) {
case 1:
org.testng.AssertJUnit.assertEquals(55.6f, event.getData(1));
break;
case 2:
org.testng.AssertJUnit.assertEquals(57.6f, event.getData(1));
break;
default:
org.testng.AssertJUnit.fail();
}
}
}
});
siddhiAppRuntime.start();
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 100L }));
InMemoryBroker.publish("IBM", new Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 100L }));
InMemoryBroker.publish("WSO2", new Event(System.currentTimeMillis(), new Object[] { "WSO2", 57.6f, 100L }));
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 2, wso2Count.get());
AssertJUnit.assertEquals("Number of IBM events", 0, ibmCount.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryWithFailingSink.
@Test
public void inMemoryWithFailingSink() throws InterruptedException {
log.info("Test failing inMemorySink");
InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
wso2Count.incrementAndGet();
}
@Override
public String getTopic() {
return "WSO2";
}
};
InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
ibmCount.incrementAndGet();
}
@Override
public String getTopic() {
return "IBM";
}
};
// subscribe to "inMemory" broker per topic
InMemoryBroker.subscribe(subscriptionWSO2);
InMemoryBroker.subscribe(subscriptionIBM);
String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='testFailingInMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
TestFailingInMemorySink.fail = true;
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
TestFailingInMemorySink.fail = false;
Thread.sleep(5500);
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 1, wso2Count.get());
AssertJUnit.assertEquals("Number of IBM events", 2, ibmCount.get());
AssertJUnit.assertEquals("Number of errors", 2, TestFailingInMemorySink.numberOfErrorOccurred);
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase9.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void inMemoryTestCase9() throws InterruptedException {
log.info("Test inMemory 9");
String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='testStringInMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase8.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void inMemoryTestCase8() throws InterruptedException {
log.info("Test inMemory 8");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testEventInMemory', topic='Foo', prop1='hi', prop2='test', fail='true', " + " @map(type='testString', @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);
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Topic in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase6.
@Test
public void inMemoryTestCase6() throws InterruptedException {
log.info("Test inMemory 6");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='test', " + " @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 }));
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();
}
Aggregations