diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-08-26 09:10:19 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-08-26 09:10:19 +0000 |
commit | c0227d2e2ef00b0193062df4f6d6e56ba211c51c (patch) | |
tree | bcc7d3ff1b6c19bc4e9a19c8849006e261aff553 /test | |
parent | 0f20fb70bc3c4e6f7f3c58f3a9afc1e884769cea (diff) | |
download | xmlgraphics-fop-c0227d2e2ef00b0193062df4f6d6e56ba211c51c.tar.gz xmlgraphics-fop-c0227d2e2ef00b0193062df4f6d6e56ba211c51c.zip |
Merged revisions 687576,687657,687786,688078,688087,688139,688508,688633,688652-688653,688660,688664,688666,688674,688698,688994,689000 via svnmerge from
https://svn.eu.apache.org/repos/asf/xmlgraphics/fop/trunk
........
r687576 | maxberger | 2008-08-21 07:25:40 +0100 (Thu, 21 Aug 2008) | 1 line
Included patched retroweaver which does not modify Boolean.valueOf
........
r687657 | jeremias | 2008-08-21 09:51:50 +0100 (Thu, 21 Aug 2008) | 1 line
Added an FAQ entry about the element mismatch error message.
........
r687786 | jeremias | 2008-08-21 16:49:13 +0100 (Thu, 21 Aug 2008) | 1 line
Added some performance statistics to MemoryEater.
........
r688078 | jeremias | 2008-08-22 14:02:37 +0100 (Fri, 22 Aug 2008) | 1 line
Final statistics output after the test with average speed indication.
........
r688087 | jeremias | 2008-08-22 15:16:58 +0100 (Fri, 22 Aug 2008) | 2 lines
Merge from branch https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95:
Fixed text stroking in SVG when the stroke-width is zero.
........
r688139 | maxberger | 2008-08-22 19:08:36 +0100 (Fri, 22 Aug 2008) | 1 line
minor spelling mistakes
........
r688508 | maxberger | 2008-08-24 14:12:02 +0100 (Sun, 24 Aug 2008) | 2 lines
Moved DataURIResolver from FOP to commons; use new URIResolver registry
........
r688633 | jeremias | 2008-08-25 07:42:44 +0100 (Mon, 25 Aug 2008) | 2 lines
Fixed memory leak in property cache (not cleaning stale PropertyCache$CacheEntry instances).
Special thanks to Andreas Delmelle for his help!
........
r688652 | maxberger | 2008-08-25 09:19:13 +0100 (Mon, 25 Aug 2008) | 1 line
Re-added moved class as deprecated
........
r688653 | jeremias | 2008-08-25 09:23:31 +0100 (Mon, 25 Aug 2008) | 1 line
Added a page on metadata (partly ported from the FOP Wiki).
........
r688660 | jeremias | 2008-08-25 09:41:29 +0100 (Mon, 25 Aug 2008) | 2 lines
Fixed example.
Thanks for noticing, Pascal Sancho!
........
r688664 | jeremias | 2008-08-25 09:59:27 +0100 (Mon, 25 Aug 2008) | 1 line
Minor documentation improvements, most notably a comment about keep-together="always".
........
r688666 | maxberger | 2008-08-25 10:00:27 +0100 (Mon, 25 Aug 2008) | 1 line
CommonURIResolver is no longer a singleton
........
r688674 | jeremias | 2008-08-25 10:15:22 +0100 (Mon, 25 Aug 2008) | 1 line
Hmm, I missed the redirects for the 0.95 release.
........
r688698 | jeremias | 2008-08-25 12:24:15 +0100 (Mon, 25 Aug 2008) | 2 lines
Merge from 0.95 branch:
Fixed jar-sources target.
........
r688994 | acumiskey | 2008-08-26 09:34:45 +0100 (Tue, 26 Aug 2008) | 1 line
Deprecate UnitConv now that it resides only in xmlgraphics commons.
........
r689000 | acumiskey | 2008-08-26 09:59:31 +0100 (Tue, 26 Aug 2008) | 1 line
Forgot to add deprecated public statics.
........
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@689005 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/java/org/apache/fop/UtilityCodeTestSuite.java | 2 | ||||
-rw-r--r-- | test/java/org/apache/fop/memory/MemoryEater.java | 41 | ||||
-rw-r--r-- | test/java/org/apache/fop/memory/Stats.java | 121 | ||||
-rw-r--r-- | test/java/org/apache/fop/util/DataURIResolverTestCase.java | 116 |
4 files changed, 151 insertions, 129 deletions
diff --git a/test/java/org/apache/fop/UtilityCodeTestSuite.java b/test/java/org/apache/fop/UtilityCodeTestSuite.java index 6611f532e..a073c4988 100644 --- a/test/java/org/apache/fop/UtilityCodeTestSuite.java +++ b/test/java/org/apache/fop/UtilityCodeTestSuite.java @@ -26,7 +26,6 @@ import org.apache.fop.events.BasicEventTestCase; import org.apache.fop.pdf.PDFObjectTestCase; import org.apache.fop.traits.BorderPropsTestCase; import org.apache.fop.util.ColorUtilTestCase; -import org.apache.fop.util.DataURIResolverTestCase; import org.apache.fop.util.ElementListUtilsTestCase; import org.apache.fop.util.PDFNumberTestCase; import org.apache.fop.util.XMLResourceBundleTestCase; @@ -49,7 +48,6 @@ public class UtilityCodeTestSuite { suite.addTest(new TestSuite(ColorUtilTestCase.class)); suite.addTest(new TestSuite(BorderPropsTestCase.class)); suite.addTest(new TestSuite(ElementListUtilsTestCase.class)); - suite.addTest(new TestSuite(DataURIResolverTestCase.class)); suite.addTest(new TestSuite(BasicEventTestCase.class)); suite.addTest(new TestSuite(XMLResourceBundleTestCase.class)); //$JUnit-END$ diff --git a/test/java/org/apache/fop/memory/MemoryEater.java b/test/java/org/apache/fop/memory/MemoryEater.java index bdbd47897..a665580ae 100644 --- a/test/java/org/apache/fop/memory/MemoryEater.java +++ b/test/java/org/apache/fop/memory/MemoryEater.java @@ -34,6 +34,7 @@ import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamSource; +import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.NullOutputStream; import org.apache.fop.apps.FOUserAgent; @@ -51,28 +52,48 @@ public class MemoryEater { private FopFactory fopFactory = FopFactory.newInstance(); private Templates replicatorTemplates; + private Stats stats; + public MemoryEater() throws TransformerConfigurationException, MalformedURLException { File xsltFile = new File("test/xsl/fo-replicator.xsl"); Source xslt = new StreamSource(xsltFile); replicatorTemplates = tFactory.newTemplates(xslt); } - private void eatMemory(File foFile, int replicatorRepeats) throws Exception { + private void eatMemory(File foFile, int runRepeats, int replicatorRepeats) throws Exception { + stats = new Stats(); + for (int i = 0; i < runRepeats; i++) { + eatMemory(i, foFile, replicatorRepeats); + stats.progress(i, runRepeats); + } + stats.dumpFinalStats(); + System.out.println(stats.getGoogleChartURL()); + } + + private void eatMemory(int callIndex, File foFile, int replicatorRepeats) throws Exception { Source src = new StreamSource(foFile); Transformer transformer = replicatorTemplates.newTransformer(); transformer.setParameter("repeats", new Integer(replicatorRepeats)); OutputStream out = new NullOutputStream(); //write to /dev/nul - FOUserAgent userAgent = fopFactory.newFOUserAgent(); - userAgent.setBaseURL(foFile.getParentFile().toURL().toExternalForm()); - Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out); - Result res = new SAXResult(fop.getDefaultHandler()); - - transformer.transform(src, res); + try { + FOUserAgent userAgent = fopFactory.newFOUserAgent(); + userAgent.setBaseURL(foFile.getParentFile().toURL().toExternalForm()); + Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out); + Result res = new SAXResult(fop.getDefaultHandler()); - System.out.println("Generated " + fop.getResults().getPageCount() + " pages."); + transformer.transform(src, res); + stats.notifyPagesProduced(fop.getResults().getPageCount()); + if (callIndex == 0) { + System.out.println(foFile.getName() + " generates " + + fop.getResults().getPageCount() + " pages."); + } + stats.checkStats(); + } finally { + IOUtils.closeQuietly(out); + } } private static void prompt() throws IOException { @@ -108,9 +129,7 @@ public class MemoryEater { long start = System.currentTimeMillis(); MemoryEater app = new MemoryEater(); - for (int i = 0; i < runRepeats; i++) { - app.eatMemory(testFile, replicatorRepeats); - } + app.eatMemory(testFile, runRepeats, replicatorRepeats); long duration = System.currentTimeMillis() - start; System.out.println("Success! Job took " + duration + " ms"); diff --git a/test/java/org/apache/fop/memory/Stats.java b/test/java/org/apache/fop/memory/Stats.java new file mode 100644 index 000000000..9e371251d --- /dev/null +++ b/test/java/org/apache/fop/memory/Stats.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.memory; + +import java.util.Iterator; +import java.util.List; + +class Stats { + + private static final int INTERVAL = 2000; + + private long startTime = System.currentTimeMillis(); + private long lastProgressDump = startTime; + private int pagesProduced; + + private int totalPagesProduced; + + private int step; + private int stepCount; + + private List samples = new java.util.LinkedList(); + + public void checkStats() { + long now = System.currentTimeMillis(); + if (now > lastProgressDump + INTERVAL) { + dumpStats(); + reset(); + } + } + + public void notifyPagesProduced(int count) { + pagesProduced += count; + totalPagesProduced += count; + } + + public void reset() { + pagesProduced = 0; + lastProgressDump = System.currentTimeMillis(); + } + + public void dumpStats() { + long duration = System.currentTimeMillis() - lastProgressDump; + + if (stepCount != 0) { + int progress = 100 * step / stepCount; + System.out.println("Progress: " + progress + "%, " + (stepCount - step) + " left"); + } + + long ppm = 60000 * pagesProduced / duration; + System.out.println("Speed: " + ppm + "ppm"); + samples.add(new Sample((int)ppm)); + } + + public void dumpFinalStats() { + long duration = System.currentTimeMillis() - startTime; + System.out.println("Final statistics"); + System.out.println("Pages produced: " +totalPagesProduced); + long ppm = 60000 * totalPagesProduced / duration; + System.out.println("Average speed: " + ppm + "ppm"); + } + + public String getGoogleChartURL() { + StringBuffer sb = new StringBuffer("http://chart.apis.google.com/chart?"); + //http://chart.apis.google.com/chart?cht=ls&chd=t:60,40&chs=250x100&chl=Hello|World + sb.append("cht=ls"); + sb.append("&chd=t:"); + boolean first = true; + int maxY = 0; + Iterator iter = samples.iterator(); + while (iter.hasNext()) { + Sample sample = (Sample)iter.next(); + if (first) { + first = false; + } else { + sb.append(','); + } + sb.append(sample.ppm); + maxY = Math.max(maxY, sample.ppm); + } + int ceilY = ((maxY / 1000) + 1) * 1000; + sb.append("&chs=1000x300"); //image size + sb.append("&chds=0,").append(ceilY); //data scale + sb.append("&chg=0,20"); //scale steps + sb.append("&chxt=y"); + sb.append("&chxl=0:|0|" + ceilY); + return sb.toString(); + } + + private static class Sample { + + private int ppm; + + public Sample(int ppm) { + this.ppm = ppm; + } + } + + public void progress(int step, int stepCount) { + this.step = step; + this.stepCount = stepCount; + + } + +} diff --git a/test/java/org/apache/fop/util/DataURIResolverTestCase.java b/test/java/org/apache/fop/util/DataURIResolverTestCase.java deleted file mode 100644 index 631b8dac1..000000000 --- a/test/java/org/apache/fop/util/DataURIResolverTestCase.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.util; - -import java.io.ByteArrayInputStream; - -import javax.xml.transform.Source; -import javax.xml.transform.URIResolver; -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.io.IOUtils; - -import junit.framework.TestCase; - -/** - * Test case for the RFC 2397 data URL/URI resolver. - */ -public class DataURIResolverTestCase extends TestCase { - - private static final byte[] TESTDATA = new byte[] {0, 1, 2, 3, 4, 5}; - - /** - * Tests DataURLUtil. - * @throws Exception if an error occurs - */ - public void testRFC2397Generator() throws Exception { - String url = DataURLUtil.createDataURL(new ByteArrayInputStream(TESTDATA), null); - assertEquals("Generated data URL is wrong", "data:;base64,AAECAwQF", url); - - url = DataURLUtil.createDataURL(new ByteArrayInputStream(TESTDATA), "application/pdf"); - assertEquals("Generated data URL is wrong", "data:application/pdf;base64,AAECAwQF", url); - } - - /** - * Test the URIResolver contract if the protocol doesn't match. Resolver must return null - * in this case. - * @throws Exception if an error occurs - */ - public void testNonMatchingContract() throws Exception { - URIResolver resolver = new DataURIResolver(); - Source src; - - src = resolver.resolve("http://xmlgraphics.apache.org/fop/index.html", null); - assertNull(src); - - src = resolver.resolve("index.html", "http://xmlgraphics.apache.org/fop/"); - assertNull(src); - } - - private static boolean byteCmp(byte[] src, int srcOffset, byte[] cmp) { - for (int i = 0, c = cmp.length; i < c; i++) { - if (src[srcOffset + i] != cmp[i]) { - return false; - } - } - return true; - } - - /** - * Test the DataURIResolver with correct values. - * @throws Exception if an error occurs - */ - public void testDataURLHandling() throws Exception { - URIResolver resolver = new DataURIResolver(); - Source src; - - src = resolver.resolve("data:;base64,AAECAwQF", null); - assertNotNull(src); - StreamSource streamSource = (StreamSource)src; - byte[] data = IOUtils.toByteArray(streamSource.getInputStream()); - assertTrue("Decoded data doesn't match the test data", byteCmp(TESTDATA, 0, data)); - - src = resolver.resolve( - "data:application/octet-stream;interpreter=fop;base64,AAECAwQF", null); - assertNotNull(src); - streamSource = (StreamSource)src; - assertNotNull(streamSource.getInputStream()); - assertNull(streamSource.getReader()); - data = IOUtils.toByteArray(streamSource.getInputStream()); - assertTrue("Decoded data doesn't match the test data", byteCmp(TESTDATA, 0, data)); - - src = resolver.resolve("data:,FOP", null); - assertNotNull(src); - streamSource = (StreamSource)src; - assertNull(streamSource.getInputStream()); - assertNotNull(streamSource.getReader()); - String text = IOUtils.toString(streamSource.getReader()); - assertEquals("FOP", text); - - /* TODO Un-escaping of special URL chars like %20 hasn't been implemented, yet. - src = resolver.resolve("data:,A%20brief%20note", null); - assertNotNull(src); - streamSource = (StreamSource)src; - text = IOUtils.toString(streamSource.getReader()); - assertEquals("A brief note", text); - */ - } - -} |