Added asterix project

git-svn-id: https://asterixdb.googlecode.com/svn/trunk/asterix@12 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-tools/src/test/java/edu/uci/ics/asterix/tools/test/AdmDataGenTest.java b/asterix-tools/src/test/java/edu/uci/ics/asterix/tools/test/AdmDataGenTest.java
new file mode 100644
index 0000000..65d0760
--- /dev/null
+++ b/asterix-tools/src/test/java/edu/uci/ics/asterix/tools/test/AdmDataGenTest.java
@@ -0,0 +1,197 @@
+package edu.uci.ics.asterix.tools.test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import org.junit.AfterClass;
+import org.junit.Assume;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import edu.uci.ics.asterix.test.base.AsterixTestHelper;
+import edu.uci.ics.asterix.tools.datagen.AdmDataGen;
+
+@RunWith(Parameterized.class)
+public class AdmDataGenTest {
+
+    private static final Logger LOGGER = Logger.getLogger(AdmDataGenTest.class.getName());
+
+    private static final String SEPARATOR = File.separator;
+    private static final String EXTENSION_QUERY = "adg";
+    private static final String FILENAME_IGNORE = "ignore.txt";
+    private static final String FILENAME_ONLY = "only.txt";
+    private static final String PATH_BASE = "src" + SEPARATOR + "test" + SEPARATOR + "resources" + SEPARATOR + "adgts"
+            + SEPARATOR;
+    private static final String PATH_QUERIES = PATH_BASE + "dgscripts" + SEPARATOR;
+    private static final String PATH_EXPECTED = PATH_BASE + "results" + SEPARATOR;
+    private static final String PATH_ACTUAL = "adgtest" + SEPARATOR;
+
+    private static final ArrayList<String> ignore = AsterixTestHelper.readFile(FILENAME_IGNORE, PATH_BASE);
+    private static final ArrayList<String> only = AsterixTestHelper.readFile(FILENAME_ONLY, PATH_BASE);
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        File outdir = new File(PATH_ACTUAL);
+        if (outdir.exists()) {
+            AsterixTestHelper.deleteRec(outdir);
+        }
+        outdir.mkdirs();
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        // _bootstrap.stop();
+        File outdir = new File(PATH_ACTUAL);
+        File[] files = outdir.listFiles();
+        if (files == null || files.length == 0) {
+            outdir.delete();
+        }
+    }
+
+    private static void suiteBuild(File dir, Collection<Object[]> testArgs, String path) {
+        for (File file : dir.listFiles()) {
+            if (file.isDirectory() && !file.getName().startsWith(".")) {
+                suiteBuild(file, testArgs, path + file.getName() + SEPARATOR);
+            }
+            if (file.isFile() && file.getName().endsWith(EXTENSION_QUERY)
+            // && !ignore.contains(path + file.getName())
+            ) {
+                File expectedDir = new File(PATH_EXPECTED + path);
+                File actualDir = new File(PATH_ACTUAL + SEPARATOR + path);
+                testArgs.add(new Object[] { file, expectedDir, actualDir });
+            }
+        }
+    }
+
+    @Parameters
+    public static Collection<Object[]> tests() {
+        Collection<Object[]> testArgs = new ArrayList<Object[]>();
+        suiteBuild(new File(PATH_QUERIES), testArgs, "");
+        return testArgs;
+    }
+
+    private File actualDir;
+    private File expectedDir;
+    private File scriptFile;
+
+    public AdmDataGenTest(File scriptFile, File expectedDir, File actualDir) {
+        this.scriptFile = scriptFile;
+        this.expectedDir = expectedDir;
+        this.actualDir = actualDir;
+    }
+
+    @Test
+    public void test() throws Exception {
+        String scriptFileShort = scriptFile.getPath().substring(PATH_QUERIES.length())
+                .replace(SEPARATOR.charAt(0), '/');
+        if (!only.isEmpty()) {
+            if (!only.contains(scriptFileShort)) {
+                LOGGER.info("SKIP TEST: \"" + scriptFile.getPath()
+                        + "\" \"only.txt\" not empty and not in \"only.txt\".");
+            }
+            Assume.assumeTrue(only.contains(scriptFileShort));
+        }
+        if (ignore.contains(scriptFileShort)) {
+            LOGGER.info("SKIP TEST: \"" + scriptFile.getPath() + "\" in \"ignore.txt\".");
+        }
+        Assume.assumeTrue(!ignore.contains(scriptFileShort));
+
+        LOGGER.info("RUN TEST: \"" + scriptFile.getPath() + "\"");
+
+        actualDir.mkdirs();
+        AdmDataGen adg = new AdmDataGen(scriptFile, actualDir);
+        try {
+            adg.init();
+            adg.dataGen();
+        } catch (Exception e) {
+            throw new Exception("Data gen. ERROR for " + scriptFile + ": " + e.getMessage(), e);
+        }
+
+        if (!expectedDir.isDirectory()) {
+            throw new Exception(expectedDir + " is not a directory.");
+        }
+        if (!actualDir.isDirectory()) {
+            throw new Exception(expectedDir + " is not a directory.");
+        }
+
+        File[] expectedFileSet = expectedDir.listFiles(AdmFileFilter.INSTANCE);
+        File[] actualFileSet = actualDir.listFiles(AdmFileFilter.INSTANCE);
+
+        if (expectedFileSet.length != actualFileSet.length) {
+            throw new Exception("Expecting " + expectedFileSet.length + " files and found " + actualFileSet.length
+                    + " files instead.");
+        }
+
+        for (File expectedFile : expectedFileSet) {
+            if (expectedFile.isHidden()) {
+                continue;
+            }
+            File actualFile = null;
+            for (File f : actualFileSet) {
+                if (f.getName().equals(expectedFile.getName())) {
+                    actualFile = f;
+                    break;
+                }
+            }
+            if (actualFile == null) {
+                throw new Exception("Could not find file " + expectedFile.getName());
+            }
+
+            BufferedReader readerExpected = new BufferedReader(new FileReader(expectedFile));
+            BufferedReader readerActual = new BufferedReader(new FileReader(actualFile));
+
+            String lineExpected, lineActual;
+            int num = 1;
+            try {
+                while ((lineExpected = readerExpected.readLine()) != null) {
+                    lineActual = readerActual.readLine();
+                    // Assert.assertEquals(lineExpected, lineActual);
+                    if (lineActual == null) {
+                        throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
+                                + lineExpected + "\n> ");
+                    }
+                    if (!lineExpected.equals(lineActual)) {
+                        throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< "
+                                + lineExpected + "\n> " + lineActual);
+                    }
+                    ++num;
+                }
+                lineActual = readerActual.readLine();
+                // Assert.assertEquals(null, lineActual);
+                if (lineActual != null) {
+                    throw new Exception("Result for " + scriptFile + " changed at line " + num + ":\n< \n> "
+                            + lineActual);
+                }
+            } finally {
+                readerExpected.close();
+                readerActual.close();
+            }
+        }
+        AsterixTestHelper.deleteRec(actualDir);
+    }
+
+    private static class AdmFileFilter implements FileFilter {
+
+        public static final AdmFileFilter INSTANCE = new AdmFileFilter();
+
+        private AdmFileFilter() {
+        }
+
+        @Override
+        public boolean accept(File path) {
+            if (path.isHidden() || !path.isFile()) {
+                return false;
+            }
+            return path.getName().endsWith(".adm");
+        }
+    }
+
+}
diff --git a/asterix-tools/src/test/resources/adgts/dgscripts/events/event.adg b/asterix-tools/src/test/resources/adgts/dgscripts/events/event.adg
new file mode 100644
index 0000000..b757994
--- /dev/null
+++ b/asterix-tools/src/test/resources/adgts/dgscripts/events/event.adg
@@ -0,0 +1,51 @@
+drop dataverse events if exists;
+create dataverse events;
+use dataverse events;
+
+
+create type AddressType as closed {
+  /*+ val-files data/events/streets.txt */
+  street: string,
+  /*+ val-files data/events/cities.txt */
+  city: string,
+  /*+ interval long 100000 999999 */
+  zip: string,
+  /*+ val-file-same-idx data/events/latlongs.txt city */
+  latlong: point
+}
+
+/*+ dgen event.adm 5*/
+create type EventType as closed {
+  /*+ auto 100000 */
+  event_id: int64,
+  /*+ insert-rand-int event- - */ 
+  name: string,
+  location: AddressType ?,
+  /*+ list 1 3 */
+  organizers: {{
+   /*+ gen-fields int 0 2 other */ 
+   {
+     /*+ val-files data/uscensus/dist.all.first.cleaned data/uscensus/dist.all.last.cleaned */
+     name: string
+   }
+  }},
+  /*+ list 1 2 */
+  sponsoring_sigs: [
+    {
+      /*+ interval int 100 120 */    
+      sig_id: int32,
+      /*+ val-files data/events/chapter_names.txt */      
+      chapter_name: string
+    }
+  ],
+  /*+ list-val-file data/events/interests.txt 1 4 */  
+  interest_keywords: {{string}},
+  /*+ interval double 5 20 */
+  price: double?,
+  /*+ datetime-between-years 1999 2012 */
+  start_time: datetime,
+  /*+ datetime-add-rand-hours 1 4 start_time */
+  end_time: datetime
+}
+
+
diff --git a/asterix-tools/src/test/resources/adgts/dgscripts/users/user.adg b/asterix-tools/src/test/resources/adgts/dgscripts/users/user.adg
new file mode 100644
index 0000000..8ad2ad5
--- /dev/null
+++ b/asterix-tools/src/test/resources/adgts/dgscripts/users/user.adg
@@ -0,0 +1,39 @@
+drop dataverse events if exists;
+create dataverse events;
+use dataverse events;
+
+
+create type AddressType as closed {
+  /*+ val-files data/events/streets.txt */
+  street: string,
+  /*+ val-files data/events/cities.txt */
+  city: string,
+  /*+ interval long 100000 999999 */
+  zip: string,
+  /*+ val-file-same-idx data/events/latlongs.txt city */
+  latlong: point
+}
+
+/*+ dgen user.adm 3*/
+create type UserType as open /*+ gen-fields int 0 10 field */ { 
+  /*+ val-files data/uscensus/dist.all.first.cleaned data/uscensus/dist.all.last.cleaned */
+  name: string,
+  /*+ insert-rand-int user @example.com */
+  email: string,
+  /*+ list-val-file data/events/interests.txt 0 7 */  
+  interests: {{string}},
+  address: AddressType,
+  /*+ list 1 10 */
+  member_of: {{
+    /*+ gen-fields int 0 2 other */
+    {
+      /*+ interval int 100000 999999 */    
+      sig_id: int32,
+      /*+ val-files data/events/chapter_names.txt */
+      chapter_name: string,
+      /*+ date-between-years 1970 1998 */ 
+      member_since: date
+    }
+  }}
+}
+
diff --git a/asterix-tools/src/test/resources/adgts/only.txt b/asterix-tools/src/test/resources/adgts/only.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-tools/src/test/resources/adgts/only.txt
diff --git a/asterix-tools/src/test/resources/adgts/results/events/event.adm b/asterix-tools/src/test/resources/adgts/results/events/event.adm
new file mode 100644
index 0000000..dd5b654
--- /dev/null
+++ b/asterix-tools/src/test/resources/adgts/results/events/event.adm
@@ -0,0 +1,5 @@
+{ "event_id": 100000i64, "name": "event-1161255810-", "location": { "street": "Washington St.", "city": "Irvine", "zip": "245704", "latlong": point("33,-117") }, "organizers": {{{ "name": "Ruth Sasala", "other_1": 928991271, "other_0": 824112980 }, { "name": "Bo Sanchz" }, { "name": "Karan Eye", "other_0": 647271456 }}}, "sponsoring_sigs": [{ "sig_id": 115, "chapter_name": "Los Angeles" }, { "sig_id": 115, "chapter_name": "Seattle" }], "interest_keywords": {{"tennis", "running", "bass"}}, "price": 5.729624060793583, "start_time": datetime("2004-01-20T02:00:00"), "end_time": datetime("2004-01-20T05:00:00") }
+{ "event_id": 100001i64, "name": "event-571555944-", "location": { "street": "Main St.", "city": "Irvine", "zip": "589756", "latlong": point("33,-117") }, "organizers": {{{ "name": "Tabatha Lammel", "other_0": 1064393481, "other_1": 811017688 }, { "name": "Magda Eska" }, { "name": "Joye Wholey", "other_1": 1465062491, "other_0": 675875773 }}}, "sponsoring_sigs": [{ "sig_id": 112, "chapter_name": "Los Angeles" }, { "sig_id": 112, "chapter_name": "Seattle" }], "interest_keywords": {{"squash"}}, "price": 5.783702367883383, "start_time": datetime("2005-02-11T23:00:00"), "end_time": datetime("2005-02-11T23:00:00") }
+{ "event_id": 100002i64, "name": "event-928991271-", "organizers": {{{ "name": "Grady Miyashiro", "other_0": 1753250755 }}}, "sponsoring_sigs": [{ "sig_id": 105, "chapter_name": "Kirkland" }, { "sig_id": 119, "chapter_name": "San Clemente" }], "interest_keywords": {{"wine", "cooking"}}, "start_time": datetime("2009-07-20T03:00:00"), "end_time": datetime("2009-07-20T07:00:00") }
+{ "event_id": 100003i64, "name": "event-1620216540-", "organizers": {{{ "name": "Ione Janiszewski", "other_0": 1449157330 }, { "name": "Ilse Hurse" }, { "name": "Mason Freudenthal", "other_0": 172885567 }}}, "sponsoring_sigs": [{ "sig_id": 117, "chapter_name": "Kirkland" }, { "sig_id": 104, "chapter_name": "Irvine" }], "interest_keywords": {{"fishing", "music", "skiing"}}, "start_time": datetime("2009-05-23T14:00:00"), "end_time": datetime("2009-05-23T17:00:00") }
+{ "event_id": 100004i64, "name": "event-824112980-", "organizers": {{{ "name": "Soo Raul" }, { "name": "Leif Henshall" }}}, "sponsoring_sigs": [{ "sig_id": 106, "chapter_name": "Portland" }], "interest_keywords": {{"wine", "walking", "basketball", "running"}}, "price": 5.191878754151207, "start_time": datetime("2002-12-23T01:00:00"), "end_time": datetime("2002-12-23T02:00:00") }
diff --git a/asterix-tools/src/test/resources/adgts/results/users/user.adm b/asterix-tools/src/test/resources/adgts/results/users/user.adm
new file mode 100644
index 0000000..35889dd
--- /dev/null
+++ b/asterix-tools/src/test/resources/adgts/results/users/user.adm
@@ -0,0 +1,3 @@
+{ "name": "Ruth Sasala", "email": "user1161255810@example.com", "interests": {{"tennis", "running", "bass", "bass", "squash"}}, "address": { "street": "Washington St.", "city": "Irvine", "zip": "245704", "latlong": point("33,-117") }, "member_of": {{{ "sig_id": 355810, "chapter_name": "Los Angeles", "member_since": date("1981-01-20"), "other_1": 928991271, "other_0": 824112980 }, { "sig_id": 155944, "chapter_name": "Seattle", "member_since": date("1980-09-06") }, { "sig_id": 291271, "chapter_name": "Los Angeles", "member_since": date("1973-11-21"), "other_0": 647271456 }, { "sig_id": 316540, "chapter_name": "Seattle", "member_since": date("1988-08-26"), "other_0": 1064393481, "other_1": 811017688 }}}, "field_1": 928991271, "field_0": 824112980 }
+{ "name": "Bo Sanchz", "email": "user571555944@example.com", "interests": {{"wine", "cooking"}}, "address": { "street": "Main St.", "city": "Irvine", "zip": "589756", "latlong": point("33,-117") }, "member_of": {{{ "sig_id": 712980, "chapter_name": "Kirkland", "member_since": date("1997-05-23") }, { "sig_id": 746825, "chapter_name": "San Clemente", "member_since": date("1980-03-12"), "other_1": 1465062491, "other_0": 675875773 }, { "sig_id": 409158, "chapter_name": "Kirkland", "member_since": date("1976-02-22"), "other_0": 1753250755 }, { "sig_id": 806510, "chapter_name": "Irvine", "member_since": date("1980-08-24"), "other_0": 1449157330 }, { "sig_id": 271456, "chapter_name": "Portland", "member_since": date("1997-11-27") }, { "sig_id": 167494, "chapter_name": "Los Angeles", "member_since": date("1976-08-16"), "other_0": 172885567 }, { "sig_id": 363383, "chapter_name": "Newport Beach", "member_since": date("1982-11-08") }}}, "field_0": 1051906510 }
+{ "name": "Karan Eye", "email": "user928991271@example.com", "interests": {{"fishing", "music", "skiing", "movies", "wine"}}, "address": { "street": "Washington St.", "city": "Huntington Beach", "zip": "248905", "latlong": point("33,-117") }, "member_of": {{{ "sig_id": 693481, "chapter_name": "Los Angeles", "member_since": date("1988-01-03") }, { "sig_id": 354593, "chapter_name": "Irvine", "member_since": date("1995-03-21"), "other_0": 1721620164 }, { "sig_id": 217688, "chapter_name": "San Clemente", "member_since": date("1982-01-19"), "other_0": 646860650 }}}, "field_5": 1832663383, "field_6": 270254593, "field_3": 1332296190, "field_2": 432209174, "field_0": 520792154, "field_7": 464970681, "field_4": 1753250755, "field_8": 1539455368, "field_1": 1167889770 }
diff --git a/asterix-tools/src/test/resources/logging.properties b/asterix-tools/src/test/resources/logging.properties
new file mode 100644
index 0000000..a205eca
--- /dev/null
+++ b/asterix-tools/src/test/resources/logging.properties
@@ -0,0 +1,65 @@
+############################################################
+#  	Default Logging Configuration File
+#
+# You can use a different file by specifying a filename
+# with the java.util.logging.config.file system property.  
+# For example java -Djava.util.logging.config.file=myfile
+############################################################
+
+############################################################
+#  	Global properties
+############################################################
+
+# "handlers" specifies a comma separated list of log Handler 
+# classes.  These handlers will be installed during VM startup.
+# Note that these classes must be on the system classpath.
+# By default we only configure a ConsoleHandler, which will only
+# show messages at the INFO and above levels.
+
+handlers= java.util.logging.ConsoleHandler
+
+# To also add the FileHandler, use the following line instead.
+
+# handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+# Default global logging level.
+# This specifies which kinds of events are logged across
+# all loggers.  For any given facility this global level
+# can be overriden by a facility specific level
+# Note that the ConsoleHandler also has a separate level
+# setting to limit messages printed to the console.
+
+.level= WARNING
+# .level= INFO
+# .level= FINE
+# .level = FINEST
+
+############################################################
+# Handler specific properties.
+# Describes specific configuration info for Handlers.
+############################################################
+
+# default file output is in user's home directory.
+
+# java.util.logging.FileHandler.pattern = %h/java%u.log
+# java.util.logging.FileHandler.limit = 50000
+# java.util.logging.FileHandler.count = 1
+# java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+
+# Limit the message that are printed on the console to FINE and above.
+
+java.util.logging.ConsoleHandler.level = FINE
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+
+############################################################
+# Facility specific properties.
+# Provides extra control for each logger.
+############################################################
+
+# For example, set the com.xyz.foo logger to only log SEVERE
+# messages:
+
+# edu.uci.ics.asterix.level = FINE
+# edu.uci.ics.algebricks.level = FINE
+# edu.uci.ics.hyracks.level = FINE