本文整理汇总了Java中org.wso2.siddhi.core.SiddhiManager.setExtension方法的典型用法代码示例。如果您正苦于以下问题:Java SiddhiManager.setExtension方法的具体用法?Java SiddhiManager.setExtension怎么用?Java SiddhiManager.setExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.siddhi.core.SiddhiManager
的用法示例。
在下文中一共展示了SiddhiManager.setExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHTTPTextMappingXML
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
@Test
public void testHTTPTextMappingXML() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("xml-output-mapper", XMLSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (message String,method String,headers String);"
+ "@sink(type='http',publisher.url='http://localhost:8005/abc',method='{{method}}',"
+ "headers='{{headers}}',"
+ "@map(type='xml', @payload('{{message}}'))) "
+ "Define stream BarStream (message String,method String,headers String);";
String query = ("@info(name = 'query') " +
"from FooStream select message,method,headers insert into BarStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition +
query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpServerListenerHandler lst = new HttpServerListenerHandler(8005);
lst.run();
String payload = "<events>"
+ "<event>"
+ "<symbol>WSO2</symbol>"
+ "<price>55.645</price>"
+ "<volume>100</volume>"
+ "</event>"
+ "</events>";
fooStream.send(new Object[]{payload, "POST", "'Name:John','Age:23'"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
String expected = "<events>"
+ "<event>"
+ "<symbol>WSO2</symbol>"
+ "<price>55.645</price>"
+ "<volume>100</volume>"
+ "</event>"
+ "</events>\n";
Assert.assertEquals(eventData, expected);
siddhiAppRuntime.shutdown();
lst.shutdown();
}
示例2: testHTTPTestDeleteMethod
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events from DELETE method.
* @throws Exception Interrupted exception
*/
@Test (dependsOnMethods = "testHTTPTestPutMethod")
public void testHTTPTestDeleteMethod() throws Exception {
log.info("Creating test for publishing events from DELETE method.");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("xml-output-mapper", XMLSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (message String,method String,headers String);"
+ "@sink(type='http',publisher.url='http://localhost:8005/abc',method='{{method}}',"
+ "headers='{{headers}}',"
+ "@map(type='xml', "
+ "@payload('{{message}}'))) "
+ "Define stream BarStream (message String,method String,headers String);";
String query = ("@info(name = 'query') " +
"from FooStream "
+ "select message,method,headers "
+ "insert into BarStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition +
query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpServerListenerHandler lst = new HttpServerListenerHandler(8005);
lst.run();
fooStream.send(new Object[]{payload, "DELETE", "'Name:John','Age:23'"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
Assert.assertEquals("", eventData);
siddhiAppRuntime.shutdown();
lst.shutdown();
}
示例3: testHTTPTextMappingText2
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with TEXT mapping.
*
* @throws Exception Interrupted exception
*/
@Test (dependsOnMethods = "testHTTPTextMappingText")
public void testHTTPTextMappingText2() throws Exception {
log.info("Creating test for publishing events with TEXT mapping.");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("text-output-mapper", TextSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (name String, age int,country" +
" String,method String,headers String);"
+ "@sink(type='http',publisher.url='http://localhost:8005/abc',method='{{method}}',"
+ "headers='{{headers}}',"
+ "@map(type='text')) "
+ "Define stream BarStream (name String, age int,country String,method String,headers String);";
String query = ("@info(name = 'query1') " +
"from FooStream select * insert into BarStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition +
query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpServerListenerHandler lst = new HttpServerListenerHandler(8005);
lst.run();
fooStream.send(new Object[]{"WSO2", 55.6, "USA", "POST", "'Name:John','Age:23'"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
Assert.assertEquals(eventData, "name:\"WSO2\",\n" +
"age:55.6,\n" +
"country:\"USA\",\n" +
"method:\"POST\",\n" +
"headers:\"'Name:John','Age:23'\"\n");
lst.shutdown();
siddhiAppRuntime.shutdown();
}
示例4: testHTTPSPublisherCustomClientTrustStorePath
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Test case for HTTPS output publisher.
*/
@Test (dependsOnMethods = "testHTTPSPublisher")
public void testHTTPSPublisherCustomClientTrustStorePath() throws Exception {
setCarbonHome();
logger.info("Test case for HTTPS output publisher with custom trustore.");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("xml-output-mapper", XMLSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (message String,method String,headers String);"
+ "@sink(type='http',publisher.url='https://localhost:8009/abc',method='{{method}}',"
+ "headers='{{headers}}',client.truststore.path='${carbon.home}/resources/security/client-"
+ "truststore.jks', client.truststore.password='wso2carbon',"
+ "@map(type='xml', "
+ "@payload('{{message}}'))) "
+ "Define stream BarStream (message String,method String,headers String);";
String query = (
"@info(name = 'query') "
+ "from FooStream "
+ "select message,method,headers "
+ "insert into BarStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpsServerListenerHandler lst = new HttpsServerListenerHandler(8009);
lst.run();
fooStream.send(new Object[]{payload, "POST", "'Name:John','Age:23'"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
Assert.assertEquals(eventData, expected);
siddhiAppRuntime.shutdown();
lst.shutdown();
}
示例5: testBasicAuthNotProvided
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with basic auth is not provided.
* @throws Exception Interrupted exception
*/
@Test
public void testBasicAuthNotProvided() throws Exception {
logger.info("Creating test for publishing events with basic auth is not provided.");
URI baseURI = URI.create(String.format("http://%s:%d", "localhost", 8005));
List<String> receivedEventNameList = new ArrayList<>(2);
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinition = "@source(type='http', @map(type='xml'), receiver.url='http://localhost:8005"
+ "/endpoints/RecPro' )"
+ "define stream inputStream (name string, age int, country string);";
String query = (
"@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpPublishEvent(event1, baseURI, "/endpoints/RecPro",
"POST");
HttpTestUtil.httpPublishEvent(event2, baseURI, "/endpoints/RecPro",
"POST");
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例6: testTextMapping
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with Text mapping.
* @throws Exception Interrupted exception
*/
@Test
public void testTextMapping() throws Exception {
logger.info("Creating test for publishing events with Text mapping.");
URI baseURI = URI.create(String.format("http://%s:%d", "localhost", 8005));
List<String> receivedEventNameList = new ArrayList<>(2);
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
siddhiManager.setExtension("text", TextSourceMapper.class);
String inStreamDefinition = "" + "@source(type='http', @map(type='text',fail.on.missing.attribute='false'), "
+ "receiver.url='http://localhost:8005/endpoints/RecPro', " + "basic.auth.enabled='false'" + ")"
+ "define stream inputStream (name string, age int, country string);";
String query = (
"@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = "name:\"John\",\n" +
"age:100,\n" +
"country:\"USA\"";
String event2 = "name:\"Mike\",\n" +
"age:100,\n" +
"country:\"USA\"";
HttpTestUtil.httpPublishEvent(event1, baseURI, "/endpoints/RecPro",
"POST");
HttpTestUtil.httpPublishEvent(event2, baseURI, "/endpoints/RecPro",
"POST");
SiddhiTestHelper.waitForEvents(waitTime, 1, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例7: testHTTPDifferentFormat
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with multiple formats synchronously.
*
* @throws Exception Interrupted exception
*/
@Test(expectedExceptions = HttpSourceAdaptorRuntimeException.class)
public void testHTTPDifferentFormat() throws Exception {
logger.info("Creating test for publishing events with https protocol.");
HttpTestUtil.setCarbonHome();
Map<String, String> masterConfigs = new HashMap<>();
masterConfigs.put("source.http.keyStoreLocation", "${carbon.home}/resources/security/wso2carbon.jks");
masterConfigs.put("source.http.keyStorePassword", "wso2carbon");
masterConfigs.put("source.http.certPassword", "wso2carbon");
List<String> receivedEventNameList = new ArrayList<>(2);
SiddhiManager siddhiManager = new SiddhiManager();
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(masterConfigs, null);
inMemoryConfigManager.generateConfigReader("source", "http");
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinitionA = "@source(type='http', @map(type='xml'), receiver.url='https://localhost:8005"
+ "/endpoints/RecPro2')"
+ "define stream inputStream (name string, age int, country string);";
String queryA = ("@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinitionA + queryA);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCountA.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
masterConfigs.put("source.http.keyStorePassword", "wso2carbon2");
masterConfigs.put("source.http.certPassword", "wso2carbon2");
String inStreamDefinitionB = "@source(type='http', @map(type='xml'), receiver.url='https://localhost:8005"
+ "/endpoints/RecPro')"
+ "define stream inputStream2 (name string, age int, country string);";
String queryB = ("@info(name = 'query2') "
+ "from inputStream2 "
+ "select * "
+ "insert into outputStream2;"
);
SiddhiAppRuntime siddhiAppRuntime2 = siddhiManager
.createSiddhiAppRuntime(inStreamDefinitionB + queryB);
siddhiAppRuntime2.start();
// publishing events
List<String> expected = new ArrayList<>(2);
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpsPublishEvent(event1);
HttpTestUtil.httpsPublishEvent(event2);
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCountA, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例8: testHTTPSInputTransportInvalidKeyStore
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with https protocol with invalid keystore.
* @throws Exception Interrupted exception
*/
@Test
public void testHTTPSInputTransportInvalidKeyStore() throws Exception {
final TestAppender appender = new TestAppender();
final Logger logger = Logger.getRootLogger();
logger.addAppender(appender);
logger.info("Creating test for publishing events with https protocol with invalid keystore.");
HttpTestUtil.setCarbonHome();
Map<String, String> masterConfigs = new HashMap<>();
masterConfigs.put("source.http.keyStoreLocation", "${carbon.home}/resources/security/store.jks");
masterConfigs.put("source.http.keyStorePassword", "wso2carbon");
masterConfigs.put("source.http.certPassword", "wso2carbon");
List<String> receivedEventNameList = new ArrayList<>(2);
SiddhiManager siddhiManager = new SiddhiManager();
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(masterConfigs , null);
inMemoryConfigManager.generateConfigReader("source", "http");
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinition = "@source(type='http', @map(type='xml'), receiver.url='https://localhost:8005/"
+ "endpoints/RecPro')"
+ "define stream inputStream (name string, age int, country string);";
String query = (
"@info(name = 'query') " +
"from inputStream " +
"select * " +
"insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpsPublishEvent(event1);
HttpTestUtil.httpsPublishEvent(event2);
final List<LoggingEvent> log = appender.getLog();
List<Object> logMessages = new ArrayList<>();
for (LoggingEvent logEvent : log) {
logMessages.add(logEvent.getLevel());
}
Assert.assertEquals(logMessages.contains(Level.ERROR), true);
Assert.assertEquals(Collections.frequency(logMessages, Level.ERROR), 2);
SiddhiTestHelper.waitForEvents(waitTime, 0, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例9: testTextMappingSingle
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with Text mapping.
*
* @throws Exception Interrupted exception
*/
@Test
public void testTextMappingSingle() throws Exception {
AtomicInteger eventCount = new AtomicInteger(0);
int waitTime = 50;
int timeout = 30000;
URI baseURI = URI.create(String.format("http://%s:%d", "localhost", 8005));
List<String> receivedEventNameList = new ArrayList<>(2);
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
siddhiManager.setExtension("text", TextSourceMapper.class);
String inStreamDefinition = "" + "@source(type='http', @map(type='text'), "
+ "receiver.url='http://localhost:8005/endpoints/RecPro', " + "basic.auth.enabled='false'" + ")"
+ "define stream inputStream (name string, age int, country string);";
String query = (
"@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = "name:\'John\',\n" +
"age:100,\n" +
"country:\'USA\'";
String event2 = "name:\'Mike\',\n" +
"age:100,\n" +
"country:\'USA\'";
HttpTestUtil.httpPublishEvent(event1, baseURI, "/endpoints/RecPro",
"POST");
HttpTestUtil.httpPublishEvent(event2, baseURI, "/endpoints/RecPro",
"POST");
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例10: testHTTPSInputTransport
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with https protocol.
* @throws Exception Interrupted exception
*/
@Test
public void testHTTPSInputTransport() throws Exception {
logger.info("Creating test for publishing events with https protocol.");
HttpTestUtil.setCarbonHome();
Map<String, String> masterConfigs = new HashMap<>();
masterConfigs.put("source.http.keyStoreLocation", "${carbon.home}/resources/security/wso2carbon.jks");
masterConfigs.put("source.http.keyStorePassword", "wso2carbon");
masterConfigs.put("source.http.certPassword", "wso2carbon");
List<String> receivedEventNameList = new ArrayList<>(2);
SiddhiManager siddhiManager = new SiddhiManager();
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(masterConfigs , null);
inMemoryConfigManager.generateConfigReader("source", "http");
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinition = "@source(type='http', @map(type='xml'), receiver.url='https://localhost:8005"
+ "/endpoints/RecPro')"
+ "define stream inputStream (name string, age int, country string);";
String query = ("@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpsPublishEvent(event1);
HttpTestUtil.httpsPublishEvent(event2);
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例11: testHTTPTextMappingJson
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with JSON mapping.
* @throws Exception Interrupted exception
*/
@Test (dependsOnMethods = "testHTTPTextMappingXML")
public void testHTTPTextMappingJson() throws Exception {
log.info("Creating test for publishing events with JSON mapping.");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("xml-output-mapper", JsonSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (message String,method String,headers String);"
+ "@sink(type='http',publisher.url='http://localhost:8005/abc',method='{{method}}',"
+ "headers='{{headers}}',"
+ "@map(type='json', @payload('{{message}}'))) "
+ "Define stream BarStream (message String,method String,headers String);";
String query = ("@info(name = 'query') " +
"from FooStream select message,method,headers insert into BarStream;");
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition +
query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpServerListenerHandler lst = new HttpServerListenerHandler(8005);
lst.run();
fooStream.send(new Object[]{
"{\"event\""
+ ":{\"symbol\":\"WSO2\","
+ "\"price\":55.6,"
+ "\"volume\":100"
+ "}}"
, "POST", "Name:John,Age:23"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
Assert.assertEquals(eventData,
"{\"event\""
+ ":{\"symbol\":\"WSO2\","
+ "\"price\":55.6,"
+ "\"volume\":100"
+ "}}\n");
lst.shutdown();
siddhiAppRuntime.shutdown();
}
示例12: testJsonMapping
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with Json mapping.
* @throws Exception Interrupted exception
*/
@Test
public void testJsonMapping() throws Exception {
logger.info("Creating test for publishing events with Json mapping.");
URI baseURI = URI.create(String.format("http://%s:%d", "localhost", 8005));
List<String> receivedEventNameList = new ArrayList<>(2);
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
siddhiManager.setExtension("xml-input-mapper", JsonSourceMapper.class);
String inStreamDefinition = "" + "@source(type='http', @map(type='json'), "
+ "receiver.url='http://localhost:8005/endpoints/RecPro', " + "basic.auth.enabled='false'" + ")"
+ "define stream inputStream (name string, age int, country string);";
String query = ("@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = " {\n" +
" \"event\":{\n" +
" \"name\":\"John\",\n" +
" \"age\":55,\n" +
" \"country\":\"US\"\n" +
" }\n" +
" }";
String event2 = " {\n" +
" \"event\":{\n" +
" \"name\":\"Mike\",\n" +
" \"age\":55,\n" +
" \"country\":\"US\"\n" +
" }\n" +
" }";
HttpTestUtil.httpPublishEvent(event1, baseURI, "/endpoints/RecPro",
"POST");
HttpTestUtil.httpPublishEvent(event2, baseURI, "/endpoints/RecPro",
"POST");
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例13: testHTTPTextAuthFalse
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events wth basic authentication false.
*
* @throws Exception Interrupted exception
*/
@Test
public void testHTTPTextAuthFalse() throws Exception {
log.info(" Creating test for publishing events wth basic authentication false.");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setExtension("xml-output-mapper", XMLSinkMapper.class);
String inStreamDefinition = "Define stream FooStream (message String,method String,headers String);" +
"@sink(type='http',publisher.url='http://localhost:8005/abc',method='{{method}}',headers='{{headers}}',"
+ "@map(type='xml', @payload('{{message}}'))) "
+ "Define stream BarStream (message String,method String,headers String);";
String query = (
"@info(name = 'query') "
+ "from FooStream "
+ "select message,method,headers "
+ "insert into BarStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition
+ query);
InputHandler fooStream = siddhiAppRuntime.getInputHandler("FooStream");
siddhiAppRuntime.start();
HttpServerListenerHandler lst = new HttpServerListenerHandler(8005);
lst.run();
String payload = "<events>"
+ "<event>"
+ "<symbol>WSO2</symbol>"
+ "<price>55.645</price>"
+ "<volume>100</volume>"
+ "</event>"
+ "</events>";
fooStream.send(new Object[]{payload, "POST", "'Name:John','Age:23','Country:USA'"});
while (!lst.getServerListener().isMessageArrive()) {
Thread.sleep(10);
}
String eventData = lst.getServerListener().getData();
String expected = "<events>"
+ "<event>"
+ "<symbol>WSO2</symbol>"
+ "<price>55.645</price>"
+ "<volume>100</volume>"
+ "</event>"
+ "</events>\n";
Assert.assertEquals(eventData, expected);
siddhiAppRuntime.shutdown();
lst.shutdown();
}
示例14: testHTTPInputTransportWithoutURL
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events without URL.
* @throws Exception Interrupted exception
*/
@Test
public void testHTTPInputTransportWithoutURL() throws Exception {
logger.info(" Creating test for publishing events without URL.");
URI baseURI = URI.create(String.format("http://%s:%d", "0.0.0.0", 8280));
List<String> receivedEventNameList = new ArrayList<>(2);
PersistenceStore persistenceStore = new InMemoryPersistenceStore();
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setPersistenceStore(persistenceStore);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinition = "@App:name('TestSiddhiApp')" +
"@source(type='http', @map(type='xml') )" +
"define stream inputStream (name string, age int, country string);";
String query = ("@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
expected.add("John");
expected.add("Mike");
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpPublishEventDefault(event1, baseURI);
HttpTestUtil.httpPublishEventDefault(event2, baseURI);
SiddhiTestHelper.waitForEvents(waitTime, 2, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}
示例15: testHTTPSInputTransportInvalidKeyStorePass
import org.wso2.siddhi.core.SiddhiManager; //导入方法依赖的package包/类
/**
* Creating test for publishing events with https protocol with invalid keystore pass.
* @throws Exception Interrupted exception
*/
@Test
public void testHTTPSInputTransportInvalidKeyStorePass() throws Exception {
final TestAppender appender = new TestAppender();
final Logger logger = Logger.getRootLogger();
logger.addAppender(appender);
logger.info("Creating test for publishing events with https protocol with invalid keystore pass.");
HttpTestUtil.setCarbonHome();
Map<String, String> masterConfigs = new HashMap<>();
masterConfigs.put("source.http.keyStoreLocation", "${carbon.home}/resources/security/wso2carbon.jks");
masterConfigs.put("source.http.keyStorePassword", "wso2carbon123");
masterConfigs.put("source.http.certPassword", "wso2carbon");
List<String> receivedEventNameList = new ArrayList<>(2);
SiddhiManager siddhiManager = new SiddhiManager();
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(masterConfigs , null);
inMemoryConfigManager.generateConfigReader("source", "http");
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("xml-input-mapper", XmlSourceMapper.class);
String inStreamDefinition = "@source(type='http', @map(type='xml'), receiver.url='https://localhost:8005/" +
"endpoints/RecPro')"
+ "define stream inputStream (name string, age int, country string);";
String query = (
"@info(name = 'query') "
+ "from inputStream "
+ "select * "
+ "insert into outputStream;"
);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager
.createSiddhiAppRuntime(inStreamDefinition + query);
siddhiAppRuntime.addCallback("query", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
for (Event event : inEvents) {
eventCount.incrementAndGet();
receivedEventNameList.add(event.getData(0).toString());
}
}
});
siddhiAppRuntime.start();
// publishing events
List<String> expected = new ArrayList<>(2);
String event1 = "<events>"
+ "<event>"
+ "<name>John</name>"
+ "<age>100</age>"
+ "<country>AUS</country>"
+ "</event>"
+ "</events>";
String event2 = "<events>"
+ "<event>"
+ "<name>Mike</name>"
+ "<age>20</age>"
+ "<country>USA</country>"
+ "</event>"
+ "</events>";
HttpTestUtil.httpsPublishEvent(event1);
HttpTestUtil.httpsPublishEvent(event2);
final List<LoggingEvent> log = appender.getLog();
List<Object> logMessages = new ArrayList<>();
for (LoggingEvent logEvent : log) {
logMessages.add(logEvent.getLevel());
}
Assert.assertEquals(logMessages.contains(Level.ERROR), true);
Assert.assertEquals(Collections.frequency(logMessages, Level.ERROR), 2);
SiddhiTestHelper.waitForEvents(waitTime, 0, eventCount, timeout);
Assert.assertEquals(receivedEventNameList.toString(), expected.toString());
siddhiAppRuntime.shutdown();
}