You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by se...@apache.org on 2015/10/12 19:51:13 UTC

[05/10] hive git commit: HIVE-12038 : Fix the 'overall' section in the HiveQA report (Szehon, reviewed by Sergio Pena)

HIVE-12038 : Fix the 'overall' section in the HiveQA report (Szehon, reviewed by Sergio Pena)


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

Branch: refs/heads/llap
Commit: 86f7af66f03a5b467709a9845d07430b2d729d28
Parents: 04febfd
Author: Szehon Ho <sz...@cloudera.com>
Authored: Fri Oct 9 16:54:10 2015 -0700
Committer: Szehon Ho <sz...@cloudera.com>
Committed: Fri Oct 9 16:54:10 2015 -0700

----------------------------------------------------------------------
 .../hive/ptest/execution/JIRAService.java       | 96 +++++++++++---------
 .../hive/ptest/execution/TestJIRAService.java   | 89 +++++++++++++++++-
 ...RAService.testErrorWithMessages.approved.txt | 20 ++++
 ...ervice.testErrorWithoutMessages.approved.txt | 14 +++
 .../TestJIRAService.testFailAdd.approved.txt    | 21 +++++
 .../TestJIRAService.testFailNoAdd.approved.txt  | 21 +++++
 .../TestJIRAService.testSuccessAdd.approved.txt | 16 ++++
 ...estJIRAService.testSuccessNoAdd.approved.txt | 16 ++++
 .../resources/test-configuration.properties     |  2 +
 9 files changed, 249 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java b/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java
