8163468: javax/xml/jaxp/unittest/validation/Bug6773084Test.java fails intermittently
authorfyuan
Thu, 11 Aug 2016 10:20:44 +0800
changeset 40292 bcb68f9b7b34
parent 40291 c0ab22b640c9
child 40293 5cb21ed83e3d
8163468: javax/xml/jaxp/unittest/validation/Bug6773084Test.java fails intermittently Reviewed-by: joehw, dfuchs, amlu Contributed-by: Frank Yuan <frank.yuan@oracle.com>
jaxp/test/javax/xml/jaxp/libs/jaxp/library/BasePolicy.java
jaxp/test/javax/xml/jaxp/unittest/validation/Bug6773084Test.java
--- a/jaxp/test/javax/xml/jaxp/libs/jaxp/library/BasePolicy.java	Wed Aug 10 15:49:23 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/libs/jaxp/library/BasePolicy.java	Thu Aug 11 10:20:44 2016 +0800
@@ -37,7 +37,7 @@
         try {
             JAXPPolicyManager.teardownPolicyManager();
         } catch (Exception e) {
-            throw new RuntimeException("Failed to teardonw the policy manager", e);
+            throw new RuntimeException("Failed to teardown the policy manager", e);
         }
     }
 
--- a/jaxp/test/javax/xml/jaxp/unittest/validation/Bug6773084Test.java	Wed Aug 10 15:49:23 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/validation/Bug6773084Test.java	Thu Aug 11 10:20:44 2016 +0800
@@ -32,11 +32,10 @@
 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.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;
@@ -69,6 +68,7 @@
     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();
@@ -93,20 +93,23 @@
             }
         });
 
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+
         for (int i = 0; i < files.length; i++) {
-            EXEC.execute(new XMLValiddator(files[i], 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 File file;
+        private Document document;
         private int index;
 
-        public XMLValiddator(File file, int index) {
-            this.file = file;
+        public XMLValiddator(Document document, int index) {
+            this.document = document;
             this.index = index;
         }
 
@@ -117,23 +120,14 @@
                 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) {