From: <sha...@us...> - 2013-03-26 07:34:12
|
Revision: 18339 http://sourceforge.net/p/exist/code/18339 Author: shabanovd Date: 2013-03-26 07:34:06 +0000 (Tue, 26 Mar 2013) Log Message: ----------- [ignore] review Modified Paths: -------------- trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTS_case.java trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTStoJUnit.java trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTestCase.java trunk/eXist/test/src/org/exist/w3c/tests/TestCase.java trunk/eXist/test/src/org/exist/xquery/xqts/QT3TS_case.java trunk/eXist/test/src/org/exist/xquery/xqts/XQTS_case.java Modified: trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTS_case.java =================================================================== --- trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTS_case.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTS_case.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -42,10 +42,10 @@ import org.exist.storage.BrokerPool; import org.exist.storage.DBBroker; import org.exist.w3c.tests.TestCase; +import org.exist.xmldb.XmldbURI; import org.exist.xquery.XPathException; import org.exist.xquery.XQueryContext; import org.exist.xquery.value.Sequence; -import org.junit.Before; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -67,19 +67,6 @@ } - @Before - public void setUp() throws Exception { - synchronized (database) { - if (testCollection == null) { - loadTS(); -// testCollection = DatabaseManager.getCollection("xmldb:exist:///db/XQTS", "admin", ""); -// if (testCollection == null) { -// Assert.fail("There is no Test Suite data at database"); -// } - } - } - } - protected void testCase(String inputURL, String xslURL, String outputURL, String expectedError) throws Exception { // String input = loadFile(XSLTS_folder+"TestInputs/"+inputURL, false); // String stylesheet = loadFile(XSLTS_folder+"TestInputs/"+xslURL, true); @@ -95,13 +82,13 @@ XQueryContext context; // XQuery xquery; // - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); // xquery = broker.getXQueryService(); // // broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); // // context = xquery.newContext(AccessContext.TEST); - context = new XSLContext(pool); + context = new XSLContext(db); // // } catch (Exception e) { // Assert.fail(e.getMessage()); @@ -123,7 +110,7 @@ // Sequence result = xquery.execute(compiled, null); TransformerFactoryImpl factory = new TransformerFactoryImpl(); - factory.setBrokerPool(pool); + factory.setBrokerPool(db); Templates templates = factory.newTemplates( new SourceImpl( @@ -174,7 +161,7 @@ Assert.fail("expected error is "+expectedError+", get "+error+" ["+e.getMessage()+"]"); } } finally { - pool.release(broker); + db.release(broker); } // StringBuilder content = new StringBuilder(); @@ -230,40 +217,44 @@ } else { // Open the file and then get a channel from the stream FileInputStream fis = new FileInputStream(file); - FileChannel fc = fis.getChannel(); - - // Get the file's size and then map it into memory - int sz = (int)fc.size(); - MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); - - // Charset and decoder for ISO-8859-15 - Charset charset = Charset.forName("ISO-8859-15"); - CharsetDecoder decoder = charset.newDecoder(); - - // Decode the file into a char buffer - CharBuffer cb = decoder.decode(bb); - - result = cb.toString(); - //TODO: rewrite to handle <?xml*?> - if (result.startsWith("<?xml ")) { - int endAt = result.indexOf("?>"); - result = result.substring(endAt+2); + try { + FileChannel fc = fis.getChannel(); + + // Get the file's size and then map it into memory + int sz = (int)fc.size(); + MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); + + // Charset and decoder for ISO-8859-15 + Charset charset = Charset.forName("ISO-8859-15"); + CharsetDecoder decoder = charset.newDecoder(); + + // Decode the file into a char buffer + CharBuffer cb = decoder.decode(bb); + + result = cb.toString(); + //TODO: rewrite to handle <?xml*?> + if (result.startsWith("<?xml ")) { + int endAt = result.indexOf("?>"); + result = result.substring(endAt+2); + } + + //XXX: rethink: prexslt query processing + if (incapsulate) { + result = result.replaceAll("\\{", "\\{\\{"); + result = result.replaceAll("\\}", "\\}\\}"); + } + + // Close the channel and the stream + fc.close(); + } finally { + fis.close(); } - - //XXX: rethink: prexslt query processing - if (incapsulate) { - result = result.replaceAll("\\{", "\\{\\{"); - result = result.replaceAll("\\}", "\\}\\}"); - } - - // Close the channel and the stream - fc.close(); } return result; } @Override - protected String getCollection() { - return "/db/XQTS"; + protected XmldbURI getCollection() { + return XmldbURI.create("/db/XSLTS"); } } Modified: trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTStoJUnit.java =================================================================== --- trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTStoJUnit.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTStoJUnit.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -49,11 +49,11 @@ private static final String NAME = "name"; - private static final String INPUT = "input"; +// private static final String INPUT = "input"; private static final String STYLESHEET = "stylesheet"; private static final String SOURCE_DOCUMENT = "source-document"; - private static final String OUTPUT = "output"; +// private static final String OUTPUT = "output"; private static final String RESULT_DOCUMENT = "result-document"; private static final String ERROR = "error"; Modified: trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTestCase.java =================================================================== --- trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTestCase.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/extensions/xslt/test/src/org/exist/xslt/XSLTestCase.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -119,24 +119,28 @@ if (testConf.canRead()) { // Open the file and then get a channel from the stream FileInputStream fis = new FileInputStream(testConf); - FileChannel fc = fis.getChannel(); - - // Get the file's size and then map it into memory - int sz = (int)fc.size(); - MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); - - // Charset and decoder for ISO-8859-15 - Charset charset = Charset.forName("ISO-8859-15"); - CharsetDecoder decoder = charset.newDecoder(); - - // Decode the file into a char buffer - CharBuffer cb = decoder.decode(bb); - - // Perform the search - loadBench(testConf, cb, bench); - - // Close the channel and the stream - fc.close(); + try { + FileChannel fc = fis.getChannel(); + + // Get the file's size and then map it into memory + int sz = (int)fc.size(); + MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); + + // Charset and decoder for ISO-8859-15 + Charset charset = Charset.forName("ISO-8859-15"); + CharsetDecoder decoder = charset.newDecoder(); + + // Decode the file into a char buffer + CharBuffer cb = decoder.decode(bb); + + // Perform the search + loadBench(testConf, cb, bench); + + // Close the channel and the stream + fc.close(); + } finally { + fis.close(); + } } } @@ -149,9 +153,9 @@ int position; Matcher lm = linePattern.matcher(cb); // Line matcher - int lines = 0; +// int lines = 0; while (lm.find()) { - lines++; +// lines++; CharSequence cs = lm.group(); // The current line String str = cs.toString(); @@ -476,32 +480,36 @@ } else { // Open the file and then get a channel from the stream FileInputStream fis = new FileInputStream(file); - FileChannel fc = fis.getChannel(); - - // Get the file's size and then map it into memory - int sz = (int)fc.size(); - MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); - - // Charset and decoder for ISO-8859-15 - Charset charset = Charset.forName("ISO-8859-15"); - CharsetDecoder decoder = charset.newDecoder(); - - // Decode the file into a char buffer - CharBuffer cb = decoder.decode(bb); - - result = cb.toString(); - //TODO: rewrite to handle <?xml*?> - if (result.startsWith("<?xml version=\"1.0\"?>")) - result = result.substring("<?xml version=\"1.0\"?>".length()); - if (result.startsWith("<?xml version=\"1.0\" encoding=\"utf-8\"?>")) - result = result.substring("<?xml version=\"1.0\" encoding=\"utf-8\"?>".length()); - - //XXX: rethink: prexslt query processing -// result = result.replaceAll("{", "{{"); -// result = result.replaceAll("}", "}}"); - - // Close the channel and the stream - fc.close(); + try { + FileChannel fc = fis.getChannel(); + + // Get the file's size and then map it into memory + int sz = (int)fc.size(); + MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); + + // Charset and decoder for ISO-8859-15 + Charset charset = Charset.forName("ISO-8859-15"); + CharsetDecoder decoder = charset.newDecoder(); + + // Decode the file into a char buffer + CharBuffer cb = decoder.decode(bb); + + result = cb.toString(); + //TODO: rewrite to handle <?xml*?> + if (result.startsWith("<?xml version=\"1.0\"?>")) + result = result.substring("<?xml version=\"1.0\"?>".length()); + if (result.startsWith("<?xml version=\"1.0\" encoding=\"utf-8\"?>")) + result = result.substring("<?xml version=\"1.0\" encoding=\"utf-8\"?>".length()); + + //XXX: rethink: prexslt query processing +// result = result.replaceAll("{", "{{"); +// result = result.replaceAll("}", "}}"); + + // Close the channel and the stream + fc.close(); + } finally { + fis.close(); + } } return result; } Modified: trunk/eXist/test/src/org/exist/w3c/tests/TestCase.java =================================================================== --- trunk/eXist/test/src/org/exist/w3c/tests/TestCase.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/test/src/org/exist/w3c/tests/TestCase.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -40,12 +40,15 @@ import org.custommonkey.xmlunit.Diff; import org.exist.Namespaces; +import org.exist.collections.Collection; import org.exist.dom.NodeProxy; import org.exist.memtree.NodeImpl; import org.exist.memtree.SAXAdapter; import org.exist.security.Subject; import org.exist.storage.BrokerPool; +import org.exist.storage.DBBroker; import org.exist.storage.serializers.EXistOutputKeys; +import org.exist.util.Configuration; import org.exist.xmldb.LocalCollection; import org.exist.xmldb.LocalXMLResource; import org.exist.xmldb.XmldbURI; @@ -62,8 +65,6 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -import org.xmldb.api.DatabaseManager; -import org.xmldb.api.base.Collection; import org.xmldb.api.base.ErrorCodes; import org.xmldb.api.base.Resource; import org.xmldb.api.base.XMLDBException; @@ -74,66 +75,24 @@ */ public abstract class TestCase { - public static org.exist.start.Main database = null; - private static int inUse = 0; - public static Collection testCollection = null; - - public static BrokerPool pool = null; - - private static Thread shutdowner = null; - + protected static BrokerPool db = null; + protected static DBBroker broker = null; + protected static Collection testCollection = null; + public static final String testLocation = "test/external/"; - static class Shutdowner implements Runnable { - - public void run() { - try { - while (true) { - Thread.sleep(10 * 1000); - - if (inUse == 0) { - //double check - Thread.sleep(10 * 1000); - - if (inUse == 0) { - database.shutdown(); - - System.out.println("database was shutdown"); - database = null; - } - } - } - } catch (InterruptedException e) { - } - } - - } - @BeforeClass public static void setUpBeforeClass() throws Exception { // System.out.println("setUpBeforeClass ENTERED"); - try { - if (database == null) { - System.out.println("Start up database..."); - database = new org.exist.start.Main("jetty"); - database.run(new String[] { "jetty" }); -// testCollection = DatabaseManager.getCollection("xmldb:exist:///db/XQTS", "admin", ""); + Configuration configuration = new Configuration(); + BrokerPool.configure(1, 10, configuration); - if (shutdowner == null) { - shutdowner = new Thread(new Shutdowner()); - shutdowner.start(); - } - - pool = BrokerPool.getInstance(); - System.out.println("Database ready."); - } - synchronized (database) { - inUse++; - } - } catch (Exception e) { - e.printStackTrace(); - } + db = BrokerPool.getInstance(); + + broker = db.get(db.getSecurityManager().getSystemSubject()); + Assert.assertNotNull(broker); + // System.out.println("setUpBeforeClass PASSED"); } @@ -141,9 +100,10 @@ @AfterClass public static void tearDownAfterClass() throws Exception { - synchronized (database) { - inUse--; - } +// System.out.println("tearDownAfterClass ENTERED"); + + db.release(broker); + // System.out.println("tearDownAfterClass PASSED"); } @@ -154,14 +114,14 @@ public void setUp() throws Exception { // System.out.println("setUp ENTERED"); if (testCollection == null) { - synchronized (database) { + synchronized (db) { if (testCollection == null) { - testCollection = DatabaseManager.getCollection("xmldb:exist://"+getCollection(), "admin", ""); + testCollection = broker.getCollection(getCollection()); if (testCollection == null) { System.out.println("setUp no TS data"); loadTS(); System.out.println("setUp checking TS data"); - testCollection = DatabaseManager.getCollection("xmldb:exist://"+getCollection(), "admin", ""); + testCollection = broker.getCollection(getCollection()); if (testCollection == null) { Assert.fail("There is no Test Suite data at database"); } @@ -172,7 +132,7 @@ // System.out.println("setUp PASSED"); } - protected abstract String getCollection(); + protected abstract XmldbURI getCollection(); /** * @throws java.lang.Exception @@ -372,12 +332,12 @@ LocalXMLResource res = null; if (r instanceof NodeProxy) { NodeProxy p = (NodeProxy) r; - res = new LocalXMLResource(user, pool, collection, p); + res = new LocalXMLResource(user, db, collection, p); } else if (r instanceof Node) { - res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI); + res = new LocalXMLResource(user, db, collection, XmldbURI.EMPTY_URI); res.setContentAsDOM((Node)r); } else if (r instanceof AtomicValue) { - res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI); + res = new LocalXMLResource(user, db, collection, XmldbURI.EMPTY_URI); res.setContent(r); } else if (r instanceof LocalXMLResource) res = (LocalXMLResource) r; Modified: trunk/eXist/test/src/org/exist/xquery/xqts/QT3TS_case.java =================================================================== --- trunk/eXist/test/src/org/exist/xquery/xqts/QT3TS_case.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/test/src/org/exist/xquery/xqts/QT3TS_case.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -33,7 +33,6 @@ import org.exist.storage.DBBroker; import org.exist.util.serializer.SAXSerializer; import org.exist.w3c.tests.TestCase; -import org.exist.xmldb.XQueryService; import org.exist.xmldb.XmldbURI; import org.exist.xquery.CompiledXQuery; import org.exist.xquery.Variable; @@ -48,9 +47,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import org.xmldb.api.base.ResourceSet; -import org.xmldb.api.base.XMLDBException; -import org.xmldb.api.modules.XMLResource; /** * @author <a href="mailto:sha...@gm...">Dmitriy Shabanov</a> @@ -82,7 +78,7 @@ XQuery xquery = null; try { - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); xquery = broker.getXQueryService(); broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); @@ -92,7 +88,7 @@ return xquery.execute(query, null, AccessContext.TEST); } finally { - pool.release(broker); + db.release(broker); } } @@ -101,7 +97,7 @@ DBBroker broker = null; try { - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); XQuery xquery = broker.getXQueryService(); broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); @@ -142,7 +138,7 @@ } catch (Exception e) { e.printStackTrace(); } finally { - pool.release(broker); + db.release(broker); } return enviroments; } @@ -152,7 +148,7 @@ DBBroker broker = null; try { - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); XQuery xquery = broker.getXQueryService(); broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); @@ -196,7 +192,7 @@ } catch (Exception e) { e.printStackTrace(); } finally { - pool.release(broker); + db.release(broker); } return enviroment; } @@ -209,15 +205,13 @@ Sequence result = null; XQuery xquery = null; - try { - XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0"); - +// try { Set<String> extectedError = new HashSet<String>(); try { - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); xquery = broker.getXQueryService(); - final XQueryContext context = new XQueryContext(pool, AccessContext.TEST); + final XQueryContext context = new XQueryContext(db, AccessContext.TEST); broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); @@ -226,11 +220,13 @@ "let $tc := $testCases//qt:test-case[@name eq \""+tcName+"\"]\n"+ "return $tc"; - ResourceSet results = service.query(query); + XQuery xqs = broker.getXQueryService(); + + Sequence results = xqs.execute(query, null, AccessContext.TEST); - Assert.assertFalse("", results.getSize() != 1); + Assert.assertFalse("", !results.isEmpty()); - ElementImpl TC = (ElementImpl) ((XMLResource) results.getResource(0)).getContentAsDOM(); + ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode(); Sequence contextSequence = null; @@ -357,11 +353,11 @@ e.printStackTrace(); Assert.fail(e.getMessage()); } finally { - pool.release(broker); + db.release(broker); } - } catch (XMLDBException e) { - Assert.fail(e.toString()); - } +// } catch (XMLDBException e) { +// Assert.fail(e.toString()); +// } } private void possibleErrors(ElementImpl el, Set<String> extectedError) { @@ -601,7 +597,7 @@ private String toString(Item item) throws SAXException { StringWriter writer = new StringWriter(); SAXSerializer serializer = new SAXSerializer(writer, properties); - item.toSAX(pool.getActiveBroker(), serializer, properties); + item.toSAX(broker, serializer, properties); String serialized = writer.toString(); //System.out.println(serialized); return serialized; @@ -649,7 +645,7 @@ @Override - protected String getCollection() { - return QT3_URI.toString(); + protected XmldbURI getCollection() { + return QT3_URI; } } Modified: trunk/eXist/test/src/org/exist/xquery/xqts/XQTS_case.java =================================================================== --- trunk/eXist/test/src/org/exist/xquery/xqts/XQTS_case.java 2013-03-26 05:28:31 UTC (rev 18338) +++ trunk/eXist/test/src/org/exist/xquery/xqts/XQTS_case.java 2013-03-26 07:34:06 UTC (rev 18339) @@ -137,7 +137,7 @@ XQuery xquery = null; try { - broker = pool.get(pool.getSecurityManager().getSystemSubject()); + broker = db.get(db.getSecurityManager().getSystemSubject()); broker.getConfiguration().setProperty( XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true); xquery = broker.getXQueryService(); @@ -153,7 +153,7 @@ Assert.assertFalse("", !results.hasOne()); - ElementImpl TC = (ElementImpl) results.itemAt(0); + ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode(); //collect test case information String folder = ""; @@ -413,7 +413,7 @@ } catch (Exception e) { Assert.fail(e.toString()); } finally { - pool.release(broker); + db.release(broker); } } @@ -460,7 +460,7 @@ } @Override - protected String getCollection() { - return XQTS_URI.toString(); + protected XmldbURI getCollection() { + return XQTS_URI; } } |