Repository: storm
Updated Branches:
  refs/heads/1.1.x-branch ba9c97daa -> c9560b106


STORM-2841 Use extended class instead of partial mock for TestHiveBolt

* while mocking partially, oddly it calls real method intermittently which 
breaks test


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

Branch: refs/heads/1.1.x-branch
Commit: c9560b106b39ff46b2b3da6f41de9222ad80e75b
Parents: ba9c97d
Author: Jungtaek Lim <kabh...@gmail.com>
Authored: Mon Feb 12 17:55:48 2018 +0900
Committer: Jungtaek Lim <kabh...@gmail.com>
Committed: Tue Feb 13 17:49:35 2018 +0900

----------------------------------------------------------------------
 .../apache/storm/hive/bolt/TestHiveBolt.java    | 33 ++++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/c9560b10/external/storm-hive/src/test/java/org/apache/storm/hive/bolt/TestHiveBolt.java
----------------------------------------------------------------------
diff --git 
a/external/storm-hive/src/test/java/org/apache/storm/hive/bolt/TestHiveBolt.java
 
b/external/storm-hive/src/test/java/org/apache/storm/hive/bolt/TestHiveBolt.java
index 0cf0084..c10d42e 100644
--- 
a/external/storm-hive/src/test/java/org/apache/storm/hive/bolt/TestHiveBolt.java
+++ 
b/external/storm-hive/src/test/java/org/apache/storm/hive/bolt/TestHiveBolt.java
@@ -19,6 +19,7 @@
 package org.apache.storm.hive.bolt;
 
 import org.apache.storm.Config;
+import org.apache.storm.hive.common.HiveWriter;
 import org.apache.storm.task.GeneralTopologyContext;
 import org.apache.storm.task.OutputCollector;
 import org.apache.storm.topology.TopologyBuilder;
@@ -45,7 +46,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.*;
@@ -306,6 +306,23 @@ public class TestHiveBolt {
         bolt.cleanup();
     }
 
+    private static class FlushFailureHiveBolt extends HiveBolt {
+
+        public FlushFailureHiveBolt(HiveOptions options) {
+            super(options);
+        }
+
+        @Override
+        void flushAllWriters(boolean rollToNext) throws 
HiveWriter.CommitFailure, HiveWriter.TxnBatchFailure, HiveWriter.TxnFailure,
+                InterruptedException {
+            if (rollToNext) {
+                throw new InterruptedException();
+            } else {
+                super.flushAllWriters(false);
+            }
+        }
+    }
+
     @Test
     public void testNoAcksIfFlushFails() throws Exception
     {
@@ -316,24 +333,20 @@ public class TestHiveBolt {
                 .withTxnsPerBatch(2)
                 .withBatchSize(2);
 
-        HiveBolt spyBolt = Mockito.spy(new HiveBolt(hiveOptions));
-
-        //This forces a failure of all the flush attempts
-        doThrow(new 
InterruptedException()).when(spyBolt).flushAllWriters(true);
-
+        HiveBolt failingBolt = new FlushFailureHiveBolt(hiveOptions);
 
-        spyBolt.prepare(config, null, new OutputCollector(collector));
+        failingBolt.prepare(config, null, new OutputCollector(collector));
 
         Tuple tuple1 = generateTestTuple(1,"SJC","Sunnyvale","CA");
         Tuple tuple2 = generateTestTuple(2,"SFO","San Jose","CA");
 
-        spyBolt.execute(tuple1);
-        spyBolt.execute(tuple2);
+        failingBolt.execute(tuple1);
+        failingBolt.execute(tuple2);
 
         verify(collector, never()).ack(tuple1);
         verify(collector, never()).ack(tuple2);
 
-        spyBolt.cleanup();
+        failingBolt.cleanup();
     }
 
     @Test

Reply via email to