1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
26 import java.io.File;
27 import java.io.FileFilter;
28 import java.io.IOException;
29 import java.util.concurrent.BrokenBarrierException;
30 import java.util.concurrent.CyclicBarrier;
31 import java.util.concurrent.ExecutorService;
32 import java.util.concurrent.Executors;
33
34 import javax.xml.XMLConstants;
35 import javax.xml.parsers.DocumentBuilder;
36 import javax.xml.parsers.DocumentBuilderFactory;
37 import javax.xml.parsers.ParserConfigurationException;
38 import javax.xml.transform.Source;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.stream.StreamSource;
41 import javax.xml.validation.Schema;
42 import javax.xml.validation.SchemaFactory;
43 import javax.xml.validation.Validator;
44
45 import org.testng.Assert;
46 import org.testng.annotations.BeforeClass;
47 import org.testng.annotations.Test;
48 import org.w3c.dom.Document;
49 import org.xml.sax.ErrorHandler;
50 import org.xml.sax.SAXException;
51 import org.xml.sax.SAXParseException;
52
53 /*
54 * @bug 6773084
55 * @summary Test Schema object is thread safe.
56 */
57 public class Bug6773084Test {
58 static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
59 static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
60
61 private static final int NTHREADS = 25;
62 private static final ExecutorService EXEC = Executors.newCachedThreadPool();
63
64 private static final CyclicBarrier BARRIER = new CyclicBarrier(NTHREADS);
65
66 public static final String IN_FOLDER = Bug6773084Test.class.getResource("Bug6773084In").getPath();
67 public static final String XSD_PATH = Bug6773084Test.class.getResource("Bug6773084.xsd").getPath();
68
69 private static Schema schema;
70
71 @BeforeClass
72 public void setup(){
73 policy.PolicyUtil.changePolicy(getClass().getResource("6773084.policy").getFile());
74 }
75
76 @Test
77 public void test() throws Exception {
78 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
79 Source schemaFile = new StreamSource(XSD_PATH);
80 try {
81 schema = factory.newSchema(schemaFile);
82 } catch (SAXException e) {
83 e.printStackTrace();
84 System.exit(-1);
85 }
86
87 File incoming = new File(IN_FOLDER);
88 File[] files = incoming.listFiles(new FileFilter() {
89 public boolean accept(File file) {
90 return file.isFile() && file.getName().endsWith(".xml");
91 }
92 });
93
94 for (int i = 0; i < files.length; i++) {
95 EXEC.execute(new XMLValiddator(files[i], i));
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
26 import java.io.File;
27 import java.io.FileFilter;
28 import java.io.IOException;
29 import java.util.concurrent.BrokenBarrierException;
30 import java.util.concurrent.CyclicBarrier;
31 import java.util.concurrent.ExecutorService;
32 import java.util.concurrent.Executors;
33
34 import javax.xml.XMLConstants;
35 import javax.xml.parsers.DocumentBuilder;
36 import javax.xml.parsers.DocumentBuilderFactory;
37 import javax.xml.parsers.ParserConfigurationException;
38 import javax.xml.transform.Source;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.stream.StreamSource;
41 import javax.xml.validation.Schema;
42 import javax.xml.validation.SchemaFactory;
43 import javax.xml.validation.Validator;
44
45 import org.testng.Assert;
46 import org.testng.annotations.Listeners;
47 import org.testng.annotations.Test;
48 import org.w3c.dom.Document;
49 import org.xml.sax.ErrorHandler;
50 import org.xml.sax.SAXException;
51 import org.xml.sax.SAXParseException;
52
53 /*
54 * @bug 6773084
55 * @summary Test Schema object is thread safe.
56 */
57 @Listeners({jaxp.library.FilePolicy.class})
58 public class Bug6773084Test {
59 static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
60 static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
61
62 private static final int NTHREADS = 25;
63 private static final ExecutorService EXEC = Executors.newCachedThreadPool();
64
65 private static final CyclicBarrier BARRIER = new CyclicBarrier(NTHREADS);
66
67 public static final String IN_FOLDER = Bug6773084Test.class.getResource("Bug6773084In").getPath();
68 public static final String XSD_PATH = Bug6773084Test.class.getResource("Bug6773084.xsd").getPath();
69
70 private static Schema schema;
71
72 @Test
73 public void test() throws Exception {
74 SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
75 Source schemaFile = new StreamSource(XSD_PATH);
76 try {
77 schema = factory.newSchema(schemaFile);
78 } catch (SAXException e) {
79 e.printStackTrace();
80 System.exit(-1);
81 }
82
83 File incoming = new File(IN_FOLDER);
84 File[] files = incoming.listFiles(new FileFilter() {
85 public boolean accept(File file) {
86 return file.isFile() && file.getName().endsWith(".xml");
87 }
88 });
89
90 for (int i = 0; i < files.length; i++) {
91 EXEC.execute(new XMLValiddator(files[i], i));
|