You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/09/05 15:05:31 UTC
svn commit: r992777 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-api/src/test/java/org/apache/axiom/om/util/
axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/
axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/
Author: veithen
Date: Sun Sep 5 13:05:30 2010
New Revision: 992777
URL: http://svn.apache.org/viewvc?rev=992777&view=rev
Log:
Refactored some StAXUtils tests to include them into the StAX dialect test suite.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java?rev=992777&r1=992776&r2=992777&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java Sun Sep 5 13:05:30 2010
@@ -19,93 +19,9 @@
package org.apache.axiom.om.util;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
import junit.framework.TestCase;
public class StAXUtilsTest extends TestCase {
- public interface Action {
- void execute() throws Exception;
- }
-
- private void testThreadSafety(final Action action) throws Throwable {
- int threadCount = 10;
- final List results = new ArrayList(threadCount);
- for (int i=0; i<threadCount; i++) {
- new Thread(new Runnable() {
- public void run() {
- Throwable result;
- try {
- for (int i=0; i<1000; i++) {
- action.execute();
- }
- result = null;
- } catch (Throwable ex) {
- result = ex;
- }
- synchronized (results) {
- results.add(result);
- results.notifyAll();
- }
- }
- }).start();
- }
- synchronized (results) {
- while (results.size() < threadCount) {
- results.wait();
- }
- }
- for (Iterator it = results.iterator(); it.hasNext(); ) {
- Throwable result = (Throwable)it.next();
- if (result != null) {
- throw result;
- }
- }
- }
-
- // Regression test for WSCOMMONS-489
- public void testCreateXMLStreamReaderIsThreadSafe() throws Throwable {
- testThreadSafety(new Action() {
- public void execute() throws Exception {
- String text = String.valueOf((int)(Math.random() * 10000));
- String xml = "<root>" + text + "</root>";
- XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader(xml));
- assertEquals(XMLStreamReader.START_DOCUMENT, reader.getEventType());
- assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
- assertEquals(XMLStreamReader.CHARACTERS, reader.next());
- assertEquals(text, reader.getText());
- assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
- assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
- reader.close();
- }
- });
- }
-
- // Regression test for WSCOMMONS-489
- public void testCreateXMLStreamWriterIsThreadSafe() throws Throwable {
- testThreadSafety(new Action() {
- public void execute() throws Exception {
- String text = String.valueOf((int)(Math.random() * 10000));
- StringWriter out = new StringWriter();
- XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(out);
- writer.writeStartElement("root");
- writer.writeCharacters(text);
- writer.writeEndElement();
- writer.writeEndDocument();
- writer.flush();
- writer.close();
- assertEquals("<root>" + text + "</root>", out.toString());
- }
- });
- }
-
public void testInputFactoryIsImmutable() throws Exception {
try {
StAXUtils.getXMLInputFactory().setProperty("javax.xml.stream.isValidating",
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java?rev=992777&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java Sun Sep 5 13:05:30 2010
@@ -0,0 +1,47 @@
+/*
+ * 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.axiom.util.stax.dialect;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.testutils.concurrent.Action;
+import org.apache.axiom.testutils.concurrent.ConcurrentTestUtils;
+
+public class CreateXMLStreamReaderThreadSafetyTestCase extends DialectTestCase {
+ protected void runTest() throws Throwable {
+ final XMLInputFactory factory = getDialect().makeThreadSafe(newNormalizedXMLInputFactory());
+ ConcurrentTestUtils.testThreadSafety(new Action() {
+ public void execute() throws Exception {
+ String text = String.valueOf((int)(Math.random() * 10000));
+ String xml = "<root>" + text + "</root>";
+ XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
+ assertEquals(XMLStreamReader.START_DOCUMENT, reader.getEventType());
+ assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+ assertEquals(XMLStreamReader.CHARACTERS, reader.next());
+ assertEquals(text, reader.getText());
+ assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
+ assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
+ reader.close();
+ }
+ });
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamReaderThreadSafetyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java?rev=992777&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java Sun Sep 5 13:05:30 2010
@@ -0,0 +1,47 @@
+/*
+ * 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.axiom.util.stax.dialect;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.testutils.concurrent.Action;
+import org.apache.axiom.testutils.concurrent.ConcurrentTestUtils;
+
+public class CreateXMLStreamWriterThreadSafetyTestCase extends DialectTestCase {
+ protected void runTest() throws Throwable {
+ final XMLOutputFactory factory = getDialect().makeThreadSafe(newNormalizedXMLOutputFactory());
+ ConcurrentTestUtils.testThreadSafety(new Action() {
+ public void execute() throws Exception {
+ String text = String.valueOf((int)(Math.random() * 10000));
+ StringWriter out = new StringWriter();
+ XMLStreamWriter writer = factory.createXMLStreamWriter(out);
+ writer.writeStartElement("root");
+ writer.writeCharacters(text);
+ writer.writeEndElement();
+ writer.writeEndDocument();
+ writer.flush();
+ writer.close();
+ assertEquals("<root>" + text + "</root>", out.toString());
+ }
+ });
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/CreateXMLStreamWriterThreadSafetyTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=992777&r1=992776&r2=992777&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java Sun Sep 5 13:05:30 2010
@@ -36,6 +36,8 @@ public class DialectTest extends TestSui
this.classLoader = classLoader;
this.props = props;
addDialectTest(new CreateXMLEventWriterWithNullEncodingTestCase());
+ addDialectTest(new CreateXMLStreamReaderThreadSafetyTestCase());
+ addDialectTest(new CreateXMLStreamWriterThreadSafetyTestCase());
addDialectTest(new CreateXMLStreamWriterWithNullEncodingTestCase());
addDialectTest(new DisallowDoctypeDeclWithDenialOfServiceTestCase());
addDialectTest(new DisallowDoctypeDeclWithExternalSubsetTestCase());
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java?rev=992777&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java Sun Sep 5 13:05:30 2010
@@ -0,0 +1,24 @@
+/*
+ * 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.axiom.testutils.concurrent;
+
+public interface Action {
+ void execute() throws Exception;
+}
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/Action.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java?rev=992777&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java Sun Sep 5 13:05:30 2010
@@ -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.axiom.testutils.concurrent;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ConcurrentTestUtils {
+
+ public static void testThreadSafety(final Action action) throws Throwable {
+ int threadCount = 10;
+ final List results = new ArrayList(threadCount);
+ for (int i=0; i<threadCount; i++) {
+ new Thread(new Runnable() {
+ public void run() {
+ Throwable result;
+ try {
+ for (int i=0; i<1000; i++) {
+ action.execute();
+ }
+ result = null;
+ } catch (Throwable ex) {
+ result = ex;
+ }
+ synchronized (results) {
+ results.add(result);
+ results.notifyAll();
+ }
+ }
+ }).start();
+ }
+ synchronized (results) {
+ while (results.size() < threadCount) {
+ results.wait();
+ }
+ }
+ for (Iterator it = results.iterator(); it.hasNext(); ) {
+ Throwable result = (Throwable)it.next();
+ if (result != null) {
+ throw result;
+ }
+ }
+ }
+
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java
------------------------------------------------------------------------------
svn:eol-style = native