Merged asterix_lsm_stabilization upto r1547
git-svn-id: https://asterixdb.googlecode.com/svn/trunk/asterix@1622 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-test-framework/pom.xml b/asterix-test-framework/pom.xml
new file mode 100755
index 0000000..4042066
--- /dev/null
+++ b/asterix-test-framework/pom.xml
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>asterix</artifactId>
+ <groupId>edu.uci.ics.asterix</groupId>
+ <version>0.0.4-SNAPSHOT</version>
+ </parent>
+ <artifactId>asterix-test-framework</artifactId>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ <fork>true</fork>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jvnet.jaxb2.maven2</groupId>
+ <artifactId>maven-jaxb2-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ </dependencies>
+</project>
diff --git a/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java
new file mode 100644
index 0000000..bb89a76
--- /dev/null
+++ b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java
@@ -0,0 +1,152 @@
+package edu.uci.ics.asterix.testframework.context;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import edu.uci.ics.asterix.testframework.xml.TestCase;
+import edu.uci.ics.asterix.testframework.xml.TestCase.CompilationUnit;
+import edu.uci.ics.asterix.testframework.xml.TestGroup;
+import edu.uci.ics.asterix.testframework.xml.TestSuite;
+import edu.uci.ics.asterix.testframework.xml.TestSuiteParser;
+
+public class TestCaseContext {
+ public static final String DEFAULT_TESTSUITE_XML_NAME = "testsuite.xml";
+
+ private File tsRoot;
+
+ private TestSuite testSuite;
+
+ private TestGroup[] testGroups;
+
+ private TestCase testCase;
+
+ public TestCaseContext(File tsRoot, TestSuite testSuite, TestGroup[] testGroups, TestCase testCase) {
+ this.tsRoot = tsRoot;
+ this.testSuite = testSuite;
+ this.testGroups = testGroups;
+ this.testCase = testCase;
+ }
+
+ public File getTsRoot() {
+ return tsRoot;
+ }
+
+ public TestSuite getTestSuite() {
+ return testSuite;
+ }
+
+ public TestGroup[] getTestGroups() {
+ return testGroups;
+ }
+
+ public TestCase getTestCase() {
+ return testCase;
+ }
+
+ public List<TestFileContext> getTestFiles(CompilationUnit cUnit) {
+ List<TestFileContext> testFileCtxs = new ArrayList<TestFileContext>();
+
+ File path = tsRoot;
+ path = new File(path, testSuite.getQueryOffsetPath());
+ path = new File(path, testCase.getFilePath());
+ path = new File(path, cUnit.getName());
+
+ String fileNames[] = path.list();
+ for (String fName : fileNames) {
+ if (fName.startsWith(".")) {
+ continue;
+ }
+
+ File testFile = new File(path, fName);
+ TestFileContext tfsc = new TestFileContext(testFile);
+ String[] nameSplits = fName.split("\\.");
+ if (nameSplits.length < 3) {
+ throw new IllegalArgumentException("Test file '" + cUnit.getName() + File.separatorChar
+ + fName + "' does not have the proper test file name format.");
+ }
+ tfsc.setSeqNum(nameSplits[nameSplits.length - 3]);
+ tfsc.setType(nameSplits[nameSplits.length - 2]);
+ testFileCtxs.add(tfsc);
+ }
+ Collections.sort(testFileCtxs);
+ return testFileCtxs;
+ }
+
+ public List<TestFileContext> getExpectedResultFiles(CompilationUnit cUnit) {
+ List<TestFileContext> resultFileCtxs = new ArrayList<TestFileContext>();
+
+ File path = tsRoot;
+ path = new File(path, testSuite.getResultOffsetPath());
+ path = new File(path, testCase.getFilePath());
+ path = new File(path, cUnit.getOutputDir().getValue());
+
+ String fileNames[] = path.list();
+
+ if (fileNames != null) {
+ for (String fName : fileNames) {
+ if (fName.startsWith(".")) {
+ continue;
+ }
+
+ File testFile = new File(path, fName);
+ TestFileContext tfsc = new TestFileContext(testFile);
+ String[] nameSplits = fName.split("\\.");
+
+ if (nameSplits.length < 3) {
+ throw new IllegalArgumentException("Test file '" + cUnit.getName() + File.separatorChar
+ + fName + "' does not have the proper test file name format.");
+ }
+
+ tfsc.setSeqNum(nameSplits[nameSplits.length - 2]);
+ resultFileCtxs.add(tfsc);
+ }
+ Collections.sort(resultFileCtxs);
+ }
+ return resultFileCtxs;
+ }
+
+ public File getActualResultFile(CompilationUnit cUnit, File actualResultsBase) {
+ File path = actualResultsBase;
+ path = new File(path, testSuite.getResultOffsetPath());
+ path = new File(path, testCase.getFilePath());
+ return new File(path, cUnit.getOutputDir().getValue() + ".adm");
+ }
+
+ public static class Builder {
+ public Builder() {
+ }
+
+ public List<TestCaseContext> build(File tsRoot) throws Exception {
+ return build(tsRoot, DEFAULT_TESTSUITE_XML_NAME);
+ }
+
+ public List<TestCaseContext> build(File tsRoot, String tsXMLFilePath) throws Exception {
+ File tsFile = new File(tsRoot, tsXMLFilePath);
+ TestSuiteParser tsp = new TestSuiteParser();
+ TestSuite ts = tsp.parse(tsFile);
+ List<TestCaseContext> tccs = new ArrayList<TestCaseContext>();
+ List<TestGroup> tgPath = new ArrayList<TestGroup>();
+ addContexts(tsRoot, ts, tgPath, ts.getTestGroup(), tccs);
+ return tccs;
+ }
+
+ private void addContexts(File tsRoot, TestSuite ts, List<TestGroup> tgPath, List<TestGroup> testGroups,
+ List<TestCaseContext> tccs) {
+ for (TestGroup tg : testGroups) {
+ tgPath.add(tg);
+ addContexts(tsRoot, ts, tgPath, tccs);
+ tgPath.remove(tgPath.size() - 1);
+ }
+ }
+
+ private void addContexts(File tsRoot, TestSuite ts, List<TestGroup> tgPath, List<TestCaseContext> tccs) {
+ TestGroup tg = tgPath.get(tgPath.size() - 1);
+ for (TestCase tc : tg.getTestCase()) {
+ tccs.add(new TestCaseContext(tsRoot, ts, tgPath.toArray(new TestGroup[tgPath.size()]), tc));
+ }
+ addContexts(tsRoot, ts, tgPath, tg.getTestGroup(), tccs);
+ }
+ }
+}
\ No newline at end of file
diff --git a/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestFileContext.java b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestFileContext.java
new file mode 100644
index 0000000..fce56ff
--- /dev/null
+++ b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestFileContext.java
@@ -0,0 +1,44 @@
+package edu.uci.ics.asterix.testframework.context;
+
+import java.io.File;
+
+public class TestFileContext implements Comparable<TestFileContext> {
+ private final File file;
+
+ private String type;
+
+ private int seqNum;
+
+ public TestFileContext(File file) {
+ this.file = file;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public int getSeqNum() {
+ return seqNum;
+ }
+
+ public void setSeqNum(String strSeqNum) {
+ seqNum = Integer.parseInt(strSeqNum);
+ }
+
+ @Override
+ public int compareTo(TestFileContext o) {
+ if (this.seqNum > o.seqNum)
+ return 1;
+ else if (this.seqNum < o.seqNum)
+ return -1;
+ return 0;
+ }
+}
diff --git a/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/xml/TestSuiteParser.java b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/xml/TestSuiteParser.java
new file mode 100644
index 0000000..0c544ac
--- /dev/null
+++ b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/xml/TestSuiteParser.java
@@ -0,0 +1,15 @@
+package edu.uci.ics.asterix.testframework.xml;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+
+public class TestSuiteParser {
+ public TestSuiteParser() {
+ }
+
+ public TestSuite parse(File testSuiteCatalog) throws Exception {
+ JAXBContext ctx = JAXBContext.newInstance(TestSuite.class);
+ return (TestSuite) ctx.createUnmarshaller().unmarshal(testSuiteCatalog);
+ }
+}
\ No newline at end of file
diff --git a/asterix-test-framework/src/main/resources/Catalog.xsd b/asterix-test-framework/src/main/resources/Catalog.xsd
new file mode 100755
index 0000000..632d6ad
--- /dev/null
+++ b/asterix-test-framework/src/main/resources/Catalog.xsd
@@ -0,0 +1,201 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:test="urn:xml.testframework.asterix.ics.uci.edu"
+ targetNamespace="urn:xml.testframework.asterix.ics.uci.edu" elementFormDefault="qualified">
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- test-suite - top level element -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <xs:element name="test-suite">
+ <xs:annotation>
+ <xs:documentation>
+ This is the top level element for documents that use this schema.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="test:test-group" maxOccurs="unbounded"/>
+ </xs:sequence>
+
+ <xs:attribute name="CatalogDesignDate" type="xs:date" use="required"/>
+
+ <xs:attribute name="ResultOffsetPath" type="test:SimplifiedRelativeFilePath" use="required">
+ <xs:annotation>
+ <xs:documentation>
+ offset from root to results
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+
+ <xs:attribute name="QueryOffsetPath" type="test:SimplifiedRelativeFilePath"
+ use="required">
+ <xs:annotation>
+ <xs:documentation>
+ offset from root to Query expression files
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+
+ </xs:complexType>
+
+ <xs:unique name="unique-test-group">
+ <xs:selector xpath=".//test:test-group"/>
+ <xs:field xpath="@name"/>
+ </xs:unique>
+
+ </xs:element>
+
+
+ <!-- SimplifiedRelativeFilePath type -->
+
+ <xs:simpleType name="SimplifiedRelativeFilePath">
+ <xs:restriction base="xs:anyURI">
+ <xs:pattern value="([a-zA-Z0-9\-\.]+/)+"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- test-group -->
+ <!-- -->
+ <!-- Group of test cases and test groups. -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <xs:element name="test-group">
+ <xs:annotation>
+ <xs:documentation>
+ Group of test cases and test groups.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="test-case" type="test:test-case" minOccurs="0" maxOccurs="unbounded">
+ <xs:unique name="unique-expected-error">
+ <xs:selector xpath=".//test:expected-error"/>
+ <xs:field xpath="."/>
+ </xs:unique>
+ </xs:element>
+
+ <xs:element ref="test:test-group" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- test-case -->
+ <!-- -->
+ <!-- A test case to be run. -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <xs:complexType name="test-case">
+ <xs:sequence>
+ <xs:element name="description" type="test:description"/>
+
+ <xs:element name="compilation-unit" minOccurs="1" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="description" type="test:description" minOccurs="0"/>
+ <xs:element name="output-dir" minOccurs="0">
+ <xs:annotation>
+ <xs:documentation>
+ Zero or one file containing expected results for this query.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="compare" type="test:comparison-enum" use="required"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+
+
+ <!-- Zero or more expected errors for this query -->
+
+ <xs:element name="expected-error" minOccurs="0" maxOccurs="unbounded">
+ <xs:annotation>
+ <xs:documentation>
+ Zero or more expected errors for this query.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="test:ErrorCode">
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+
+ </xs:sequence>
+
+ <!-- This name is always equal to the name of the test case -->
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ </xs:complexType>
+ </xs:element>
+
+ <!-- Zero or more files containing expected results for this query -->
+
+ </xs:sequence>
+
+ <!-- The filename for this query can be constructed from: -->
+ <!-- the QueryOffsetPath -->
+ <!-- the FilePath -->
+ <!-- the name -->
+ <!-- the QueryFileExtension -->
+
+ <xs:attribute name="FilePath" type="test:SimplifiedRelativeFilePath" use="required"/>
+ <xs:attribute name="date" type="xs:date" use="required"/>
+ </xs:complexType>
+
+ <!-- comparison-enum type -->
+ <!-- Identify the type of comparison used to determine whether an -->
+ <!-- expected result and an actual result match. -->
+
+ <xs:simpleType name="comparison-enum">
+ <xs:annotation>
+ <xs:documentation>
+ Identify the type of comparison used to determine whether an
+ expected result and an actual result match.
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="XML"/>
+ <xs:enumeration value="Text"/>
+ <xs:enumeration value="Inspect"/>
+ <xs:enumeration value="Ignore"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+ <!-- description type -->
+
+ <xs:complexType name="description">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="last-mod" type="xs:date"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+
+
+ <!-- ErrorCode type -->
+ <!-- * is used to mean that any error code is acceptable -->
+
+ <xs:simpleType name="ErrorCode">
+ <xs:annotation>
+ <xs:documentation>
+ * is used to mean that any error code is acceptable
+ </xs:documentation>
+ </xs:annotation>
+
+ <xs:restriction base="xs:string">
+ <xs:pattern value="\*|([A-Z]{4}[0-9]{4})"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+</xs:schema>