本文整理汇总了Java中backtype.storm.testing.CompleteTopologyParam类的典型用法代码示例。如果您正苦于以下问题:Java CompleteTopologyParam类的具体用法?Java CompleteTopologyParam怎么用?Java CompleteTopologyParam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompleteTopologyParam类属于backtype.storm.testing包,在下文中一共展示了CompleteTopologyParam类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasicTopology
import backtype.storm.testing.CompleteTopologyParam; //导入依赖的package包/类
@Test
public void testBasicTopology() {
PythonRepository.getInstance();
MkClusterParam mkClusterParam = new MkClusterParam();
Config daemonConf = new Config();
daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, false);
mkClusterParam.setDaemonConf(daemonConf);
try {
Testing.withSimulatedTimeLocalCluster(mkClusterParam,
new TestJob() {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void run(ILocalCluster cluster) throws Exception {
// TODO Auto-generated method stub
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("karma-json-spout", new BasicJSONTestSpout());
Properties basicKarmaBoltProperties = new Properties();
basicKarmaBoltProperties.setProperty("name", "Stormy");
basicKarmaBoltProperties.setProperty("karma.input.type", "JSON");
basicKarmaBoltProperties.setProperty("base.uri", "http://ex.com");
String source = null;
try {
source = new File(this.getClass().getClassLoader().getResource("people-model.ttl").toURI()).getAbsolutePath().toString();
basicKarmaBoltProperties.setProperty("model.file", source);
} catch (URISyntaxException e) {
LOG.error("Unable to load model", e);
}
builder.setBolt("karma-generate-json", new KarmaBolt(basicKarmaBoltProperties, null)).shuffleGrouping("karma-json-spout");
Set<String> sources = new HashSet<String>();
sources.add(source);
KarmaReducerBolt reducerBolt = new KarmaReducerBolt(sources);
builder.setBolt("karma-reducer-json", reducerBolt).fieldsGrouping("karma-generate-json", new Fields("id"));
String inputs = IOUtils.toString(getTestResource("input/people.json"));
JSONArray array = new JSONArray(inputs);
List<Values> values = new LinkedList<Values>();
for(int i = 0; i < array.length(); i++)
{
JSONObject obj = array.getJSONObject(i);
values.add(new Values("a.txt",obj.toString()));
}
MockedSources mockedSources = new MockedSources();
mockedSources.addMockData("karma-json-spout", values.toArray(new Values[values.size()]));
Config config = new Config();
config.setDebug(true);
StormTopology topology = builder.createTopology();
CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
completeTopologyParam.setMockedSources(mockedSources);
completeTopologyParam.setStormConf(config);
Map results = Testing.completeTopology(cluster, topology, completeTopologyParam);
ArrayList<String> karmaJsonSpoutResults = ( ArrayList<String>)results.get("karma-json-spout");
Assert.assertEquals(7, karmaJsonSpoutResults.size() );
ArrayList<String> karmaJsonReducerResults = ( ArrayList<String>)results.get("karma-reducer-json");
Assert.assertEquals(7, karmaJsonReducerResults.size() );
ArrayList<String> karmaBoltResults = ( ArrayList<String>)results.get("karma-generate-json");
Assert.assertEquals(7, karmaBoltResults.size() );
}
});
} catch (Exception ex) {
if ((ex instanceof IOException) == false) {
throw ex;
}
}
}