use of org.apache.axiom.testutils.concurrent.Action in project webservices-axiom by apache.
the class TestCreateXMLStreamReaderThreadSafety method runTest.
protected void runTest() throws Throwable {
final XMLInputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.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();
}
});
}
use of org.apache.axiom.testutils.concurrent.Action in project webservices-axiom by apache.
the class TestCreateXMLStreamWriterThreadSafety method runTest.
@SuppressWarnings("deprecation")
protected void runTest() throws Throwable {
final XMLOutputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.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());
}
});
}
Aggregations