< prev index next >

test/javax/xml/jaxp/unittest/validation/Bug6773084Test.java

Print this page

        

*** 30,44 **** import java.io.IOException; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.xml.XMLConstants; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; --- 30,43 ---- import java.io.IOException; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; + import java.util.concurrent.TimeUnit; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory;
*** 67,76 **** --- 66,76 ---- private static final int NTHREADS = 25; private static final ExecutorService EXEC = Executors.newCachedThreadPool(); private static final CyclicBarrier BARRIER = new CyclicBarrier(NTHREADS); + private static final int TIMEOUT = 110; public static final String IN_FOLDER = Bug6773084Test.class.getResource("Bug6773084In").getPath(); public static final String XSD_PATH = Bug6773084Test.class.getResource("Bug6773084.xsd").getPath(); private static Schema schema;
*** 91,141 **** public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".xml"); } }); for (int i = 0; i < files.length; i++) { ! EXEC.execute(new XMLValiddator(files[i], i)); } runWithAllPerm(() -> EXEC.shutdown()); ! } private static class XMLValiddator implements Runnable { ! private File file; private int index; ! public XMLValiddator(File file, int index) { ! this.file = file; this.index = index; } public void run() { try { System.out.printf("Waiting for barrier: %s%n", index); BARRIER.await(); System.out.println("Validating...."); - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse(file); - Validator validator = schema.newValidator(); validator.setErrorHandler(new ErrorHandlerImpl()); validator.validate(new DOMSource(document)); - } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); Assert.fail("Test failed."); - } catch (ParserConfigurationException e) { - e.printStackTrace(); } catch (BrokenBarrierException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } --- 91,135 ---- public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".xml"); } }); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + for (int i = 0; i < files.length; i++) { ! EXEC.execute(new XMLValiddator(dbf.newDocumentBuilder().parse(files[i]), i)); } runWithAllPerm(() -> EXEC.shutdown()); ! EXEC.awaitTermination(TIMEOUT, TimeUnit.SECONDS); } private static class XMLValiddator implements Runnable { ! private Document document; private int index; ! public XMLValiddator(Document document, int index) { ! this.document = document; this.index = index; } public void run() { try { System.out.printf("Waiting for barrier: %s%n", index); BARRIER.await(); System.out.println("Validating...."); Validator validator = schema.newValidator(); validator.setErrorHandler(new ErrorHandlerImpl()); validator.validate(new DOMSource(document)); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); Assert.fail("Test failed."); } catch (BrokenBarrierException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); }
< prev index next >