index 37127ea..03a6321 100644
--- a/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java
+++ b/testutils/ptest2/src/main/java/org/apache/hive/ptest/execution/JIRAService.java
@@ -101,37 +101,37 @@ class JIRAService {
 
   void postComment(boolean error, int numTestsExecuted, SortedSet<String> failedTests,
     List<String> messages, Set<String> addedTests) {
-    DefaultHttpClient httpClient = new DefaultHttpClient();
-    try {
-      BuildInfo buildInfo = formatBuildTag(mBuildTag);
-      String buildTagForLogs = formatBuildTagForLogs(mBuildTag);
-      List<String> comments = Lists.newArrayList();
-      comments.add("");
-      comments.add("");
-      if (!failedTests.isEmpty()) {
-        comments.add("{color:red}Overall{color}: -1 at least one tests failed");
-      } else if (numTestsExecuted == 0) {
-        comments.add("{color:red}Overall{color}: -1 no tests executed");
-      } else if (error) {
-        comments.add("{color:red}Overall{color}: -1 build exited with an error");
-      } else {
-        comments.add("{color:green}Overall{color}: +1 all checks pass");
-      }
-      comments.add("");
-      if (!mPatch.isEmpty()) {
-        comments.add("Here are the results of testing the latest attachment:");
-        comments.add(mPatch);
-      }
-      comments.add("");
+    String comments = generateComments(error, numTestsExecuted, failedTests, messages, addedTests);
+    publishComments(comments);
+  }
+
+  @VisibleForTesting
+  String generateComments(boolean error, int numTestsExecuted, SortedSet<String> failedTests,
+    List<String> messages, Set<String> addedTests) {
+    BuildInfo buildInfo = formatBuildTag(mBuildTag);
+    String buildTagForLogs = formatBuildTagForLogs(mBuildTag);
+    List<String> comments = Lists.newArrayList();
+    comments.add("");
+    comments.add("");
+    if (!mPatch.isEmpty()) {
+      comments.add("Here are the results of testing the latest attachment:");
+      comments.add(mPatch);
+    }
+    comments.add("");
+    if (error) {
+      comments.add(formatError("-1 due to build exiting with an error"));
+    } else {
       if (addedTests.size() > 0) {
         comments.add(formatSuccess("+1 due to " + addedTests.size() + " test(s) being added or modified."));
       } else {
         comments.add(formatError("-1 due to no test(s) being added or modified."));
       }
       comments.add("");
-      if (numTestsExecuted > 0) {
+      if (numTestsExecuted == 0) {
+        comments.add(formatError("-1 due to no tests executed"));
+      } else {
         if (failedTests.isEmpty()) {
-          comments.add(formatSuccess("+1 " + numTestsExecuted + " tests passed"));
+          comments.add(formatSuccess("+1 due to " + numTestsExecuted + " tests passed"));
         } else {
           comments.add(formatError("-1 due to " + failedTests.size()
             + " failed/errored test(s), " + numTestsExecuted + " tests executed"));
@@ -140,28 +140,34 @@ class JIRAService {
           comments.addAll(failedTests);
           comments.add("{noformat}");
         }
-        comments.add("");
-      }
-      comments.add("Test results: " + mJenkinsURL + "/" +
-        buildInfo.getFormattedBuildTag() + "/testReport");
-      comments.add("Console output: " + mJenkinsURL + "/" +
-        buildInfo.getFormattedBuildTag() + "/console");
-      comments.add("Test logs: " + mLogsURL + buildTagForLogs);
-      comments.add("");
-      if (!messages.isEmpty()) {
-        comments.add("Messages:");
-        comments.add("{noformat}");
-        comments.addAll(trimMessages(messages));
-        comments.add("{noformat}");
-        comments.add("");
       }
-      comments.add("This message is automatically generated.");
-      String attachmentId = parseAttachementId(mPatch);
+    }
+    comments.add("");
+    comments.add("Test results: " + mJenkinsURL + "/" +
+      buildInfo.getFormattedBuildTag() + "/testReport");
+    comments.add("Console output: " + mJenkinsURL + "/" +
+      buildInfo.getFormattedBuildTag() + "/console");
+    comments.add("Test logs: " + mLogsURL + buildTagForLogs);
+    comments.add("");
+    if (!messages.isEmpty()) {
+      comments.add("Messages:");
+      comments.add("{noformat}");
+      comments.addAll(trimMessages(messages));
+      comments.add("{noformat}");
       comments.add("");
-      comments.add("ATTACHMENT ID: " + attachmentId +
-        " - " + buildInfo.getBuildName());
-      mLogger.info("Comment: " + Joiner.on("\n").join(comments));
-      String body = Joiner.on("\n").join(comments);
+    }
+    comments.add("This message is automatically generated.");
+    String attachmentId = parseAttachementId(mPatch);
+    comments.add("");
+    comments.add("ATTACHMENT ID: " + attachmentId +
+      " - " + buildInfo.getBuildName());
+    mLogger.info("Comment: " + Joiner.on("\n").join(comments));
+    return Joiner.on("\n").join(comments);
+  }
+
+  void publishComments(String comments) {
+    DefaultHttpClient httpClient = new DefaultHttpClient();
+    try {
       String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName);
       URL apiURL = new URL(mUrl);
       httpClient.getCredentialsProvider()
@@ -174,7 +180,7 @@ class JIRAService {
       httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
       HttpPost request = new HttpPost(url);
       ObjectMapper mapper = new ObjectMapper();
-      StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(body)));
+      StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(comments)));
       request.addHeader("Content-Type", "application/json");
       request.setEntity(params);
       HttpResponse httpResponse = httpClient.execute(request, localcontext);

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java
index 2ce1dc9..b97b890 100644
--- a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.java
@@ -20,13 +20,42 @@ package org.apache.hive.ptest.execution;
 
 import com.google.common.collect.Lists;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import com.google.common.io.Resources;
 import junit.framework.Assert;
 
 import org.apache.hive.ptest.execution.JIRAService.BuildInfo;
+import org.apache.hive.ptest.execution.conf.TestConfiguration;
+import org.approvaltests.Approvals;
+import org.approvaltests.reporters.JunitReporter;
+import org.approvaltests.reporters.UseReporter;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@UseReporter(JunitReporter.class)
+public class TestJIRAService extends AbstractTestPhase {
+
+  TestConfiguration conf;
+  JIRAService jiraService;
+
+  @Before
+  public void setup() throws Exception {
+    initialize(getClass().getSimpleName());
+    conf = TestConfiguration.fromInputStream(
+      Resources.getResource("test-configuration.properties").openStream(), logger);
+    conf.setPatch("https://HIVE-10000.patch");
+    jiraService = new JIRAService(logger, conf, "tag-10");
+  }
 
-public class TestJIRAService  {
 
   @Test
   public void testFormatBuildTagPositive() throws Throwable {
@@ -75,4 +104,62 @@ public class TestJIRAService  {
     expected.add(0, JIRAService.TRIMMED_MESSAGE);
     Assert.assertEquals(expected, JIRAService.trimMessages(messages));
   }
+
+  @Test
+  public void testErrorWithMessages() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    List<String> messages = new ArrayList<String>();
+    messages.add("Error message 1");
+    messages.add("Error message 2");
+    Set<String> addedTests = new HashSet<String>();
+    Approvals.verify(jiraService.generateComments(true, 0, failedTests, messages, addedTests));
+  }
+
+  @Test
+  public void testErrorWithoutMessages() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    List<String> messages = new ArrayList<String>();
+    Set<String> addedTests = new HashSet<String>();
+    Approvals.verify(jiraService.generateComments(true, 0, failedTests, messages, addedTests));
+  }
+
+  @Test
+  public void testFailNoAdd() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    failedTests.add("FailedTest1");
+    failedTests.add("FailedTest2");
+    List<String> messages = new ArrayList<String>();
+    Set<String> addedTests = new HashSet<String>();
+    Approvals.verify(jiraService.generateComments(false, 5, failedTests, messages, addedTests));
+  }
+
+  @Test
+  public void testFailAdd() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    failedTests.add("FailedTest1");
+    failedTests.add("FailedTest2");
+    List<String> messages = new ArrayList<String>();
+    Set<String> addedTests = new HashSet<String>();
+    addedTests.add("AddedTest1");
+    addedTests.add("AddedTest2");
+    Approvals.verify(jiraService.generateComments(false, 5, failedTests, messages, addedTests));
+  }
+
+  @Test
+  public void testSuccessNoAdd() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    List<String> messages = new ArrayList<String>();
+    Set<String> addedTests = new HashSet<String>();
+    Approvals.verify(jiraService.generateComments(false, 5, failedTests, messages, addedTests));
+  }
+
+  @Test
+  public void testSuccessAdd() throws Exception {
+    SortedSet<String> failedTests = new TreeSet<String>();
+    List<String> messages = new ArrayList<String>();
+    Set<String> addedTests = new HashSet<String>();
+    addedTests.add("AddedTest1");
+    addedTests.add("AddedTest2");
+    Approvals.verify(jiraService.generateComments(false, 5, failedTests, messages, addedTests));
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithMessages.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithMessages.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithMessages.approved.txt
new file mode 100644
index 0000000..546a5f4
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithMessages.approved.txt
@@ -0,0 +1,20 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:red}ERROR:{color} -1 due to build exiting with an error
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+Messages:
+{noformat}
+Error message 1
+Error message 2
+{noformat}
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithoutMessages.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithoutMessages.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithoutMessages.approved.txt
new file mode 100644
index 0000000..ec42030
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testErrorWithoutMessages.approved.txt
@@ -0,0 +1,14 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:red}ERROR:{color} -1 due to build exiting with an error
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailAdd.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailAdd.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailAdd.approved.txt
new file mode 100644
index 0000000..07ee6b4
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailAdd.approved.txt
@@ -0,0 +1,21 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:green}SUCCESS:{color} +1 due to 2 test(s) being added or modified.
+
+{color:red}ERROR:{color} -1 due to 2 failed/errored test(s), 5 tests executed
+*Failed tests:*
+{noformat}
+FailedTest1
+FailedTest2
+{noformat}
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailNoAdd.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailNoAdd.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailNoAdd.approved.txt
new file mode 100644
index 0000000..1f86cfc
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testFailNoAdd.approved.txt
@@ -0,0 +1,21 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:red}ERROR:{color} -1 due to no test(s) being added or modified.
+
+{color:red}ERROR:{color} -1 due to 2 failed/errored test(s), 5 tests executed
+*Failed tests:*
+{noformat}
+FailedTest1
+FailedTest2
+{noformat}
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessAdd.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessAdd.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessAdd.approved.txt
new file mode 100644
index 0000000..bc8839c
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessAdd.approved.txt
@@ -0,0 +1,16 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:green}SUCCESS:{color} +1 due to 2 test(s) being added or modified.
+
+{color:green}SUCCESS:{color} +1 due to 5 tests passed
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessNoAdd.approved.txt
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessNoAdd.approved.txt b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessNoAdd.approved.txt
new file mode 100644
index 0000000..8ea4d37
--- /dev/null
+++ b/testutils/ptest2/src/test/java/org/apache/hive/ptest/execution/TestJIRAService.testSuccessNoAdd.approved.txt
@@ -0,0 +1,16 @@
+
+
+Here are the results of testing the latest attachment:
+https://HIVE-10000.patch
+
+{color:red}ERROR:{color} -1 due to no test(s) being added or modified.
+
+{color:green}SUCCESS:{color} +1 due to 5 tests passed
+
+Test results: https://builds.apache.org/job/tag/10/testReport
+Console output: https://builds.apache.org/job/tag/10/console
+Test logs: http://builds.apache.org/logs/tag-10/
+
+This message is automatically generated.
+
+ATTACHMENT ID:  - tag
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hive/blob/86f7af66/testutils/ptest2/src/test/resources/test-configuration.properties
----------------------------------------------------------------------
diff --git a/testutils/ptest2/src/test/resources/test-configuration.properties b/testutils/ptest2/src/test/resources/test-configuration.properties
index caba9ea..73a683b 100644
--- a/testutils/ptest2/src/test/resources/test-configuration.properties
+++ b/testutils/ptest2/src/test/resources/test-configuration.properties
@@ -6,6 +6,8 @@ host.localhost.host = localhost
 host.localhost.threads = 2
 host.localhost.localDirs = /home/hiveptest
 
+logsURL = http://builds.apache.org/logs/
+
 workingDirectory = /tmp/hive-ptest-units/working/dir
 profileDirectory = /etc/hiveptest/conf