use of org.wso2.broker.core.Broker in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySinkAndEventMappingWithSiddhiQLDynamicParams.
@Test
public void inMemorySinkAndEventMappingWithSiddhiQLDynamicParams() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
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='inMemory', 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 });
stockStream.send(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", 1, ibmCount.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.broker.core.Broker in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySourceSinkAndEventMappingWithSiddhiQL2.
@Test
public void inMemorySourceSinkAndEventMappingWithSiddhiQL2() throws InterruptedException {
log.info("Test inMemory Source Sink And EventMapping With SiddhiQL2");
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')" + "@source(type='inMemory', topic='Foo', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='inMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into FooBarStream; " + "" + "from FooBarStream " + "select * " + "insert into BarStream; " + "";
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
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", 1, ibmCount.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.broker.core.Broker in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySourceSinkAndEventMappingWithSiddhiQL.
@Test
public void inMemorySourceSinkAndEventMappingWithSiddhiQL() throws InterruptedException {
log.info("Test inMemory Source Sink And EventMapping With SiddhiQL");
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')" + "@source(type='inMemory', topic='Foo', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='inMemory', 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);
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", 1, ibmCount.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.broker.core.Broker in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef.
@Test
public void inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef() throws InterruptedException {
log.info("Test inMemory Source Sink And EventMapping With SiddhiQL and Ref");
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')" + "@source(ref='test1', @map(type='passThrough')) " + "define stream FooStream (symbol string, price float, volume long); " + "@sink(ref='test2', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
Map<String, String> systemConfigs = new HashMap<>();
systemConfigs.put("test1.topic", "Foo");
systemConfigs.put("test1.type", "inMemory");
systemConfigs.put("test2.type", "inMemory");
systemConfigs.put("test2.topic", "{{symbol}}");
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setConfigManager(inMemoryConfigManager);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
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", 1, ibmCount.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.broker.core.Broker in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemorySinkAndEventMappingWithSiddhiQL.
@Test
public void inMemorySinkAndEventMappingWithSiddhiQL() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL");
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='inMemory', topic='IBM', @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 });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of WSO2 events", 0, wso2Count.get());
AssertJUnit.assertEquals("Number of IBM events", 3, ibmCount.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
Aggregations