Add Flag To ExecutionTest To Enable Test Repeats

- Also, fix tests to be able to be repeated

Change-Id: Ib263ff475bb7640bb3b4309e6804e4ab2e2702fb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1121
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/ExecutionTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/ExecutionTest.java
index baa3923..adc691f 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/ExecutionTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/runtime/ExecutionTest.java
@@ -55,6 +55,7 @@
     private static final boolean cleanupOnStart = true;
     private static final boolean cleanupOnStop = true;
     private static TestLibrarian librarian;
+    private static final int repeat = Integer.getInteger("test.repeat", 1);
 
     @BeforeClass
     public static void setUp() throws Exception {
@@ -66,6 +67,9 @@
             List<ILibraryManager> libraryManagers = ExecutionTestUtil.setUp(cleanupOnStart);
             librarian = new TestLibrarian(libraryManagers);
             testExecutor.setLibrarian(librarian);
+            if (repeat != 1) {
+                System.out.println("FYI: each test will be run " + repeat + " times.");
+            }
         } catch (Throwable th) {
             th.printStackTrace();
             throw th;
@@ -106,7 +110,16 @@
 
     @Test
     public void test() throws Exception {
-        librarian.cleanup();
-        testExecutor.executeTest(PATH_ACTUAL, tcCtx, null, false, ExecutionTestUtil.FailedGroup);
+        try {
+            for (int i = 1; i <= repeat; i++) {
+                if (repeat > 1) {
+                    System.err.print("[" + i + "/" + repeat + "] ");
+                }
+                librarian.cleanup();
+                testExecutor.executeTest(PATH_ACTUAL, tcCtx, null, false, ExecutionTestUtil.FailedGroup);
+            }
+        } finally {
+            System.err.flush();
+        }
     }
 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue382/query-issue382.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue382/query-issue382.1.ddl.aql
index 4838505..4568a83 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue382/query-issue382.1.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue382/query-issue382.1.ddl.aql
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+drop dataverse SocialNetworkData if exists;
 create dataverse SocialNetworkData;
 
 use dataverse SocialNetworkData;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue433/query-issue433.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue433/query-issue433.1.ddl.aql
index 85efa49..87970ef 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue433/query-issue433.1.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/dml/query-issue433/query-issue433.1.ddl.aql
@@ -23,6 +23,7 @@
  * Date         : 3th April 2013
  */
 
+drop dataverse insertIssue if exists;
 create dataverse insertIssue;
 use dataverse insertIssue;
 
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.aql
index 8b171ed..0426ae5 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.aql
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.aql
@@ -16,6 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+drop dataverse test if exists;
+create dataverse test;
+
 use dataverse test;
 
 create type DBLPType as closed {
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue382/query-issue382.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue382/query-issue382.1.ddl.sqlpp
index ec633db..0919bac 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue382/query-issue382.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue382/query-issue382.1.ddl.sqlpp
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+drop dataverse SocialNetworkData if exists;
 create  dataverse SocialNetworkData;
 
 use SocialNetworkData;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue433/query-issue433.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue433/query-issue433.1.ddl.sqlpp
index 53b48dd..c2fc5e1 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue433/query-issue433.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/query-issue433/query-issue433.1.ddl.sqlpp
@@ -23,6 +23,7 @@
  * Date         : 3th April 2013
  */
 
+drop dataverse insertIssue if exists;
 create  dataverse insertIssue;
 
 use insertIssue;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.sqlpp
index 994b753..4488d29 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/similarity/similarity-jaccard-sorted-check_query/similarity-jaccard-sorted-check_query.1.ddl.sqlpp
@@ -17,6 +17,9 @@
  * under the License.
  */
 
+drop dataverse test if exists;
+create dataverse test;
+
 use test;