cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r608960 - in /cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon: components/sax/XMLByteStreamCompilerInterpreterTestCase.java xml/AbstractXMLTestCase.java
Date Fri, 04 Jan 2008 19:16:38 GMT
Author: antonio
Date: Fri Jan  4 11:16:37 2008
New Revision: 608960

URL: http://svn.apache.org/viewvc?rev=608960&view=rev
Log:
Test for COCOON-2158. Replace line 59 with line 58 to see the issue.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
    cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java?rev=608960&r1=608959&r2=608960&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/components/sax/XMLByteStreamCompilerInterpreterTestCase.java
Fri Jan  4 11:16:37 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -16,14 +16,17 @@
  */
 package org.apache.cocoon.components.sax;
 
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.ContentHandler;
-import org.apache.cocoon.xml.dom.DOMBuilder;
-import org.apache.cocoon.xml.AbstractXMLTestCase;
-import org.apache.cocoon.xml.DefaultHandlerWrapper;
+import java.io.ByteArrayInputStream;
+
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import java.io.ByteArrayInputStream;
+
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.cocoon.xml.AbstractXMLTestCase;
+import org.apache.cocoon.xml.DefaultHandlerWrapper;
+import org.apache.cocoon.xml.dom.DOMBuilder;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * Testcase for XMLByteStreamCompiler and Interpreter
@@ -43,14 +46,16 @@
         generateLargeSAX(in);
 
         // capture events
-        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+        XMLSerializer xmlc = makeSerializer();
         generateLargeSAX(xmlc);
 
         // recall events and build a DOM from it
-        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        XMLDeserializer xmli = makeDeserializer();
         DOMBuilder out = new DOMBuilder();
         xmli.setConsumer(out);
-        xmli.deserialize(xmlc.getSAXFragment());
+        final Object fragment = xmlc.getSAXFragment();
+        System.out.println("Fragment is bytes: " + ((byte[])fragment).length);
+		xmli.deserialize(fragment);
 
         // compare DOMs
         assertXMLEqual(in.getDocument(), out.getDocument());
@@ -58,15 +63,15 @@
 
     public void testCompareByteArray() throws Exception {
         // capture events
-        XMLByteStreamCompiler sa = new XMLByteStreamCompiler();
+        XMLSerializer sa = makeSerializer();
         generateLargeSAX(sa);
 
         // serialize events
         byte[] aa = (byte[]) sa.getSAXFragment();
 
         // deserialize and capture
-        XMLByteStreamCompiler sb = new XMLByteStreamCompiler();
-        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        XMLSerializer sb = makeSerializer();
+        XMLDeserializer xmli = makeDeserializer();
         xmli.setConsumer(sb);
         xmli.deserialize(aa);
 
@@ -81,7 +86,7 @@
     }
 
     public void testStressLoop() throws Exception {
-        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+        XMLSerializer xmlc = makeSerializer();
 
         long loop = 10000;
 
@@ -89,7 +94,12 @@
         long start = System.currentTimeMillis();
         for(int i=0;i<loop;i++) {
             generateSmallSAX(xmlc);
-            xmlc.recycle();
+            xmlc.getSAXFragment();
+            if (xmlc instanceof Recyclable) {
+            	((Recyclable)xmlc).recycle();
+            } else {
+            	xmlc = makeSerializer();
+            }
         }
         long stop = System.currentTimeMillis();
 
@@ -104,7 +114,7 @@
         SAXParserFactory pfactory = SAXParserFactory.newInstance();
         SAXParser p = pfactory.newSAXParser();
 
-        XMLByteStreamCompiler xmlc = new XMLByteStreamCompiler();
+        XMLSerializer xmlc = makeSerializer();
         DefaultHandlerWrapper wrapper = new DefaultHandlerWrapper(xmlc);
 
         ByteArrayInputStream bis = new ByteArrayInputStream(generateByteArray());
@@ -114,7 +124,11 @@
         // parse documents
         long start = System.currentTimeMillis();
         for(int i=0;i<loop;i++) {
-            xmlc.recycle();
+            if (xmlc instanceof Recyclable) {
+            	((Recyclable)xmlc).recycle();
+            } else {
+            	xmlc = makeSerializer();
+            }
             bis.reset();
             p.parse(bis,wrapper);
         }
@@ -124,13 +138,13 @@
         System.out.println("parsed: " + r + " documents per second");
 
 
-        XMLByteStreamInterpreter xmli = new XMLByteStreamInterpreter();
+        XMLDeserializer xmli = makeDeserializer();
         ContentHandler ch = new DefaultHandler();
 
         // recall documents
         start = System.currentTimeMillis();
         for(int i=0;i<loop;i++) {
-            xmli.setContentHandler(ch);
+            ((AbstractXMLByteStreamInterpreter)xmli).setContentHandler(ch);
             xmli.deserialize(xmlc.getSAXFragment());
         }
         stop = System.currentTimeMillis();
@@ -138,4 +152,12 @@
         r = 1000*loop/(stop-start);
         System.out.println("recalling: " + r + " documents per second");
     }
+
+	protected XMLDeserializer makeDeserializer() {
+		return new XMLByteStreamInterpreter();
+	}
+
+	protected XMLSerializer makeSerializer() {
+		return new XMLByteStreamCompiler();
+	}
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java?rev=608960&r1=608959&r2=608960&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/AbstractXMLTestCase.java Fri
Jan  4 11:16:37 2008
@@ -5,9 +5,9 @@
  * 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.
@@ -47,14 +47,20 @@
     protected void generateLargeSAX( ContentHandler consumer ) throws SAXException {
         AttributesImpl atts = new AttributesImpl();
 
-        final int size = 65000;
+        final int size = 66000;
         char[] large = new char[size];
         for(int i=0;i<size;i++) {
-            large[i] = 'x';
+            large[i] = '\uffff';
         }
 
         consumer.startDocument();
         consumer.startElement("", "root", "root", atts);
+//        for (int i=0; i<0x1ffff; ++i) { // breaks current code
+        for (int i=0; i<0x0ff0; ++i) { // doesn't break current code
+        	final String uniqueString = "f_" + i;
+            consumer.startElement("", uniqueString, uniqueString, atts);
+            consumer.endElement("", uniqueString, uniqueString);
+        }
         consumer.characters(large,0,size);
         consumer.endElement("", "root", "root");
         consumer.endDocument();



Mime
View raw message