Added a single text to maven.
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/1ac6b407 Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/1ac6b407 Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/1ac6b407 Branch: refs/heads/site Commit: 1ac6b40764fcefec915adf33690f02ad0578e407 Parents: 131096b Author: Preston Carman <[email protected]> Authored: Mon Aug 18 16:01:17 2014 -0700 Committer: Preston Carman <[email protected]> Committed: Mon Aug 18 16:01:17 2014 -0700 ---------------------------------------------------------------------- pom.xml | 4 +- .../vxquery/xtest/AbstractTestCaseFactory.java | 198 +++++++++++++++++++ .../apache/vxquery/xtest/TestCaseFactory.java | 196 +----------------- .../org/apache/vxquery/xtest/TestRunner.java | 168 ++++++++++++++++ .../apache/vxquery/xtest/TestRunnerFactory.java | 143 +------------- .../java/org/apache/vxquery/xtest/XTest.java | 2 +- .../vxquery/xtest/JUnitTestCaseFactory.java | 43 ++++ .../org/apache/vxquery/xtest/VXQueryTest.java | 50 ++++- .../ExpectedTestResults/Simple/add.txt | 1 + .../ExpectedTestResults/Simple/list.txt | 3 + .../test/resources/Queries/XQuery/Simple/add.xq | 18 ++ .../resources/Queries/XQuery/Simple/list.xq | 18 ++ .../src/test/resources/VXQuerySingleCatalog.xml | 96 +++++++++ .../src/test/resources/cat/SingleQuery.xml | 28 +++ 14 files changed, 630 insertions(+), 338 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 6dc0c26..ed391b6 100644 --- a/pom.xml +++ b/pom.xml @@ -536,9 +536,9 @@ <modules> <module>vxquery-core</module> - <module>vxquery-xtest</module> - <module>vxquery-benchmark</module> <module>vxquery-server</module> <module>vxquery-cli</module> + <module>vxquery-xtest</module> + <module>vxquery-benchmark</module> </modules> </project> http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java new file mode 100644 index 0000000..4d8f0fb --- /dev/null +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java @@ -0,0 +1,198 @@ +package org.apache.vxquery.xtest; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Pattern; + +import javax.xml.namespace.QName; + +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +public abstract class AbstractTestCaseFactory { + public TestConfiguration tConfig; + public File catalog; + public String baseDirectory; + public TestCase tc; + public Pattern include; + public Pattern exclude; + public XTestOptions opts; + public String nextVariable; + public boolean expectedError; + public boolean outputFile; + public int currPathLen; + public int count; + + public AbstractTestCaseFactory(XTestOptions opts) { + System.err.println("opts.catalog: " + opts.catalog); + this.catalog = new File(opts.catalog); + this.baseDirectory = this.catalog.getParent(); + tConfig = new TestConfiguration(); + tConfig.options = opts; + this.opts = opts; + if (opts.include != null) { + this.include = Pattern.compile(opts.include); + } + if (opts.exclude != null) { + this.exclude = Pattern.compile(opts.exclude); + } + try { + currPathLen = new File(".").getCanonicalPath().length(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public int process() throws Exception { + count = 0; + XMLReader parser = XMLReaderFactory.createXMLReader(); + nextVariable = null; + Handler handler = new Handler(); + parser.setContentHandler(handler); + parser.setEntityResolver(new EntityResolver() { + @Override + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + URL url = new URL(systemId); + return new InputSource(baseDirectory + + new File(url.getFile()).getCanonicalPath().substring(currPathLen)); + } + }); + parser.parse(new InputSource(new FileReader(catalog))); + return count; + } + + protected abstract void submit(TestCase tc); + + protected class Handler implements ContentHandler { + StringBuilder buffer = null; + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + if (buffer == null) { + buffer = new StringBuilder(); + } + buffer.append(ch, start, length); + } + + private void flushChars() { + if (buffer == null) { + return; + } + String str = buffer.toString(); + buffer = null; + if (nextVariable != null) { + if (tConfig.sourceFileMap.get(str) == null) { + System.err.println(tc.getXQueryFile()); + System.err.println(str); + } + tc.addExternalVariableBinding(new QName(nextVariable), tConfig.sourceFileMap.get(str)); + } else if (expectedError) { + tc.setExpectedError(str); + } else if (outputFile) { + ExpectedResult er = new ExpectedResult(str); + tc.addExpectedResult(er); + } + } + + @Override + public void endDocument() throws SAXException { + flushChars(); + } + + @Override + public void endElement(String uri, String localName, String name) throws SAXException { + flushChars(); + if ("test-case".equals(localName)) { + if (tc != null) { + submit(tc); + tc = null; + } + } else if ("input-file".equals(localName)) { + nextVariable = null; + } else if ("output-file".equals(localName)) { + outputFile = false; + } else if ("expected-error".equals(localName)) { + expectedError = false; + } + } + + @Override + public void endPrefixMapping(String prefix) throws SAXException { + } + + @Override + public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { + } + + @Override + public void processingInstruction(String target, String data) throws SAXException { + flushChars(); + } + + @Override + public void setDocumentLocator(Locator locator) { + flushChars(); + } + + @Override + public void skippedEntity(String name) throws SAXException { + flushChars(); + } + + @Override + public void startDocument() throws SAXException { + flushChars(); + } + + @Override + public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { + flushChars(); + try { + if ("query".equals(localName)) { + if (tc != null) { + String tcName = atts.getValue("", "name"); + tc.setName(tcName); + } + } else if ("expected-error".equals(localName)) { + if (tc != null) { + expectedError = true; + } + } else if ("input-file".equals(localName)) { + nextVariable = atts.getValue("", "variable"); + } else if ("output-file".equals(localName)) { + outputFile = true; + } else if ("test-case".equals(localName)) { + tc = new TestCase(tConfig); + String folder = atts.getValue("", "FilePath"); + tc.setFolder(folder); + } else if ("source".equals(localName)) { + String id = atts.getValue("", "ID"); + File srcFile = new File(tConfig.testRoot, atts.getValue("", "FileName")); + tConfig.sourceFileMap.put(id, srcFile); + } else if ("test-suite".equals(localName)) { + tConfig.testRoot = new File(new File(baseDirectory).getCanonicalFile(), atts.getValue("", + "SourceOffsetPath")); + tConfig.xqueryQueryOffsetPath = new File(tConfig.testRoot, atts.getValue("", + "XQueryQueryOffsetPath")); + tConfig.resultOffsetPath = new File(tConfig.testRoot, atts.getValue("", "ResultOffsetPath")); + tConfig.xqueryFileExtension = atts.getValue("", "XQueryFileExtension"); + tConfig.xqueryxFileExtension = atts.getValue("", "XQueryXFileExtension"); + } + } catch (Exception e) { + throw new SAXException(e); + } + } + + @Override + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestCaseFactory.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestCaseFactory.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestCaseFactory.java index cadd5a7..f3980db 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestCaseFactory.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestCaseFactory.java @@ -14,80 +14,20 @@ */ package org.apache.vxquery.xtest; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.net.URL; import java.util.concurrent.ExecutorService; -import java.util.regex.Pattern; -import javax.xml.namespace.QName; +public class TestCaseFactory extends AbstractTestCaseFactory { -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; + public TestRunnerFactory trf; + public ExecutorService eSvc; -public class TestCaseFactory { - private TestConfiguration tConfig; - private File catalog; - private String baseDirectory; - private TestRunnerFactory trf; - private ExecutorService eSvc; - private TestCase tc; - private Pattern include; - private Pattern exclude; - private XTestOptions opts; - - private String nextVariable; - private boolean expectedError; - private boolean outputFile; - private int currPathLen; - int count; - - public TestCaseFactory(String catalog, TestRunnerFactory trf, ExecutorService eSvc, XTestOptions opts) { - this.catalog = new File(catalog); - this.baseDirectory = this.catalog.getParent(); + public TestCaseFactory(TestRunnerFactory trf, ExecutorService eSvc, XTestOptions opts) { + super(opts); this.trf = trf; - tConfig = new TestConfiguration(); - tConfig.options = opts; this.eSvc = eSvc; - this.opts = opts; - if (opts.include != null) { - this.include = Pattern.compile(opts.include); - } - if (opts.exclude != null) { - this.exclude = Pattern.compile(opts.exclude); - } - try { - currPathLen = new File(".").getCanonicalPath().length(); - } catch (IOException e) { - e.printStackTrace(); - } } - public int process() throws Exception { - count = 0; - XMLReader parser = XMLReaderFactory.createXMLReader(); - nextVariable = null; - Handler handler = new Handler(); - parser.setContentHandler(handler); - parser.setEntityResolver(new EntityResolver() { - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - URL url = new URL(systemId); - return new InputSource(baseDirectory + new File(url.getFile()).getCanonicalPath().substring(currPathLen)); - } - }); - parser.parse(new InputSource(new FileReader(catalog))); - return count; - } - - private void submit(TestCase tc) { + protected void submit(TestCase tc) { boolean toSubmit = include == null || include.matcher(tc.getXQueryDisplayName()).find(); toSubmit = toSubmit && (exclude == null || !exclude.matcher(tc.getXQueryDisplayName()).find()); if (toSubmit) { @@ -99,128 +39,4 @@ public class TestCaseFactory { } } - private class Handler implements ContentHandler { - StringBuilder buffer = null; - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - if (buffer == null) { - buffer = new StringBuilder(); - } - buffer.append(ch, start, length); - } - - private void flushChars() { - if (buffer == null) { - return; - } - String str = buffer.toString(); - buffer = null; - if (nextVariable != null) { - if (tConfig.sourceFileMap.get(str) == null) { - System.err.println(tc.getXQueryFile()); - System.err.println(str); - } - tc.addExternalVariableBinding(new QName(nextVariable), tConfig.sourceFileMap.get(str)); - } else if (expectedError) { - tc.setExpectedError(str); - } else if (outputFile) { - ExpectedResult er = new ExpectedResult(str); - tc.addExpectedResult(er); - } - } - - @Override - public void endDocument() throws SAXException { - flushChars(); - } - - @Override - public void endElement(String uri, String localName, String name) throws SAXException { - flushChars(); - if ("test-case".equals(localName)) { - if (tc != null) { - submit(tc); - tc = null; - } - } else if ("input-file".equals(localName)) { - nextVariable = null; - } else if ("output-file".equals(localName)) { - outputFile = false; - } else if ("expected-error".equals(localName)) { - expectedError = false; - } - } - - @Override - public void endPrefixMapping(String prefix) throws SAXException { - } - - @Override - public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { - } - - @Override - public void processingInstruction(String target, String data) throws SAXException { - flushChars(); - } - - @Override - public void setDocumentLocator(Locator locator) { - flushChars(); - } - - @Override - public void skippedEntity(String name) throws SAXException { - flushChars(); - } - - @Override - public void startDocument() throws SAXException { - flushChars(); - } - - @Override - public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { - flushChars(); - try { - if ("query".equals(localName)) { - if (tc != null) { - String tcName = atts.getValue("", "name"); - tc.setName(tcName); - } - } else if ("expected-error".equals(localName)) { - if (tc != null) { - expectedError = true; - } - } else if ("input-file".equals(localName)) { - nextVariable = atts.getValue("", "variable"); - } else if ("output-file".equals(localName)) { - outputFile = true; - } else if ("test-case".equals(localName)) { - tc = new TestCase(tConfig); - String folder = atts.getValue("", "FilePath"); - tc.setFolder(folder); - } else if ("source".equals(localName)) { - String id = atts.getValue("", "ID"); - File srcFile = new File(tConfig.testRoot, atts.getValue("", "FileName")); - tConfig.sourceFileMap.put(id, srcFile); - } else if ("test-suite".equals(localName)) { - tConfig.testRoot = new File(new File(baseDirectory).getCanonicalFile(), atts.getValue("", - "SourceOffsetPath")); - tConfig.xqueryQueryOffsetPath = new File(tConfig.testRoot, atts.getValue("", - "XQueryQueryOffsetPath")); - tConfig.resultOffsetPath = new File(tConfig.testRoot, atts.getValue("", "ResultOffsetPath")); - tConfig.xqueryFileExtension = atts.getValue("", "XQueryFileExtension"); - tConfig.xqueryxFileExtension = atts.getValue("", "XQueryXFileExtension"); - } - } catch (Exception e) { - throw new SAXException(e); - } - } - - @Override - public void startPrefixMapping(String prefix, String uri) throws SAXException { - } - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java new file mode 100644 index 0000000..9c0bc64 --- /dev/null +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunner.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.vxquery.xtest; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.ByteBuffer; +import java.util.EnumSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.vxquery.compiler.CompilerControlBlock; +import org.apache.vxquery.compiler.algebricks.VXQueryGlobalDataFactory; +import org.apache.vxquery.context.DynamicContext; +import org.apache.vxquery.context.DynamicContextImpl; +import org.apache.vxquery.context.RootStaticContextImpl; +import org.apache.vxquery.context.StaticContextImpl; +import org.apache.vxquery.exceptions.ErrorCode; +import org.apache.vxquery.exceptions.SystemException; +import org.apache.vxquery.result.ResultUtils; +import org.apache.vxquery.xmlquery.query.XMLQueryCompiler; + +import edu.uci.ics.hyracks.api.client.HyracksConnection; +import edu.uci.ics.hyracks.api.client.IHyracksClientConnection; +import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor; +import edu.uci.ics.hyracks.api.dataset.IHyracksDataset; +import edu.uci.ics.hyracks.api.dataset.IHyracksDatasetReader; +import edu.uci.ics.hyracks.api.dataset.ResultSetId; +import edu.uci.ics.hyracks.api.exceptions.HyracksException; +import edu.uci.ics.hyracks.api.job.JobFlag; +import edu.uci.ics.hyracks.api.job.JobId; +import edu.uci.ics.hyracks.api.job.JobSpecification; +import edu.uci.ics.hyracks.client.dataset.HyracksDataset; +import edu.uci.ics.hyracks.control.cc.ClusterControllerService; +import edu.uci.ics.hyracks.control.common.controllers.CCConfig; +import edu.uci.ics.hyracks.control.common.controllers.NCConfig; +import edu.uci.ics.hyracks.control.nc.NodeControllerService; +import edu.uci.ics.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor; + +public class TestRunner { + private static final int FRAME_SIZE = 65536; + + private static final Pattern EMBEDDED_SYSERROR_PATTERN = Pattern + .compile("org\\.apache\\.vxquery\\.exceptions\\.SystemException: (\\p{javaUpperCase}{4}\\d{4})"); + + private XTestOptions opts; + private ClusterControllerService cc; + private NodeControllerService nc1; + private IHyracksClientConnection hcc; + private IHyracksDataset hds; + + public TestRunner(XTestOptions opts) throws Exception { + this.opts = opts; + } + + public void open() throws Exception { + CCConfig ccConfig = new CCConfig(); + ccConfig.clientNetIpAddress = "127.0.0.1"; + ccConfig.clientNetPort = 39000; + ccConfig.clusterNetIpAddress = "127.0.0.1"; + ccConfig.clusterNetPort = 39001; + ccConfig.profileDumpPeriod = 10000; + File outDir = new File("target/ClusterController"); + outDir.mkdirs(); + File ccRoot = File.createTempFile(TestRunner.class.getName(), ".data", outDir); + ccRoot.delete(); + ccRoot.mkdir(); + ccConfig.ccRoot = ccRoot.getAbsolutePath(); + cc = new ClusterControllerService(ccConfig); + cc.start(); + + NCConfig ncConfig1 = new NCConfig(); + ncConfig1.ccHost = "localhost"; + ncConfig1.ccPort = 39001; + ncConfig1.clusterNetIPAddress = "127.0.0.1"; + ncConfig1.dataIPAddress = "127.0.0.1"; + ncConfig1.datasetIPAddress = "127.0.0.1"; + ncConfig1.nodeId = "nc1"; + nc1 = new NodeControllerService(ncConfig1); + nc1.start(); + + hcc = new HyracksConnection(ccConfig.clientNetIpAddress, ccConfig.clientNetPort); + } + + public TestCaseResult run(final TestCase testCase) { + TestCaseResult res = new TestCaseResult(testCase); + if (opts.verbose) { + System.err.println("Starting " + testCase.getXQueryDisplayName()); + } + long start = System.currentTimeMillis(); + try { + try { + XMLQueryCompiler compiler = new XMLQueryCompiler(null, new String[] { "nc1" }, FRAME_SIZE); + Reader in = new InputStreamReader(new FileInputStream(testCase.getXQueryFile()), "UTF-8"); + CompilerControlBlock ccb = new CompilerControlBlock(new StaticContextImpl( + RootStaticContextImpl.INSTANCE), new ResultSetId(testCase.getXQueryDisplayName().hashCode()), + testCase.getSourceFileMap()); + compiler.compile(testCase.getXQueryDisplayName(), in, ccb, opts.optimizationLevel); + JobSpecification spec = compiler.getModule().getHyracksJobSpecification(); + + DynamicContext dCtx = new DynamicContextImpl(compiler.getModule().getModuleContext()); + spec.setGlobalJobDataFactory(new VXQueryGlobalDataFactory(dCtx.createFactory())); + + spec.setMaxReattempts(0); + JobId jobId = hcc.startJob(spec, EnumSet.of(JobFlag.PROFILE_RUNTIME)); + + if (hds == null) { + hds = new HyracksDataset(hcc, spec.getFrameSize(), opts.threads); + } + ByteBuffer buffer = ByteBuffer.allocate(spec.getFrameSize()); + IHyracksDatasetReader reader = hds.createReader(jobId, ccb.getResultSetId()); + IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor(spec.getFrameSize()); + buffer.clear(); + res.result = ""; + while (reader.read(buffer) > 0) { + buffer.clear(); + res.result += ResultUtils.getStringFromBuffer(buffer, frameTupleAccessor); + } + res.result.trim(); + hcc.waitForCompletion(jobId); + } catch (HyracksException e) { + Throwable t = e; + while (t.getCause() != null) { + t = t.getCause(); + } + Matcher m = EMBEDDED_SYSERROR_PATTERN.matcher(t.getMessage()); + if (m.find()) { + String eCode = m.group(1); + throw new SystemException(ErrorCode.valueOf(eCode), e); + } + throw e; + } + } catch (SystemException e) { + res.error = e; + } catch (Throwable e) { + res.error = e; + } finally { + try { + res.compare(); + } catch (Exception e) { + System.err.println("Framework error"); + e.printStackTrace(); + } + long end = System.currentTimeMillis(); + res.time = end - start; + } + return res; + } + + public void close() throws Exception { + nc1.stop(); + cc.stop(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java index 6b3fb4b..1910f84 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java @@ -14,87 +14,19 @@ */ package org.apache.vxquery.xtest; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collection; -import java.util.EnumSet; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.vxquery.compiler.CompilerControlBlock; -import org.apache.vxquery.compiler.algebricks.VXQueryGlobalDataFactory; -import org.apache.vxquery.context.DynamicContext; -import org.apache.vxquery.context.DynamicContextImpl; -import org.apache.vxquery.context.RootStaticContextImpl; -import org.apache.vxquery.context.StaticContextImpl; -import org.apache.vxquery.exceptions.ErrorCode; -import org.apache.vxquery.exceptions.SystemException; -import org.apache.vxquery.result.ResultUtils; -import org.apache.vxquery.xmlquery.query.XMLQueryCompiler; - -import edu.uci.ics.hyracks.api.client.HyracksConnection; -import edu.uci.ics.hyracks.api.client.IHyracksClientConnection; -import edu.uci.ics.hyracks.api.comm.IFrameTupleAccessor; -import edu.uci.ics.hyracks.api.dataset.IHyracksDataset; -import edu.uci.ics.hyracks.api.dataset.IHyracksDatasetReader; -import edu.uci.ics.hyracks.api.dataset.ResultSetId; -import edu.uci.ics.hyracks.api.exceptions.HyracksException; -import edu.uci.ics.hyracks.api.job.JobFlag; -import edu.uci.ics.hyracks.api.job.JobId; -import edu.uci.ics.hyracks.api.job.JobSpecification; -import edu.uci.ics.hyracks.client.dataset.HyracksDataset; -import edu.uci.ics.hyracks.control.cc.ClusterControllerService; -import edu.uci.ics.hyracks.control.common.controllers.CCConfig; -import edu.uci.ics.hyracks.control.common.controllers.NCConfig; -import edu.uci.ics.hyracks.control.nc.NodeControllerService; -import edu.uci.ics.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor; public class TestRunnerFactory { - private static final Pattern EMBEDDED_SYSERROR_PATTERN = Pattern - .compile("org\\.apache\\.vxquery\\.exceptions\\.SystemException: (\\p{javaUpperCase}{4}\\d{4})"); private List<ResultReporter> reporters; - private XTestOptions opts; - private ClusterControllerService cc; - private NodeControllerService nc1; - private IHyracksClientConnection hcc; - private IHyracksDataset hds; + private TestRunner tr; public TestRunnerFactory(XTestOptions opts) throws Exception { + tr = new TestRunner(opts); + tr.open(); reporters = new ArrayList<ResultReporter>(); - this.opts = opts; - - CCConfig ccConfig = new CCConfig(); - ccConfig.clientNetIpAddress = "127.0.0.1"; - ccConfig.clientNetPort = 39000; - ccConfig.clusterNetIpAddress = "127.0.0.1"; - ccConfig.clusterNetPort = 39001; - ccConfig.profileDumpPeriod = 10000; - File outDir = new File("target/ClusterController"); - outDir.mkdirs(); - File ccRoot = File.createTempFile(TestRunnerFactory.class.getName(), ".data", outDir); - ccRoot.delete(); - ccRoot.mkdir(); - ccConfig.ccRoot = ccRoot.getAbsolutePath(); - cc = new ClusterControllerService(ccConfig); - cc.start(); - - NCConfig ncConfig1 = new NCConfig(); - ncConfig1.ccHost = "localhost"; - ncConfig1.ccPort = 39001; - ncConfig1.clusterNetIPAddress = "127.0.0.1"; - ncConfig1.dataIPAddress = "127.0.0.1"; - ncConfig1.datasetIPAddress = "127.0.0.1"; - ncConfig1.nodeId = "nc1"; - nc1 = new NodeControllerService(ncConfig1); - nc1.start(); - - hcc = new HyracksConnection(ccConfig.clientNetIpAddress, ccConfig.clientNetPort); } public void registerReporter(ResultReporter reporter) { @@ -105,73 +37,13 @@ public class TestRunnerFactory { return new Runnable() { @Override public void run() { - TestCaseResult res = new TestCaseResult(testCase); - if (opts.verbose) { - System.err.println("Starting " + testCase.getXQueryDisplayName()); - } - long start = System.currentTimeMillis(); - try { + TestCaseResult res = tr.run(testCase); + for (ResultReporter r : reporters) { try { - XMLQueryCompiler compiler = new XMLQueryCompiler(null, new String[] { "nc1" }, 65536); - Reader in = new InputStreamReader(new FileInputStream(testCase.getXQueryFile()), "UTF-8"); - CompilerControlBlock ccb = new CompilerControlBlock(new StaticContextImpl( - RootStaticContextImpl.INSTANCE), new ResultSetId(testCase.getXQueryDisplayName() - .hashCode()), testCase.getSourceFileMap()); - compiler.compile(testCase.getXQueryDisplayName(), in, ccb, opts.optimizationLevel); - JobSpecification spec = compiler.getModule().getHyracksJobSpecification(); - - DynamicContext dCtx = new DynamicContextImpl(compiler.getModule().getModuleContext()); - spec.setGlobalJobDataFactory(new VXQueryGlobalDataFactory(dCtx.createFactory())); - - spec.setMaxReattempts(0); - JobId jobId = hcc.startJob(spec, EnumSet.of(JobFlag.PROFILE_RUNTIME)); - - if (hds == null) { - hds = new HyracksDataset(hcc, spec.getFrameSize(), opts.threads); - } - ByteBuffer buffer = ByteBuffer.allocate(spec.getFrameSize()); - IHyracksDatasetReader reader = hds.createReader(jobId, ccb.getResultSetId()); - IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor(spec.getFrameSize()); - buffer.clear(); - res.result = ""; - while (reader.read(buffer) > 0) { - buffer.clear(); - res.result += ResultUtils.getStringFromBuffer(buffer, frameTupleAccessor); - } - res.result.trim(); - hcc.waitForCompletion(jobId); - } catch (HyracksException e) { - Throwable t = e; - while (t.getCause() != null) { - t = t.getCause(); - } - Matcher m = EMBEDDED_SYSERROR_PATTERN.matcher(t.getMessage()); - if (m.find()) { - String eCode = m.group(1); - throw new SystemException(ErrorCode.valueOf(eCode), e); - } - throw e; - } - } catch (SystemException e) { - res.error = e; - } catch (Throwable e) { - res.error = e; - } finally { - try { - res.compare(); + r.reportResult(res); } catch (Exception e) { - System.err.println("Framework error"); e.printStackTrace(); } - long end = System.currentTimeMillis(); - res.time = end - start; - for (ResultReporter r : reporters) { - try { - r.reportResult(res); - } catch (Exception e) { - e.printStackTrace(); - } - } } } }; @@ -182,7 +54,6 @@ public class TestRunnerFactory { } public void close() throws Exception { - nc1.stop(); - cc.stop(); + tr.close(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java index 41040f4..87f0687 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java @@ -78,7 +78,7 @@ public class XTest { }); trf = new TestRunnerFactory(opts); trf.registerReporters(reporters); - TestCaseFactory tcf = new TestCaseFactory(opts.catalog, trf, eSvc, opts); + TestCaseFactory tcf = new TestCaseFactory(trf, eSvc, opts); count = tcf.process(); } http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/JUnitTestCaseFactory.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/JUnitTestCaseFactory.java b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/JUnitTestCaseFactory.java new file mode 100644 index 0000000..337fbd2 --- /dev/null +++ b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/JUnitTestCaseFactory.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.vxquery.xtest; + +import java.util.ArrayList; +import java.util.Collection; + +public class JUnitTestCaseFactory extends AbstractTestCaseFactory { + + private Collection<Object[]> testCases; + + public JUnitTestCaseFactory(XTestOptions opts) { + super(opts); + } + + protected void submit(TestCase tc) { + boolean toSubmit = include == null || include.matcher(tc.getXQueryDisplayName()).find(); + toSubmit = toSubmit && (exclude == null || !exclude.matcher(tc.getXQueryDisplayName()).find()); + if (toSubmit) { + testCases.add(new Object[] { tc }); + ++count; + } + } + + public Collection<Object[]> getList() throws Exception { + testCases = new ArrayList<Object[]>(); + this.process(); + return testCases; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java index 39f4b4f..b9dc37d 100644 --- a/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java +++ b/vxquery-xtest/src/test/java/org/apache/vxquery/xtest/VXQueryTest.java @@ -16,6 +16,8 @@ */ package org.apache.vxquery.xtest; +import static org.junit.Assert.fail; + import java.io.File; import java.util.Collection; @@ -27,23 +29,53 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class VXQueryTest { + private TestCase tc; + private TestRunner tr; + + // private final String CATALOG = "VXQueryCatalog.xml"; + private static String CATALOG = "VXQuerySingleCatalog.xml"; - private static final String PATH_QUERIES = StringUtils.join(new String[] { "Queries", "XQuery" + File.separator }, - File.separator); - private static final String PATH_RESULTS = "ExpectedTestResults" + File.separator; - private static final String PATH_TESTS = "cat" + File.separator; - private static final String PATH_BASE = StringUtils.join( - new String[] { "src", "test", "resources" + File.separator }, File.separator); + private static XTestOptions getOptions() { + XTestOptions opts = new XTestOptions(); + opts.catalog = StringUtils.join(new String[] { "src", "test", "resources", CATALOG }, File.separator); + opts.verbose = true; + return opts; + } @Parameters public static Collection<Object[]> tests() throws Exception { - return null; + JUnitTestCaseFactory jtcf = new JUnitTestCaseFactory(getOptions()); + return jtcf.getList(); } - public VXQueryTest() { + public VXQueryTest(TestCase tc) throws Exception { + this.tc = tc; + System.err.println("Query: " + tc.getXQueryFile()); + tr = new TestRunner(getOptions()); } @Test public void test() throws Exception { + tr.open(); + TestCaseResult result = tr.run(tc); + System.err.println("result.result: " + result.result); + System.err.println("result.report: " + result.report); + System.err.println("result.state: " + result.state); + switch (result.state) { + case EXPECTED_ERROR_GOT_DIFFERENT_ERROR: + case EXPECTED_ERROR_GOT_FAILURE: + case EXPECTED_ERROR_GOT_RESULT: + case EXPECTED_RESULT_GOT_DIFFERENT_RESULT: + case EXPECTED_RESULT_GOT_ERROR: + case EXPECTED_RESULT_GOT_FAILURE: + fail(result.state + " (" + result.time + " ms): " + result.testCase.getXQueryDisplayName()); + break; + case EXPECTED_ERROR_GOT_SAME_ERROR: + case EXPECTED_RESULT_GOT_SAME_RESULT: + break; + case NO_RESULT_FILE: + break; + } + tr.close(); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/add.txt ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/add.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/add.txt new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/add.txt @@ -0,0 +1 @@ +3 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/list.txt ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/list.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/list.txt new file mode 100644 index 0000000..5f5fbe7 --- /dev/null +++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Simple/list.txt @@ -0,0 +1,3 @@ +1 +2 +3 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/add.xq ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/add.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/add.xq new file mode 100644 index 0000000..2b904bd --- /dev/null +++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/add.xq @@ -0,0 +1,18 @@ +(: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. :) + +1+2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/list.xq ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/list.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/list.xq new file mode 100644 index 0000000..f1f6e71 --- /dev/null +++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Simple/list.xq @@ -0,0 +1,18 @@ +(: Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. :) + +(1, 2, 3) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/VXQuerySingleCatalog.xml ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/VXQuerySingleCatalog.xml b/vxquery-xtest/src/test/resources/VXQuerySingleCatalog.xml new file mode 100644 index 0000000..c0fe358 --- /dev/null +++ b/vxquery-xtest/src/test/resources/VXQuerySingleCatalog.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!DOCTYPE test-suite [ + +<!ENTITY AggregatePartition1Queries SYSTEM "cat/AggregatePartition1Queries.xml"> +<!ENTITY AggregatePartition2Queries SYSTEM "cat/AggregatePartition2Queries.xml"> +<!ENTITY AggregatePartition4Queries SYSTEM "cat/AggregatePartition4Queries.xml"> + +<!ENTITY GhcndPartition1Queries SYSTEM "cat/GhcndPartition1Queries.xml"> +<!ENTITY GhcndPartition2Queries SYSTEM "cat/GhcndPartition2Queries.xml"> +<!ENTITY GhcndPartition4Queries SYSTEM "cat/GhcndPartition4Queries.xml"> + +<!ENTITY GhcndRecordsPartition1Queries SYSTEM "cat/GhcndRecordsPartition1Queries.xml"> +<!ENTITY GhcndRecordsPartition2Queries SYSTEM "cat/GhcndRecordsPartition2Queries.xml"> +<!ENTITY GhcndRecordsPartition4Queries SYSTEM "cat/GhcndRecordsPartition4Queries.xml"> + +<!ENTITY GhcndCountPartition1Queries SYSTEM "cat/GhcndCountPartition1Queries.xml"> +<!ENTITY GhcndCountPartition2Queries SYSTEM "cat/GhcndCountPartition2Queries.xml"> +<!ENTITY GhcndCountPartition4Queries SYSTEM "cat/GhcndCountPartition4Queries.xml"> + +<!ENTITY SingleQuery SYSTEM "cat/SingleQuery.xml"> + +]> +<test-suite xmlns="http://www.w3.org/2005/02/query-test-XQTSCatalog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + CatalogDesignDate="2014-04-01" + version="0.0.1" + SourceOffsetPath="./" + ResultOffsetPath="ExpectedTestResults/" + XQueryQueryOffsetPath="Queries/XQuery/" + XQueryXQueryOffsetPath="Queries/XQueryX/" + XQueryFileExtension=".xq" + XQueryXFileExtension=".xqx" + xsi:schemaLocation="http://www.w3.org/2005/02/query-test-XQTSCatalog XQTSCatalog.xsd"> + <test-suite-info> + <title>VXQuery Test Suite</title> + <description> + Test Suite for VXQuery. + </description> + </test-suite-info> + <sources> + <source ID="VXQueryCatalog" FileName="VXQueryCatalog.xml" Creator="VXQuery team"> + <description last-mod="2014-04-02">VXQuery Test Suite Catalog</description> + </source> + <source ID="ghcnd" FileName="TestSources/ghcnd" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_half_1" FileName="TestSources/ghcnd/half_1" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_half_2" FileName="TestSources/ghcnd/half_2" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_quarter_1" FileName="TestSources/ghcnd/half_1/quarter_1" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_quarter_2" FileName="TestSources/ghcnd/half_1/quarter_2" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_quarter_3" FileName="TestSources/ghcnd/half_2/quarter_3" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + <source ID="ghcnd_quarter_4" FileName="TestSources/ghcnd/half_2/quarter_4" Creator="Preston Carman"> + <description last-mod="2014-04-02">Collection of files</description> + </source> + </sources> + <test-group name="SingleQuery" featureOwner="Preston Carman"> + <GroupInfo> + <title>Single Query</title> + <description/> + </GroupInfo> + <test-group name="SingleTest" featureOwner="Preston Carman"> + <GroupInfo> + <title>Single Test</title> + <description/> + </GroupInfo> + &SingleQuery; + </test-group> + </test-group> +</test-suite> http://git-wip-us.apache.org/repos/asf/vxquery/blob/1ac6b407/vxquery-xtest/src/test/resources/cat/SingleQuery.xml ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/test/resources/cat/SingleQuery.xml b/vxquery-xtest/src/test/resources/cat/SingleQuery.xml new file mode 100644 index 0000000..19011b7 --- /dev/null +++ b/vxquery-xtest/src/test/resources/cat/SingleQuery.xml @@ -0,0 +1,28 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<test-group xmlns="http://www.w3.org/2005/02/query-test-XQTSCatalog" name="AggregatePartition1Queries" featureOwner="VXQuery"> + <GroupInfo> + <title>Single Test</title> + <description/> + </GroupInfo> + <test-case name="simple-add" FilePath="Simple/" Creator="Preston Carman"> + <description>Adds two numbers.</description> + <query name="add" date="2014-08-18"/> + <output-file compare="Text">add.txt</output-file> + </test-case> +</test-group> \ No newline at end of file
