當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。