You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2016/09/22 06:03:30 UTC

asterixdb git commit: Add JUnit Rule Implementation To Trace Test Methods

Repository: asterixdb
Updated Branches:
  refs/heads/master 83108375a -> d2fc11deb


Add JUnit Rule Implementation To Trace Test Methods

Change-Id: I8ecc73825881714d33c7937a1de4eda32d51a85c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1194
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/d2fc11de
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/d2fc11de
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/d2fc11de

Branch: refs/heads/master
Commit: d2fc11debe67855e9c9e5187bd76a7679e781327
Parents: 8310837
Author: Michael Blow <mb...@apache.org>
Authored: Wed Sep 21 21:27:48 2016 -0400
Committer: Michael Blow <mb...@apache.org>
Committed: Wed Sep 21 23:03:03 2016 -0700

----------------------------------------------------------------------
 .../asterix/test/base/AsterixTestHelper.java    | 34 -----------
 .../asterix/test/base/RetainLogsRule.java       | 57 ++++++++++++++++++
 .../asterix/test/base/TestMethodTracer.java     | 62 ++++++++++++++++++++
 .../installer/test/AbstractExecutionIT.java     |  4 +-
 .../test/AsterixExternalLibraryIT.java          |  4 +-
 .../installer/transaction/DmlRecoveryIT.java    |  4 +-
 .../installer/transaction/RecoveryIT.java       |  4 +-
 .../server/test/SampleLocalClusterIT.java       | 11 ++--
 8 files changed, 134 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
index adb0d7a..4953ac8 100644
--- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/AsterixTestHelper.java
@@ -27,8 +27,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 
 import org.apache.commons.io.FileUtils;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
 
 public class AsterixTestHelper {
 
@@ -100,36 +98,4 @@ public class AsterixTestHelper {
         }
     }
 
