kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] 03/03: java: fix tests that use ExpectedException
Date Thu, 28 Mar 2019 04:25:03 GMT
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit ef900efdc7fe781c59e2c33d3a95d9d79ba6f6da
Author: Adar Dembo <adar@cloudera.com>
AuthorDate: Wed Mar 27 16:57:00 2019 -0700

    java: fix tests that use ExpectedException
    
    There's a weird interaction between the ExpectedException and
    KuduTestHarness rules. The test passes, but the RetryRule embedded in
    KuduTestHarness thinks it failed and reports a test failure. It has
    something to do with the assumptions JUnit has around state; reinvoking a
    test method violates those assumptions.
    
    Anyway, the solution is to use a RuleChain to set up the two rules. In the
    case of TestAsyncUtil, we didn't even need the ExpectedException at all.
    
    Change-Id: Iddba2ccfac5a3120c111d25f5cfefae22292c5f4
    Reviewed-on: http://gerrit.cloudera.org:8080/12875
    Reviewed-by: Grant Henke <granthenke@apache.org>
    Tested-by: Kudu Jenkins
---
 .../apache/kudu/mapreduce/tools/ITImportParquetPreCheck.java   |  9 +++++++--
 .../src/test/java/org/apache/kudu/util/TestAsyncUtil.java      |  7 +------
 .../flume/sink/RegexpKuduOperationsProducerParseErrorTest.java | 10 +++++++---
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/java/kudu-client-tools/src/test/java/org/apache/kudu/mapreduce/tools/ITImportParquetPreCheck.java
b/java/kudu-client-tools/src/test/java/org/apache/kudu/mapreduce/tools/ITImportParquetPreCheck.java
index 6bfde78..a3f7561 100644
--- a/java/kudu-client-tools/src/test/java/org/apache/kudu/mapreduce/tools/ITImportParquetPreCheck.java
+++ b/java/kudu-client-tools/src/test/java/org/apache/kudu/mapreduce/tools/ITImportParquetPreCheck.java
@@ -43,6 +43,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.RuleChain;
 
 import org.apache.kudu.ColumnSchema;
 import org.apache.kudu.Schema;
@@ -77,11 +78,15 @@ public class ITImportParquetPreCheck {
     schema = new Schema(columns);
   }
 
-  @Rule
   public KuduTestHarness harness = new KuduTestHarness();
+  public ExpectedException thrown = ExpectedException.none();
 
+  // ExpectedException misbehaves when combined with other rules; we use a
+  // RuleChain to beat it into submission.
+  //
+  // See https://stackoverflow.com/q/28846088 for more information.
   @Rule
-  public ExpectedException thrown = ExpectedException.none();
+  public RuleChain chain = RuleChain.outerRule(harness).around(thrown);
 
   @Before
   public void setUp() throws Exception {
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/util/TestAsyncUtil.java b/java/kudu-client/src/test/java/org/apache/kudu/util/TestAsyncUtil.java
index f0b831a..794a985 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/util/TestAsyncUtil.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/util/TestAsyncUtil.java
@@ -22,17 +22,13 @@ import com.stumbleupon.async.Callback;
 import com.stumbleupon.async.Deferred;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 /**
  * Test for {@link AsyncUtil}.
  */
 public class TestAsyncUtil {
 
-  @Rule
-  public ExpectedException exception = ExpectedException.none();
-
-  @Test
+  @Test(expected = IllegalStateException.class)
   public void testAddCallbacksDeferring() throws Exception {
     Deferred<String> d = new Deferred<String>();
     TestCallback cb = new TestCallback();
@@ -52,7 +48,6 @@ public class TestAsyncUtil {
     d = new Deferred<String>();
     AsyncUtil.addCallbacksDeferring(d, cb, eb);
     d.callback(new IllegalStateException());
-    exception.expect(IllegalStateException.class);
     d.join();
   }
 
diff --git a/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
b/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
index 2db41e0..c367f77 100644
--- a/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
+++ b/java/kudu-flume-sink/src/test/java/org/apache/kudu/flume/sink/RegexpKuduOperationsProducerParseErrorTest.java
@@ -39,7 +39,7 @@ import org.apache.kudu.test.KuduTestHarness;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-
+import org.junit.rules.RuleChain;
 
 import org.apache.kudu.ColumnSchema;
 import org.apache.kudu.Schema;
@@ -69,11 +69,15 @@ public class RegexpKuduOperationsProducerParseErrorTest {
   private static final String POLICY_WARN = "WARN";
   private static final String POLICY_IGNORE = "IGNORE";
 
-  @Rule
   public KuduTestHarness harness = new KuduTestHarness();
+  public ExpectedException thrown = ExpectedException.none();
 
+  // ExpectedException misbehaves when combined with other rules; we use a
+  // RuleChain to beat it into submission.
+  //
+  // See https://stackoverflow.com/q/28846088 for more information.
   @Rule
-  public ExpectedException thrown = ExpectedException.none();
+  public RuleChain chain = RuleChain.outerRule(harness).around(thrown);
 
   @Test
   public void testMissingColumnThrowsExceptionDefaultConfig() throws Exception {


Mime
View raw message