ASTERIXDB-1439: Add Test Cases For Big Objects
Two cases involving 20MB values, using load mechanism
Change-Id: I26abeba3db348f08de5b936a791fb3e3814519c9
Reviewed-on: https://asterix-gerrit.ics.uci.edu/849
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <michael.blow@couchbase.com>
diff --git a/asterixdb/asterix-app/data/big-object/big_object_20M.adm.template b/asterixdb/asterix-app/data/big-object/big_object_20M.adm.template
new file mode 100644
index 0000000..5c70ca6
--- /dev/null
+++ b/asterixdb/asterix-app/data/big-object/big_object_20M.adm.template
@@ -0,0 +1,4 @@
+{ "id": 1, "name": "Person One", "hobbies": {{ "%lorembytes:20971520%" }} }
+{ "id": 2, "name": "Person Two", "hobbies": {{ "%lorembytes:20971520%" }} }
+{ "id": 3, "name": "Person Three", "hobbies": {{ "%lorembytes:20971520%" }} }
+{ "id": 4, "name": "Person Four", "hobbies": {{ "%lorembytes:20971520%" }} }
diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml
index 19c2d5a..8870ce2 100644
--- a/asterixdb/asterix-app/pom.xml
+++ b/asterixdb/asterix-app/pom.xml
@@ -133,6 +133,29 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.asterix</groupId>
+ <artifactId>asterix-test-datagenerator-maven-plugin</artifactId>
+ <version>0.8.9-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>replace-template-data</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>generate-testdata</goal>
+ </goals>
+ <configuration>
+ <inputFiles>
+ <directory>data</directory>
+ <includes>
+ <include>**/*.template</include>
+ </includes>
+ </inputFiles>
+ <outputDir>target/data</outputDir>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<dependencies>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.1.ddl.aql
new file mode 100644
index 0000000..77c8179
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.1.ddl.aql
@@ -0,0 +1,36 @@
+/*
+ * 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 case Name : big_object_bulkload.aql
+ * Description : bulkload insert of large objects
+ * Expected Result : Success
+ * Date : 20th April 2016
+ */
+
+drop dataverse testdv2 if exists;
+create dataverse testdv2;
+use dataverse testdv2;
+
+create type testtype as closed {
+ id: int64,
+ name: string,
+ hobbies: {{string}}
+}
+
+create dataset testds(testtype) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql
new file mode 100644
index 0000000..d8895f6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.2.update.aql
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/**
+ *
+ * Big object (20 MB) loading test
+ * Expected result: success
+ *
+ */
+
+use dataverse testdv2;
+
+load dataset testds
+using localfs
+(("path"="asterix_nc1://target/data/big-object/big_object_20M.adm"),("format"="adm")) pre-sorted;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.3.query.aql
new file mode 100644
index 0000000..23c1bed
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_20M/big_object_load_20M.3.query.aql
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+use dataverse testdv2;
+
+for $d in dataset("testds")
+where $d.id = 1
+return $d
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.1.ddl.aql
new file mode 100644
index 0000000..77c8179
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.1.ddl.aql
@@ -0,0 +1,36 @@
+/*
+ * 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 case Name : big_object_bulkload.aql
+ * Description : bulkload insert of large objects
+ * Expected Result : Success
+ * Date : 20th April 2016
+ */
+
+drop dataverse testdv2 if exists;
+create dataverse testdv2;
+use dataverse testdv2;
+
+create type testtype as closed {
+ id: int64,
+ name: string,
+ hobbies: {{string}}
+}
+
+create dataset testds(testtype) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.2.update.aql
new file mode 100644
index 0000000..d8895f6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.2.update.aql
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/**
+ *
+ * Big object (20 MB) loading test
+ * Expected result: success
+ *
+ */
+
+use dataverse testdv2;
+
+load dataset testds
+using localfs
+(("path"="asterix_nc1://target/data/big-object/big_object_20M.adm"),("format"="adm")) pre-sorted;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.3.query.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.3.query.aql
new file mode 100644
index 0000000..9979ef6
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/big-object/big_object_load_only_20M/big_object_load_only_20M.3.query.aql
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+use dataverse testdv2;
+
+for $d in dataset("testds")
+order by $d.id
+return $d.id
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_20M/big_object_load_20M.1.adm.template b/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_20M/big_object_load_20M.1.adm.template
new file mode 100644
index 0000000..af4d6d0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_20M/big_object_load_20M.1.adm.template
@@ -0,0 +1 @@
+{ "id": 1, "name": "Person One", "hobbies": {{ "%lorembytes:20971520%" }} }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_only_20M/big_object_load_only_20M.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_only_20M/big_object_load_only_20M.1.adm
new file mode 100644
index 0000000..94ebaf9
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/big-object/big_object_load_only_20M/big_object_load_only_20M.1.adm
@@ -0,0 +1,4 @@
+1
+2
+3
+4
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index f77b38b..27aa7be 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -6470,6 +6470,16 @@
<output-dir compare="Text">big_object_insert</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="big-object">
+ <compilation-unit name="big_object_load_20M">
+ <output-dir compare="Text">big_object_load_20M</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="big-object">
+ <compilation-unit name="big_object_load_only_20M">
+ <output-dir compare="Text">big_object_load_only_20M</output-dir>
+ </compilation-unit>
+ </test-case>
</test-group>
<test-group name="temporal">
<test-case FilePath="temporal">
diff --git a/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/pom.xml b/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/pom.xml
new file mode 100644
index 0000000..db211a6
--- /dev/null
+++ b/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/pom.xml
@@ -0,0 +1,54 @@
+<!--
+ ! 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.
+ !-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>asterix-test-datagenerator-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>asterix-test-datagenerator-maven-plugin</name>
+
+ <parent>
+ <artifactId>asterix-maven-plugins</artifactId>
+ <groupId>org.apache.asterix</groupId>
+ <version>0.8.9-SNAPSHOT</version>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>file-management</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.asterix</groupId>
+ <artifactId>asterix-test-framework</artifactId>
+ <version>0.8.9-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/src/main/java/org/apache/hyracks/maven/plugin/TestDataGeneratorMojo.java b/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/src/main/java/org/apache/hyracks/maven/plugin/TestDataGeneratorMojo.java
new file mode 100644
index 0000000..e1afb43
--- /dev/null
+++ b/asterixdb/asterix-maven-plugins/asterix-test-datagenerator-maven-plugin/src/main/java/org/apache/hyracks/maven/plugin/TestDataGeneratorMojo.java
@@ -0,0 +1,80 @@
+/*
+ * 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.hyracks.maven.plugin;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.asterix.testframework.template.TemplateHelper;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.model.fileset.FileSet;
+import org.apache.maven.shared.model.fileset.util.FileSetManager;
+
+/**
+ * @goal generate-testdata
+ *
+ * @phase process-test-resources
+ */
+public class TestDataGeneratorMojo extends AbstractMojo {
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ MavenProject project;
+
+ /**
+ * @parameter
+ * @required
+ */
+ FileSet inputFiles;
+
+ /**
+ * @parameter
+ * @required
+ */
+ File outputDir;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ FileSetManager mgr = new FileSetManager();
+ // this seems pretty hacky, but necessary to get the correct result.
+ File inputFilesDirectory = new File(inputFiles.getDirectory());
+ if (!inputFilesDirectory.isAbsolute()) {
+ inputFiles.setDirectory(new File(project.getBasedir(), inputFiles.getDirectory()).getAbsolutePath());
+ }
+
+ final String[] includedFiles = mgr.getIncludedFiles(inputFiles);
+ getLog().info("Processing " + includedFiles.length + " files...");
+ for (String file : includedFiles) {
+ getLog().info(" -" + file);
+ try {
+ TemplateHelper.INSTANCE.processFile(new File(inputFiles.getDirectory(), file),
+ new File(outputDir, file.replace(".template", "")));
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new MojoExecutionException("failure", e);
+ }
+ }
+ }
+}
diff --git a/asterixdb/asterix-maven-plugins/pom.xml b/asterixdb/asterix-maven-plugins/pom.xml
index d3b37fa..2623c64 100644
--- a/asterixdb/asterix-maven-plugins/pom.xml
+++ b/asterixdb/asterix-maven-plugins/pom.xml
@@ -55,5 +55,6 @@
<module>lexer-generator-maven-plugin</module>
<module>record-manager-generator-maven-plugin</module>
<module>asterix-evaluator-generator-maven-plugin</module>
+ <module>asterix-test-datagenerator-maven-plugin</module>
</modules>
</project>
\ No newline at end of file
diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
index 8592286..0c25f69 100644
--- a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
+++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/context/TestCaseContext.java
@@ -19,11 +19,13 @@
package org.apache.asterix.testframework.context;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
+import org.apache.asterix.testframework.template.TemplateHelper;
import org.apache.asterix.testframework.xml.CategoryEnum;
import org.apache.asterix.testframework.xml.TestCase;
import org.apache.asterix.testframework.xml.TestCase.CompilationUnit;
@@ -140,6 +142,14 @@
}
File testFile = new File(path, fName);
+ if (fName.endsWith(".template")) {
+ try {
+ testFile = TemplateHelper.INSTANCE.resolveTemplateFile(testFile);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ fName = testFile.getName();
+ }
TestFileContext tfsc = new TestFileContext(testFile);
String[] nameSplits = fName.split("\\.");
if (nameSplits.length < 3) {
diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/LoremIpsumReplacement.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/LoremIpsumReplacement.java
new file mode 100644
index 0000000..e1145ac
--- /dev/null
+++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/LoremIpsumReplacement.java
@@ -0,0 +1,60 @@
+/*
+ * 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.asterix.testframework.datagen;
+
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class LoremIpsumReplacement implements TemplateReplacement {
+
+ public static final LoremIpsumReplacement INSTANCE = new LoremIpsumReplacement();
+
+ private static final String LOREM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
+ + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
+ + "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in "
+ + "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non "
+ + "proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ";
+
+ private static final Pattern p = Pattern.compile("%lorembytes:([0-9]*)%");
+
+ private LoremIpsumReplacement() {
+ }
+
+ @Override
+ public String tag() {
+ return "lorembytes";
+ }
+
+ @Override
+ public boolean appendReplacement(String expression, Appendable output) throws IOException {
+ Matcher m = p.matcher(expression);
+ if (m.find()) {
+ int loremBytes = Integer.parseInt(m.group(1)) - 1;
+ while (loremBytes > LOREM.length()) {
+ output.append(LOREM);
+ loremBytes -= LOREM.length();
+ }
+ output.append(LOREM, 0, loremBytes);
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/TemplateReplacement.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/TemplateReplacement.java
new file mode 100644
index 0000000..6648ce4
--- /dev/null
+++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/datagen/TemplateReplacement.java
@@ -0,0 +1,27 @@
+/*
+ * 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.asterix.testframework.datagen;
+
+import java.io.IOException;
+
+public interface TemplateReplacement {
+ String tag();
+
+ boolean appendReplacement(String expression, Appendable output) throws IOException;
+}
diff --git a/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/template/TemplateHelper.java b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/template/TemplateHelper.java
new file mode 100644
index 0000000..b3f26fd
--- /dev/null
+++ b/asterixdb/asterix-test-framework/src/main/java/org/apache/asterix/testframework/template/TemplateHelper.java
@@ -0,0 +1,89 @@
+/*
+ * 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.asterix.testframework.template;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.asterix.testframework.datagen.LoremIpsumReplacement;
+import org.apache.asterix.testframework.datagen.TemplateReplacement;
+
+public class TemplateHelper {
+
+ private final Map<String, TemplateReplacement> replacements = new HashMap<>();
+ private final Pattern replacementPattern;
+
+ public static final TemplateHelper INSTANCE = new TemplateHelper();
+
+ private TemplateHelper() {
+ registerReplacement(LoremIpsumReplacement.INSTANCE);
+ StringBuffer pattern = null;
+ for (Map.Entry<String, TemplateReplacement> entry : replacements.entrySet()) {
+ if (pattern == null) {
+ pattern = new StringBuffer("%(");
+ } else {
+ pattern.append("|");
+ }
+ pattern.append(entry.getKey());
+ }
+ pattern.append(")[^%]*%");
+ replacementPattern = Pattern.compile(pattern.toString());
+ }
+
+ private void registerReplacement(TemplateReplacement replacement) {
+ replacements.put(replacement.tag(), replacement);
+ }
+
+ public File resolveTemplateFile(File inputFile) throws IOException {
+ File outputFile = File.createTempFile("template.", "." +
+ inputFile.getName().substring(0, inputFile.getName().lastIndexOf(".template")));
+ outputFile.deleteOnExit();
+ processFile(inputFile, outputFile);
+ return outputFile;
+ }
+
+ public void processFile(File inputFile, File outputFile) throws IOException {
+ synchronized (this) {
+ outputFile.getParentFile().mkdirs();
+ }
+ try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ Matcher m = replacementPattern.matcher(line);
+ if (m.find()) {
+ writer.write(line, 0, m.start());
+ replacements.get(m.group(1)).appendReplacement(m.group(0), writer);
+ writer.write(line, m.end(), line.length() - m.end());
+ writer.newLine();
+ } else {
+ writer.write(line + "\n");
+ }
+ }
+ }
+ }
+}