-    public static class RetainLogsRule extends TestWatcher {
-        private final File baseDir;
-        private final File destDir;
-        private long startTime;
-
-        public RetainLogsRule(File baseDir, File destDir) {
-            this.baseDir = baseDir;
-            this.destDir = destDir;
-        }
-
-        public RetainLogsRule(String baseDir, String destDir) {
-            this(new File(baseDir), new File(destDir));
-        }
-
-        @Override
-        protected void starting(Description description) {
-            startTime = System.currentTimeMillis();
-        }
-
-        @Override
-        protected void failed(Throwable e, Description description) {
-            File reportDir = new File(destDir, description.getTestClass().getName() + "." + description.getMethodName());
-            reportDir.mkdirs();
-            try {
-                AsterixTestHelper.deepSelectiveCopy(baseDir, reportDir,
-                        pathname -> pathname.getName().endsWith("log") &&
-                                pathname.lastModified() > startTime);
-            } catch (Exception e1) {
-                e1.printStackTrace();
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/RetainLogsRule.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/RetainLogsRule.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/RetainLogsRule.java
new file mode 100644
index 0000000..39bd5e7
--- /dev/null
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/RetainLogsRule.java
@@ -0,0 +1,57 @@
+/*
+ * 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.test.base;
+
+import java.io.File;
+
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+public class RetainLogsRule extends TestWatcher {
+    private final File baseDir;
+    private final File destDir;
+    private long startTime;
+
+    public RetainLogsRule(File baseDir, File destDir) {
+        this.baseDir = baseDir;
+        this.destDir = destDir;
+    }
+
+    public RetainLogsRule(String baseDir, String destDir) {
+        this(new File(baseDir), new File(destDir));
+    }
+
+    @Override
+    protected void starting(Description description) {
+        startTime = System.currentTimeMillis();
+    }
+
+    @Override
+    protected void failed(Throwable e, Description description) {
+        File reportDir = new File(destDir, description.getTestClass().getName() + "." + description.getMethodName());
+        reportDir.mkdirs();
+        try {
+            AsterixTestHelper.deepSelectiveCopy(baseDir, reportDir,
+                    pathname -> pathname.getName().endsWith("log") &&
+                            pathname.lastModified() > startTime);
+        } catch (Exception e1) {
+            e1.printStackTrace();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/TestMethodTracer.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/TestMethodTracer.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/TestMethodTracer.java
new file mode 100644
index 0000000..692805f
--- /dev/null
+++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/base/TestMethodTracer.java
@@ -0,0 +1,62 @@
+/*
+ * 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.test.base;
+
+import java.io.PrintStream;
+
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/*
+ * Traces method entry/exit to System.out (or supplied PrintStream).  To use, add the following to your test class:
+ *
+ *   @Rule
+ *   public TestRule watcher = new TestMethodTracer();
+ *
+ *   @Rule
+ *   public TestRule watcher = new TestMethodTracer(System.err);
+ */
+
+public class TestMethodTracer extends TestWatcher {
+
+    private final PrintStream out;
+
+    public TestMethodTracer(PrintStream out) {
+        this.out = out;
+    }
+
+    public TestMethodTracer() {
+        this(System.out);
+    }
+
+    @Override
+    protected void starting(Description description) {
+        out.println("## " + description.getMethodName() + " START");
+    }
+
+    @Override
+    protected void failed(Throwable e, Description description) {
+        out.println("## " + description.getMethodName() + " FAILED (" + e.getClass().getName() + ")");
+    }
+
+    @Override
+    protected void succeeded(Description description) {
+        out.println("## " + description.getMethodName() + " SUCCEEDED");
+    }
+}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AbstractExecutionIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AbstractExecutionIT.java b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AbstractExecutionIT.java
index 676137c..d9c902e 100644
--- a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AbstractExecutionIT.java
+++ b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AbstractExecutionIT.java
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
 import org.apache.asterix.external.util.ExternalDataConstants;
 import org.apache.asterix.external.util.IdentitiyResolverFactory;
 import org.apache.asterix.test.aql.TestExecutor;
-import org.apache.asterix.test.base.AsterixTestHelper;
+import org.apache.asterix.test.base.RetainLogsRule;
 import org.apache.asterix.test.runtime.HDFSCluster;
 import org.apache.asterix.testframework.context.TestCaseContext;
 import org.apache.asterix.testframework.context.TestFileContext;
@@ -65,7 +65,7 @@ public abstract class AbstractExecutionIT {
             new File(StringUtils.join(new String[] { "target", "failsafe-reports" }, File.separator)).getAbsolutePath();
 
     @Rule
-    public TestRule retainLogs = new AsterixTestHelper.RetainLogsRule(
+    public TestRule retainLogs = new RetainLogsRule(
             AsterixInstallerIntegrationUtil.getManagixHome(), reportPath);
 
     @BeforeClass

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AsterixExternalLibraryIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AsterixExternalLibraryIT.java b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AsterixExternalLibraryIT.java
index 57aaeee..ae98d19 100644
--- a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AsterixExternalLibraryIT.java
+++ b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/test/AsterixExternalLibraryIT.java
@@ -24,7 +24,7 @@ import java.util.logging.Logger;
 
 import org.apache.asterix.event.model.AsterixInstance.State;
 import org.apache.asterix.test.aql.TestExecutor;
-import org.apache.asterix.test.base.AsterixTestHelper;
+import org.apache.asterix.test.base.RetainLogsRule;
 import org.apache.asterix.testframework.context.TestCaseContext;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.AfterClass;
@@ -49,7 +49,7 @@ public class AsterixExternalLibraryIT {
     private final TestExecutor testExecutor = new TestExecutor();
 
     @Rule
-    public TestRule retainLogs = new AsterixTestHelper.RetainLogsRule(
+    public TestRule retainLogs = new RetainLogsRule(
             AsterixInstallerIntegrationUtil.getManagixHome(), reportPath);
 
     @BeforeClass

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/DmlRecoveryIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/DmlRecoveryIT.java b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/DmlRecoveryIT.java
index 68c009a..b55510a 100644
--- a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/DmlRecoveryIT.java
+++ b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/DmlRecoveryIT.java
@@ -26,7 +26,7 @@ import java.util.Map;
 import java.util.logging.Logger;
 
 import org.apache.asterix.test.aql.TestExecutor;
-import org.apache.asterix.test.base.AsterixTestHelper;
+import org.apache.asterix.test.base.RetainLogsRule;
 import org.apache.asterix.testframework.context.TestCaseContext;
 import org.apache.commons.io.FileUtils;
 import org.junit.AfterClass;
@@ -60,7 +60,7 @@ public class DmlRecoveryIT {
     private final TestExecutor testExecutor = new TestExecutor();
 
     @Rule
-    public TestRule retainLogs = new AsterixTestHelper.RetainLogsRule(managixHomePath, reportPath);
+    public TestRule retainLogs = new RetainLogsRule(managixHomePath, reportPath);
 
     @BeforeClass
     public static void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/RecoveryIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/RecoveryIT.java b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/RecoveryIT.java
index 9795702..98c0853 100644
--- a/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/RecoveryIT.java
+++ b/asterixdb/asterix-installer/src/test/java/org/apache/asterix/installer/transaction/RecoveryIT.java
@@ -26,7 +26,7 @@ import java.util.Map;
 import java.util.logging.Logger;
 
 import org.apache.asterix.test.aql.TestExecutor;
-import org.apache.asterix.test.base.AsterixTestHelper;
+import org.apache.asterix.test.base.RetainLogsRule;
 import org.apache.asterix.test.runtime.HDFSCluster;
 import org.apache.asterix.testframework.context.TestCaseContext;
 import org.apache.commons.io.FileUtils;
@@ -58,7 +58,7 @@ public class RecoveryIT {
     private final TestExecutor testExecutor = new TestExecutor();
 
     @Rule
-    public TestRule retainLogs = new AsterixTestHelper.RetainLogsRule(managixHomePath, reportPath);
+    public TestRule retainLogs = new RetainLogsRule(managixHomePath, reportPath);
 
     @BeforeClass
     public static void setUp() throws Exception {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d2fc11de/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
index e98262a..a49086b 100644
--- a/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
+++ b/asterixdb/asterix-server/src/test/java/org/apache/asterix/server/test/SampleLocalClusterIT.java
@@ -18,16 +18,18 @@
  */
 package org.apache.asterix.server.test;
 
+import static org.apache.asterix.test.common.TestHelper.joinPath;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
 import java.net.URL;
 import java.util.Collections;
-import java.util.logging.Logger;
 
 import org.apache.asterix.common.utils.ServletUtil.Servlets;
 import org.apache.asterix.test.aql.TestExecutor;
+import org.apache.asterix.test.base.TestMethodTracer;
 import org.apache.asterix.test.common.TestHelper;
 import org.apache.asterix.testframework.context.TestCaseContext.OutputFormat;
 import org.apache.commons.io.FileUtils;
@@ -35,11 +37,11 @@ import org.apache.commons.io.IOUtils;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TestRule;
 import org.junit.runners.MethodSorters;
 
-import static org.apache.asterix.test.common.TestHelper.joinPath;
-
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class SampleLocalClusterIT {
 
@@ -54,7 +56,8 @@ public class SampleLocalClusterIT {
 
     private static final String LOCAL_SAMPLES_DIR = joinPath(OUTPUT_DIR, "samples", "local");
 
-    private static final Logger LOGGER = Logger.getLogger(SampleLocalClusterIT.class.getName());
+    @Rule
+    public TestRule watcher = new TestMethodTracer();
 
     @BeforeClass
     public static void setUp() throws Exception {