RMResourceFetcher implements ResourceFetcher<AppInfo> { public ClusterInfo getClusterInfo() throws Exception { InputStream is = null; try { selector.checkUrl(); final String urlString = getClusterInfoURL(); LOG.info("Calling yarn api to fetch cluster info: " + urlString); is = InputStreamUtils.getInputStream(urlString, null, Constants.CompressionType.GZIP); final ClusterInfoWrapper clusterInfoWrapper = OBJ_MAPPER.readValue(is, ClusterInfoWrapper.class); if (clusterInfoWrapper != null && clusterInfoWrapper.getClusterInfo() != null) { return clusterInfoWrapper.getClusterInfo(); } return null; } finally { if (is != null) { try { is.close(); } catch (Exception e) { LOG.warn("{}", e); } } } } RMResourceFetcher(String[] rmBasePaths); HAURLSelector getSelector(); String getRunningJobURL(Constants.JobType jobType, String startTime, String endTime, String limit); List<AppInfo> getResource(Constants.ResourceType resourceType, Object... parameter); ClusterInfo getClusterInfo();  }
@Test public void testGetClusterInfo() throws Exception { String[] rmBasePaths = new String[]{"http: RMResourceFetcher rmResourceFetcher = new RMResourceFetcher(rmBasePaths); mockStatic(InputStreamUtils.class); InputStream jsonstream = this.getClass().getResourceAsStream("/clusterinfo.json"); when(InputStreamUtils.getInputStream("http: when(InputStreamUtils.getInputStream("http: ClusterInfo clusterInfo = rmResourceFetcher.getClusterInfo(); Assert.assertEquals("ClusterInfo{id=1324053971963, startedOn=1324053971963, state='STARTED', haState='ACTIVE', resourceManagerVersion='0.23.1-SNAPSHOT', resourceManagerBuildVersion='0.23.1-SNAPSHOT from 1214049 by user1 source checksum 050cd664439d931c8743a6428fd6a693', resourceManagerVersionBuiltOn='Tue Dec 13 22:12:48 CST 2011', hadoopVersion='0.23.1-SNAPSHOT', hadoopBuildVersion='0.23.1-SNAPSHOT from 1214049 by user1 source checksum 11458df3bb77342dca5f917198fad328', hadoopVersionBuiltOn='Tue Dec 13 22:12:26 CST 2011'}", clusterInfo.toString()); }