JobTransformer { StringReader applyCountersXslt(InputStream stream) throws JobTransformerException { StringWriter stringWriter = new StringWriter(); try { this.counterTransformer.transform(new StreamSource(stream), new StreamResult(stringWriter)); } catch (TransformerException exception) { throw new JobTransformerException(exception); } return new StringReader(stringWriter.toString()); } JobTransformer();   }
@Test public void canTransformCounters() throws Exception { StringReader reader = jobTransformer.applyCountersXslt(getSampleCountersInputStream()); String transformedString = IOUtils.toString(reader); assertThat(transformedString, equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<jobCounters>" + "<id>job_1498650116199_0092</id>" + "<counterGroup>" + "<counterGroupName>org.apache.hadoop.mapreduce.FileSystemCounter</counterGroupName>" + "<counter>" + "<name>FILE_BYTES_READ</name>" + "<totalCounterValue>0</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>FILE_BYTES_WRITTEN</name>" + "<totalCounterValue>266437</totalCounterValue>" + "<mapCounterValue>266437</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>HDFS_BYTES_READ</name>" + "<totalCounterValue>266437</totalCounterValue>" + "<mapCounterValue>266437</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>HDFS_BYTES_WRITTEN</name>" + "<totalCounterValue>266437</totalCounterValue>" + "<mapCounterValue>266437</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>MB_MILLIS_MAPS</name>" + "<totalCounterValue>1</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>MB_MILLIS_REDUCES</name>" + "<totalCounterValue>1</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>VCORES_MILLIS_MAPS</name>" + "<totalCounterValue>160210</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>VCORES_MILLIS_REDUCES</name>" + "<totalCounterValue>160210</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "<counter>" + "<name>CPU_MILLISECONDS</name>" + "<totalCounterValue>0</totalCounterValue>" + "<mapCounterValue>0</mapCounterValue>" + "<reduceCounterValue>0</reduceCounterValue>" + "</counter>" + "</counterGroup>" + "</jobCounters>")); reader.close(); }