You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2009/02/07 14:44:26 UTC
svn commit: r741893 - in /cocoon/cocoon3/trunk/cocoon-stax: ./
src/test/java/org/apache/cocoon/stax/stress/
src/test/java/org/apache/cocoon/stax/stress/src/
src/test/java/org/apache/cocoon/stax/stress/test/
src/test/resources/org/apache/cocoon/stax/str...
Author: reinhard
Date: Sat Feb 7 13:44:26 2009
New Revision: 741893
URL: http://svn.apache.org/viewvc?rev=741893&view=rev
Log:
COCOON3-20
Add stress tests that process huge data sets (double size of the available memory). These tests only run if the 'stress' profile is activated at the Maven build.
Added:
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java (with props)
cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/
cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml (with props)
Modified:
cocoon/cocoon3/trunk/cocoon-stax/pom.xml
Modified: cocoon/cocoon3/trunk/cocoon-stax/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/pom.xml?rev=741893&r1=741892&r2=741893&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-stax/pom.xml Sat Feb 7 13:44:26 2009
@@ -56,7 +56,7 @@
<groupId>org.apache.cocoon.sax</groupId>
<artifactId>cocoon-sax</artifactId>
<optional>true</optional>
- </dependency>
+ </dependency>
<!-- test dependencies -->
<dependency>
@@ -85,9 +85,17 @@
<target>1.6</target>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/cocoon/stax/stress/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
</plugins>
</build>
-
+
<profiles>
<profile>
<id>it</id>
@@ -100,7 +108,7 @@
<excludes>
<exclude>src/main/java/org/apache/cocoon/stax/converter/util/*.java</exclude>
</excludes>
- </configuration>
+ </configuration>
<executions>
<execution>
<phase>verify</phase>
@@ -109,9 +117,41 @@
</goals>
</execution>
</executions>
- </plugin>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>stress</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/cocoon/**</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ <configuration>
+ <excludes>
+ <exclude>none</exclude>
+ </excludes>
+ <includes>
+ <include>**/cocoon/stax/stress/test/*Test.*</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
- </build>
- </profile>
+ </build>
+ </profile>
</profiles>
</project>
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.src;
+
+import java.util.List;
+
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.cocoon.stax.AbstractStAXTransformer;
+import org.apache.cocoon.stax.StAXConsumer;
+import org.apache.cocoon.stax.navigation.FindStartElementNavigator;
+import org.apache.cocoon.stax.navigation.Navigator;
+
+/**
+ * A transformer that emits new elements under a configurable parent.
+ */
+public class EmitElementTransformer extends AbstractStAXTransformer implements StAXConsumer {
+
+ private static final int BATCH_SIZE = 1000;
+ private final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ private Navigator navigator;
+ private String childElementName;
+ private int elementCount;
+ private boolean emitingElements;
+ private int count;
+
+ /**
+ * Creates a new {@link EmitElementTransformer} that emits new elements under a configurable
+ * parent.
+ *
+ * @param parentElementName The name of the element that is the parent of the new emitted
+ * elements.
+ * @param parentElementAttributes The attributes an element must contain in order to be the
+ * parent of the new emitted elements.
+ * @param childElement The name the created children shall have.
+ * @param elementCount The number of identical children that shall be emitted.
+ */
+ public EmitElementTransformer(String parentElementName, List<Attribute> parentElementAttributes,
+ String childElement, int elementCount) {
+ this.navigator = new FindStartElementNavigator(parentElementName, parentElementAttributes);
+ this.childElementName = childElement;
+ this.elementCount = elementCount;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.stax.AbstractStAXTransformer#produceEvents()
+ */
+ @Override
+ protected void produceEvents() throws XMLStreamException {
+ if (!this.emitingElements && this.getParent().hasNext()) {
+ XMLEvent event = this.getParent().nextEvent();
+ this.addEventToQueue(event);
+
+ if (this.navigator.fulfillsCriteria(event)) {
+ this.emitingElements = true;
+ this.count = 0;
+ }
+ } else {
+ for (; this.count < this.elementCount;) {
+ this.count++;
+ this.addEventToQueue(this.eventFactory.createStartElement("", "", this.childElementName));
+ this.addEventToQueue(this.eventFactory.createEndElement("", "", this.childElementName));
+ if (this.count % BATCH_SIZE == 0) {
+ break;
+ }
+ }
+
+ if (this.count >= this.elementCount) {
+ this.emitingElements = false;
+ }
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/EmitElementTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,144 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.src;
+
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.cocoon.pipeline.component.Starter;
+import org.apache.cocoon.stax.AbstractStAXProducer;
+
+/**
+ * This Starter implementation generates events of a simple document with a specified root element
+ * followed by a number of specified elements.
+ */
+public class GeneratingStarter extends AbstractStAXProducer implements Starter {
+
+ private XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ private String rootElement;
+ private String repeatingElementName;
+ private int repetitionCount;
+ private int currentElementNumber = 0;
+ private GenerationState state = GenerationState.START_DOCUMENT;
+
+ /**
+ * Creates a new {@link GeneratingStarter} {@link Starter} that generates events of a simple
+ * document with a specified root element followed by a number of specified elements.
+ *
+ * @param rootElement
+ * @param repeatingElementName
+ * @param repetitionCount
+ */
+ public GeneratingStarter(String rootElement, String repeatingElementName, int repetitionCount) {
+ this.rootElement = rootElement;
+ this.repeatingElementName = repeatingElementName;
+ this.repetitionCount = repetitionCount;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.pipeline.component.Starter#execute()
+ */
+ @Override
+ public void execute() {
+ this.getConsumer().initiatePullProcessing();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.stax.StAXProducer#hasNext()
+ */
+ @Override
+ public boolean hasNext() {
+ return !this.state.equals(GenerationState.FINISHED);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.stax.StAXProducer#nextEvent()
+ */
+ @Override
+ public XMLEvent nextEvent() throws XMLStreamException {
+ return this.createNextElement(false);
+ }
+
+ /**
+ * Creates the next element.
+ *
+ * @param isPeeking Indicates if the element is peeked or consumed.
+ * @return The next element.
+ * @throws XMLStreamException Is thrown if an error occurs.
+ */
+ private XMLEvent createNextElement(boolean isPeeking) throws XMLStreamException {
+ switch (this.state) {
+ case START_REPEATING_ELEMENT:
+ if (!isPeeking) {
+ this.state = GenerationState.END_REPEATING_ELEMENT;
+ }
+ return this.eventFactory.createStartElement("", "", this.repeatingElementName);
+ case END_REPEATING_ELEMENT:
+ if (!isPeeking) {
+ this.currentElementNumber++;
+ if (this.currentElementNumber == this.repetitionCount) {
+ this.state = GenerationState.END_ROOT;
+ } else {
+ this.state = GenerationState.START_REPEATING_ELEMENT;
+ }
+ }
+ return this.eventFactory.createEndElement("", "", this.repeatingElementName);
+ case START_DOCUMENT:
+ if (!isPeeking) {
+ this.state = GenerationState.START_ROOT;
+ }
+ return this.eventFactory.createStartDocument();
+ case START_ROOT:
+ if (!isPeeking) {
+ if (this.currentElementNumber == this.repetitionCount) {
+ this.state = GenerationState.END_ROOT;
+ } else {
+ this.state = GenerationState.START_REPEATING_ELEMENT;
+ }
+ }
+ return this.eventFactory.createStartElement("", "", this.rootElement);
+ case END_DOCUMENT:
+ if (!isPeeking) {
+ this.state = GenerationState.FINISHED;
+ }
+ return this.eventFactory.createEndDocument();
+ case END_ROOT:
+ if (!isPeeking) {
+ this.state = GenerationState.END_DOCUMENT;
+ }
+ return this.eventFactory.createEndElement("", "", this.rootElement);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.stax.StAXProducer#peek()
+ */
+ @Override
+ public XMLEvent peek() throws XMLStreamException {
+ return this.createNextElement(true);
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GeneratingStarter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.src;
+
+/**
+ * Enumeration for different states a generator can have.
+ */
+public enum GenerationState {
+
+ /** Indicates that the document started. */
+ START_DOCUMENT,
+
+ /** Indicates the root xml element start. */
+ START_ROOT,
+
+ /** Indicates an intermediate xml element start. */
+ START_REPEATING_ELEMENT,
+
+ /** Indicates an intermediate xml element end. */
+ END_REPEATING_ELEMENT,
+
+ /** Indicates the root xml element end. */
+ END_ROOT,
+
+ /** Indicates that the document ends. */
+ END_DOCUMENT,
+
+ /** Indicates that the document was created completely. */
+ FINISHED
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/GenerationState.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.src;
+
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.cocoon.stax.AbstractStAXTransformer;
+import org.apache.cocoon.stax.navigation.FindCorrespondingStartEndElementPairNavigator;
+import org.apache.cocoon.stax.navigation.Navigator;
+
+/**
+ * This Transformer omits elements, that match certain criteria.
+ */
+public class OmitElementTransformer extends AbstractStAXTransformer {
+
+ private Navigator navigator;
+
+ /**
+ * Creates a new {@link OmitElementTransformer} that omits elements matching certain criteria.
+ *
+ * @param elementName The name of the elements that shall be omitted.
+ * @param attributes The attributes an element must contain in order to be omitted.
+ */
+ public OmitElementTransformer(String elementName, List<Attribute> attributes) {
+ this.navigator = new FindCorrespondingStartEndElementPairNavigator(elementName, attributes);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.stax.AbstractStAXTransformer#produceEvents()
+ */
+ @Override
+ protected void produceEvents() throws XMLStreamException {
+ while (this.getParent().hasNext()) {
+ XMLEvent event = this.getParent().nextEvent();
+ if (!this.navigator.fulfillsCriteria(event)) {
+ this.addEventToQueue(event);
+ return;
+ }
+ }
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/src/OmitElementTransformer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.test;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Map;
+
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.component.Consumer;
+import org.apache.cocoon.stax.StAXGenerator;
+import org.apache.cocoon.stax.StAXPipelineComponent;
+import org.apache.cocoon.stax.StAXProducer;
+import org.apache.cocoon.stax.StAXSerializer;
+import org.apache.cocoon.stax.stress.src.EmitElementTransformer;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Contains unit tests for the emit transformer.<br>
+ *
+ * It emits a number of configurable elements at a specific point of the document.
+ *
+ */
+public class EmitTransformerTest {
+
+ /**
+ * Shows a transformer emitting new elements at a point of the document step by step.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testEmitTransformerBySteps() throws Exception {
+ EmitElementTransformer transformer = new EmitElementTransformer("parent", new ArrayList<Attribute>(), "child",
+ 1);
+
+ transformer.setParent(new StAXProducer() {
+ private final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ private boolean startEmitted = false;
+
+ @Override
+ public boolean hasNext() {
+ return true;
+ }
+
+ @Override
+ public XMLEvent nextEvent() throws XMLStreamException {
+ if (this.startEmitted) {
+ return this.eventFactory.createEndElement("", "", "parent");
+ } else {
+ this.startEmitted = true;
+ return this.eventFactory.createStartElement("", "", "parent");
+ }
+ }
+
+ @Override
+ public XMLEvent peek() throws XMLStreamException {
+ throw new RuntimeException("not impl");
+ }
+
+ @Override
+ public void setConsumer(Consumer consumer) {
+ }
+
+ @Override
+ public void finish() {
+ }
+
+ @Override
+ public void setConfiguration(Map<String, ? extends Object> configuration) {
+ }
+
+ @Override
+ public void setup(Map<String, Object> parameters) {
+ }
+ });
+
+ // "parent" start-tag
+ assertTrue(transformer.hasNext());
+ XMLEvent event = transformer.nextEvent();
+ assertTrue(event.isStartElement());
+ assertEquals(event.asStartElement().getName().getLocalPart(), "parent");
+
+ // "child" start-tag
+ assertTrue(transformer.hasNext());
+ event = transformer.nextEvent();
+ assertTrue(event.isStartElement());
+ assertEquals(event.asStartElement().getName().getLocalPart(), "child");
+
+ // "child" end-tag
+ assertTrue(transformer.hasNext());
+ event = transformer.nextEvent();
+ assertTrue(event.isEndElement());
+ assertEquals(event.asEndElement().getName().getLocalPart(), "child");
+
+ // "element" end-tag
+ assertTrue(transformer.hasNext());
+ event = transformer.nextEvent();
+ assertTrue(event.isEndElement());
+ assertEquals(event.asEndElement().getName().getLocalPart(), "parent");
+ }
+
+ /**
+ * Shows a transformer emitting new elements at a point of the document included in a pipeline.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testEmitTransformer() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ InputStream in = new ByteArrayInputStream("<root/>".getBytes());
+
+ Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
+ pipe.addComponent(new StAXGenerator(in));
+ pipe.addComponent(new EmitElementTransformer("root", new ArrayList<Attribute>(), "element", 5));
+ pipe.addComponent(new StAXSerializer());
+ pipe.setup(out);
+ pipe.execute();
+
+ String created = new String(out.toByteArray());
+ out.close();
+
+ StringBuffer correctOne = new StringBuffer("<root>");
+ for (int i = 0; i < 5; i++) {
+ correctOne.append("<element/>");
+ }
+ correctOne.append("</root>");
+ XMLUnit.setIgnoreWhitespace(true);
+ Diff myDiff = new Diff(correctOne.toString(), created);
+ assertTrue("pieces of XML are similar " + myDiff, myDiff.similar());
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/EmitTransformerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.test;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.stax.StAXPipelineComponent;
+import org.apache.cocoon.stax.StAXSerializer;
+import org.apache.cocoon.stax.stress.src.GeneratingStarter;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Contains unit tests of the generating starter, which generates a document on the fly.<br>
+ *
+ */
+public class GeneratingStarterTest {
+
+ /**
+ * Tests an empty document - that is an document without any child elements.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testGeneratingStarterEmpty() throws Exception {
+ this.doTest(0);
+ }
+
+ /**
+ * Tests an document with one child element.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testGeneratingStarterOneChildElement() throws Exception {
+ this.doTest(1);
+ }
+
+ /**
+ * Tests an document with more child elements.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testGeneratingStarterMultipleChildElements() throws Exception {
+ this.doTest(100);
+ }
+
+ /**
+ * Helper test method, sets up the pipeline and GeneratingStarter and verifies the result.
+ *
+ * @param count the number of child elements of the GeneratingStarter
+ * @throws Exception
+ */
+ private void doTest(int count) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
+ pipe.addComponent(new GeneratingStarter("root", "element", count));
+ pipe.addComponent(new StAXSerializer());
+ pipe.setup(out);
+ pipe.execute();
+
+ String created = new String(out.toByteArray());
+ out.close();
+ StringBuffer correctOne = new StringBuffer("<root>");
+ for (int i = 0; i < count; i++) {
+ correctOne.append("<element/>");
+ }
+ correctOne.append("</root>");
+
+ XMLUnit.setIgnoreWhitespace(true);
+ Diff myDiff = new Diff(correctOne.toString(), created);
+ assertTrue("pieces of XML are similar " + myDiff, myDiff.similar());
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/GeneratingStarterTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java Sat Feb 7 13:44:26 2009
@@ -0,0 +1,140 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.stax.stress.test;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+
+import javax.xml.stream.events.Attribute;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.stax.StAXGenerator;
+import org.apache.cocoon.stax.StAXPipelineComponent;
+import org.apache.cocoon.stax.StAXSerializer;
+import org.apache.cocoon.stax.component.IncludeTransformer;
+import org.apache.cocoon.stax.stress.src.EmitElementTransformer;
+import org.apache.cocoon.stax.stress.src.GeneratingStarter;
+import org.apache.cocoon.stax.stress.src.OmitElementTransformer;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+/**
+ * Contains the tests with huge data sets.<br>
+ * It should show that the cocoon-stax implementation is capable to process data bigger than the
+ * available virtual memory.
+ *
+ */
+public class HugeDataTest {
+
+ private final int TEST_SIZE;
+
+ public HugeDataTest() {
+ // results in documents with approx. 2 times of the maximum memory. The
+ // number is designed for systems running with 256mb of ram. Since some
+ // maven processes require more than that a minimum value was added that
+ // the tests could be run in acceptable time.
+ this.TEST_SIZE = Math.min((int) (Runtime.getRuntime().maxMemory() * 2 / 10), 102196838);
+ }
+
+ /**
+ * Tests an huge input document, which is processed to a very small output.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testHugeInSmallOut() throws Exception {
+ Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
+ pipe.addComponent(new GeneratingStarter("root", "element", this.TEST_SIZE));
+ pipe.addComponent(new OmitElementTransformer("element", new ArrayList<Attribute>()));
+ pipe.addComponent(new StAXSerializer());
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ pipe.setup(out);
+ pipe.execute();
+ out.close();
+ }
+
+ /**
+ * Tests an adding transformer variant, which produces a huge output document from a small input
+ * document.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testSmallInHugeOut() throws Exception {
+ File tmpOutput = File.createTempFile("C3HUGE", ".xml");
+ tmpOutput.deleteOnExit();
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpOutput));
+ InputStream in = new ByteArrayInputStream("<root/>".getBytes());
+
+ Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
+ pipe.addComponent(new StAXGenerator(in));
+ pipe.addComponent(new EmitElementTransformer("root", new ArrayList<Attribute>(), "element", this.TEST_SIZE));
+ pipe.addComponent(new StAXSerializer());
+ pipe.setup(out);
+ pipe.execute();
+ }
+
+ /**
+ * Tests using an {@link IncludeTransformer} to include a huge file.
+ *
+ * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
+ * itself.
+ */
+ @Test
+ public void testSmallIn_IncludeHuge_HugeOut() throws Exception {
+ File input = File.createTempFile("C3STAXHUGEINC_INPUT", ".xml");
+ File include = File.createTempFile("C3STAXHUGEINC_INCLUDE", ".xml");
+ File output = File.createTempFile("C3STAXHUGEINC_OUTPUT", ".xml");
+ input.deleteOnExit();
+ include.deleteOnExit();
+ output.deleteOnExit();
+ PrintStream includeSource = new PrintStream(include);
+ includeSource.println("<test>");
+ for (int i = 0; i < this.TEST_SIZE; i++) {
+ includeSource.println("<element></element>");
+ }
+ includeSource.println("</test>");
+ includeSource.close();
+
+ String inputSource = IOUtils.toString(
+ HugeDataTest.class
+ .getResourceAsStream("/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml"))
+ .replaceAll("file_to_include\\.xml", include.toURI().toURL().toString());
+ FileUtils.writeStringToFile(input, inputSource);
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(output));
+ Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
+ pipe.addComponent(new StAXGenerator(new FileInputStream(input)));
+ pipe.addComponent(new IncludeTransformer());
+ pipe.addComponent(new StAXSerializer());
+ pipe.setup(out);
+ pipe.execute();
+
+ out.close();
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/java/org/apache/cocoon/stax/stress/test/HugeDataTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml?rev=741893&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml (added)
+++ cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml Sat Feb 7 13:44:26 2009
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<root>
+ <include xmlns="http://apache.org/cocoon/3.0/include" src="file_to_include.xml" />
+</root>
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cocoon/cocoon3/trunk/cocoon-stax/src/test/resources/org/apache/cocoon/stax/stress/stax-test-huge-include-input.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml