use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase14.
@Test(dependsOnMethods = { "inMemoryTestCase13" })
public void inMemoryTestCase14() throws InterruptedException {
log.info("Test inMemoryTestCase14");
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='testDepInMemory', topic='{{symbol}}', dep:prop3='foo', @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);
ServiceDeploymentInfo serviceDeploymentInfo = (ServiceDeploymentInfo) siddhiAppRuntime.getSinks().iterator().next().get(0).getServiceDeploymentInfoList().get(0);
Assert.assertNotNull(serviceDeploymentInfo);
Assert.assertTrue(serviceDeploymentInfo.isSecured());
Assert.assertTrue(serviceDeploymentInfo.getServiceProtocol() == ServiceDeploymentInfo.ServiceProtocol.TCP);
Assert.assertTrue(serviceDeploymentInfo.getPort() == 8080);
Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("prop3").equals("foo"));
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 io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.
the class InMemoryTransportTestCase method inMemoryTestCase11.
@Test(dependsOnMethods = { "inMemoryTestCase10" })
public void inMemoryTestCase11() throws InterruptedException, SubscriberUnAvailableException {
log.info("Test inMemory 11");
String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='test', " + " @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 serviceDeploymentInfos = siddhiAppRuntime.getSources().iterator().next().get(0).getServiceDeploymentInfo();
Assert.assertNull(serviceDeploymentInfos);
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.ServiceDeploymentInfo 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.ServiceDeploymentInfo in project siddhi by wso2.
the class MultiClientDistributedSinkTestCase method multiClientRoundRobinWithDep.
@Test(dependsOnMethods = { "singleClientBroadcastWithRef" })
public void multiClientRoundRobinWithDep() 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='testDepInMemory', dep:foo='bar', @map(type='passThrough'), " + " @distribution(strategy='roundRobin', " + " @destination(topic = 'topic1', dep:foo1='bar1'), " + " @destination(topic = 'topic2', dep:foo2='bar2'))) " + "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);
List<ServiceDeploymentInfo> serviceDeploymentInfos = siddhiAppRuntime.getSinks().iterator().next().get(0).getServiceDeploymentInfoList();
Assert.assertEquals(serviceDeploymentInfos.size(), 2);
for (int i = 0; i < serviceDeploymentInfos.size(); i++) {
ServiceDeploymentInfo serviceDeploymentInfo = serviceDeploymentInfos.get(i);
Assert.assertNotNull(serviceDeploymentInfo);
Assert.assertTrue(serviceDeploymentInfo.isSecured());
Assert.assertTrue(serviceDeploymentInfo.getServiceProtocol() == ServiceDeploymentInfo.ServiceProtocol.TCP);
Assert.assertTrue(serviceDeploymentInfo.getPort() == 8080);
Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("foo").equals("bar"));
if (i == 0) {
Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("foo1").equals("bar1"));
} else {
Assert.assertTrue(serviceDeploymentInfo.getDeploymentProperties().get("foo2").equals("bar2"));
}
}
InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "WSO2", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 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 WSO2 events", 3, topic1Count.get());
AssertJUnit.assertEquals("Number of IBM events", 2, topic2Count.get());
siddhiAppRuntime.shutdown();
// unsubscribe from "inMemory" broker per topic
InMemoryBroker.unsubscribe(subscriptionWSO2);
InMemoryBroker.unsubscribe(subscriptionIBM);
}
use of io.siddhi.core.stream.ServiceDeploymentInfo in project siddhi by wso2.
the class MultiClientDistributedSink method initTransport.
@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Map<String, String> deploymentProperties, List<Map<String, String>> destinationDeploymentProperties, Annotation sinkAnnotation, ConfigReader sinkConfigReader, DistributionStrategy strategy, String type, SiddhiAppContext siddhiAppContext) {
String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
for (int i = 0; i < destinationOptionHolders.size(); i++) {
OptionHolder destinationOption = destinationOptionHolders.get(i);
Sink sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
destinationOption.merge(sinkOptionHolder);
sink.initOnlyTransport(streamDefinition, destinationOption, sinkConfigReader, type, new MultiClientConnectionCallback(transports.size(), strategy), destinationDeploymentProperties.get(i), siddhiAppContext);
if (!sink.getServiceDeploymentInfoList().isEmpty()) {
((ServiceDeploymentInfo) sink.getServiceDeploymentInfoList().get(0)).addDeploymentProperties(deploymentProperties);
}
transports.add(sink);
}
}
Aggregations