当前位置: 首页>>代码示例>>Java>>正文


Java CompleteTopologyParam类代码示例

本文整理汇总了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;
		}
	}

}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:74,代码来源:TestBasicKarmaTopology.java


注:本文中的backtype.storm.testing.CompleteTopologyParam类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。