sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2424: Sqoop2: Provide custom TestNG listener in integration tests
Date Thu, 23 Jul 2015 21:01:43 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 473de8932 -> ec2d2619e


SQOOP-2424: Sqoop2: Provide custom TestNG listener in integration tests

(Jarek Jarcec Cecho via Abraham Elmahrek)


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

Branch: refs/heads/sqoop2
Commit: ec2d2619ee2ec7a4097648a5081337af9d2534ba
Parents: 473de89
Author: Abraham Elmahrek <abe@apache.org>
Authored: Thu Jul 23 12:13:12 2015 -0700
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Thu Jul 23 12:13:12 2015 -0700

----------------------------------------------------------------------
 .../sqoop/test/testng/SqoopTestListener.java    | 97 ++++++++++++++++++++
 .../test/resources/integration-tests-suite.xml  |  4 +
 test/src/test/resources/upgrade-tests-suite.xml |  4 +
 3 files changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/ec2d2619/test/src/main/java/org/apache/sqoop/test/testng/SqoopTestListener.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/sqoop/test/testng/SqoopTestListener.java b/test/src/main/java/org/apache/sqoop/test/testng/SqoopTestListener.java
new file mode 100644
index 0000000..c86a765
--- /dev/null
+++ b/test/src/main/java/org/apache/sqoop/test/testng/SqoopTestListener.java
@@ -0,0 +1,97 @@
+/**
+ * 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.sqoop.test.testng;
+
+import org.apache.commons.lang.StringUtils;
+import org.testng.ITestResult;
+import org.testng.TestListenerAdapter;
+
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+
+/**
+ * Sqoop specific listener that will print name of each particular test that being run.
+ *
+ * Particularly suitable for integration tests that generally takes long time to finish.
+ */
+public class SqoopTestListener extends TestListenerAdapter {
+
+  /**
+   * Sqoop tests are generally running with redirectTestOutputToFile=true which means
+   * that System.out is redirected to file. That is unpleasant as output user is suppose
+   * to see is not available on the console. Hence instead of System.out we're using
+   * directly the STDOUT file descriptor.
+   */
+  static PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out));
+
+
+  @Override
+  public void onTestStart(ITestResult tr) {
+    ps.flush();
+    ps.print(testName(tr));
+    ps.print(" running...\n");
+  }
+
+  @Override
+  public void onTestFailure(ITestResult tr) {
+    ps.flush();
+    ps.print("FAILURE");
+    ps.print(elapsedTime(tr));
+    ps.print("\n\n");
+  }
+
+  @Override
+  public void onTestSkipped(ITestResult tr) {
+    ps.flush();
+    ps.print("SKIPPED");
+    ps.print(elapsedTime(tr));
+    ps.print("\n\n");
+  }
+
+  @Override
+  public void onTestSuccess(ITestResult tr) {
+    ps.flush();
+    ps.print("SUCCESS");
+    ps.print(elapsedTime(tr));
+    ps.print("\n\n");
+  }
+
+  private String testName(ITestResult tr) {
+    StringBuilder sb = new StringBuilder("Test ")
+      .append(tr.getTestClass().getName())
+      .append(".")
+      .append(tr.getName());
+
+    if(tr.getParameters() != null && tr.getParameters().length > 0) {
+      sb.append(" with parameters [")
+        .append(StringUtils.join(tr.getParameters(), ","))
+        .append("]");
+    }
+
+    return sb.toString();
+  }
+
+  private String elapsedTime(ITestResult tr) {
+    StringBuilder sb = new StringBuilder(" in ")
+      .append((tr.getEndMillis() - tr.getStartMillis()) / 1000)
+      .append(" seconds");
+
+    return sb.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ec2d2619/test/src/test/resources/integration-tests-suite.xml
----------------------------------------------------------------------
diff --git a/test/src/test/resources/integration-tests-suite.xml b/test/src/test/resources/integration-tests-suite.xml
index f0dd905..c105329 100644
--- a/test/src/test/resources/integration-tests-suite.xml
+++ b/test/src/test/resources/integration-tests-suite.xml
@@ -20,6 +20,10 @@ limitations under the License.
 
 <suite name="IntegrationTests" verbose="2" parallel="false">
 
+  <listeners>
+    <listener class-name="org.apache.sqoop.test.testng.SqoopTestListener" />
+  </listeners>
+
   <test name="ConnectorTests">
     <packages>
       <package name="org.apache.sqoop.integration.connector.*"/>

http://git-wip-us.apache.org/repos/asf/sqoop/blob/ec2d2619/test/src/test/resources/upgrade-tests-suite.xml
----------------------------------------------------------------------
diff --git a/test/src/test/resources/upgrade-tests-suite.xml b/test/src/test/resources/upgrade-tests-suite.xml
index 2856556..3318e67 100644
--- a/test/src/test/resources/upgrade-tests-suite.xml
+++ b/test/src/test/resources/upgrade-tests-suite.xml
@@ -20,6 +20,10 @@ limitations under the License.
 
 <suite name="UpgradeTests" verbose="2" parallel="false">
 
+  <listeners>
+    <listener class-name="org.apache.sqoop.test.testng.SqoopTestListener" />
+  </listeners>
+
   <test name="RepositoryTests">
     <packages>
       <package name="org.apache.sqoop.integration.repository.derby.upgrade"/>


Mime
View raw message