use of org.wso2.carbon.apimgt.core.api.Broker in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase method singleClientPartitioned.
@Test
public void singleClientPartitioned() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic1Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic1";
}
};
InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic2Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic2";
}
};
// 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='testInMemory', @map(type='passThrough'), " + " @distribution(strategy='partitioned', partitionKey='symbol'," + " @destination(topic = 'topic1'), " + " @destination(topic = 'topic2'))) " + "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 });
stockStream.send(new Object[] { "IBM", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of topic 1 events", 2, topic1Count.get());
AssertJUnit.assertEquals("Number of topic 2 events", 4, topic2Count.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.carbon.apimgt.core.api.Broker in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase method singleClientBroadcast.
@Test
public void singleClientBroadcast() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic1Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic1";
}
};
InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic2Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic2";
}
};
// 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='testInMemory', @map(type='passThrough'), " + " @distribution(strategy='broadcast'," + " @destination(topic = 'topic1'), " + " @destination(topic = 'topic2'))) " + "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 });
stockStream.send(new Object[] { "IBM", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of topic 1 events", 6, topic1Count.get());
AssertJUnit.assertEquals("Number of topic 2 events", 6, topic2Count.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.carbon.apimgt.core.api.Broker in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase method singleClientFailingBroadcast.
@Test
public void singleClientFailingBroadcast() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic1Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic1";
}
};
InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic2Count.incrementAndGet();
}
@Override
public String getTopic() {
return "topic2";
}
};
// 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', @map(type='passThrough'), " + " @distribution(strategy='broadcast'," + " @destination(topic = 'topic1'), " + " @destination(topic = 'topic2'))) " + "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 });
TestFailingInMemorySink.fail = true;
stockStream.send(new Object[] { "IBM", 57.6f, 100L });
TestFailingInMemorySink.fail = false;
Thread.sleep(6000);
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of topic 1 events", 5, topic1Count.get());
AssertJUnit.assertEquals("Number of topic 2 events", 5, topic2Count.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.carbon.apimgt.core.api.Broker in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase method multiClientFailingBroadcast2.
@Test
public void multiClientFailingBroadcast2() throws InterruptedException {
log.info("Test inMemorySink And EventMapping With SiddhiQL Dynamic Params");
InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic1Count.incrementAndGet();
}
@Override
public String getTopic() {
return "WSO2";
}
};
InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {
@Override
public void onMessage(Object msg) {
topic2Count.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='testFailingInMemory2', @map(type='passThrough'), " + " @distribution(strategy='broadcast'," + " @destination(topic = 'IBM', test='1'), " + " @destination(topic = 'WSO2', test='2'))) " + "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 });
TestFailingInMemorySink2.failOnce = true;
stockStream.send(new Object[] { "IBM", 57.6f, 100L });
Thread.sleep(6000);
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
Thread.sleep(100);
// assert event count
AssertJUnit.assertEquals("Number of topic 1 events", 7, topic1Count.get());
AssertJUnit.assertEquals("Number of topic 2 events", 6, topic2Count.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of org.wso2.carbon.apimgt.core.api.Broker in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addAPI.
@Override
public void addAPI(API api) throws GatewayException {
// build the message to send
APIEvent apiCreateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_CREATE);
apiCreateEvent.setLabels(api.getLabels());
apiCreateEvent.setApiSummary(toAPISummary(api));
publishToPublisherTopic(apiCreateEvent);
if (log.isDebugEnabled()) {
log.debug("API : " + api.getName() + " created event has been successfully published to broker");
}
}
Aggregations